|
@ -2,52 +2,57 @@ package queries |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"context" |
|
|
"context" |
|
|
"errors" |
|
|
|
|
|
|
|
|
|
|
|
"git.aiterp.net/rpdata/api/graphql/loader" |
|
|
|
|
|
"git.aiterp.net/rpdata/api/graphql/resolver/types" |
|
|
"git.aiterp.net/rpdata/api/graphql/resolver/types" |
|
|
"git.aiterp.net/rpdata/api/model/character" |
|
|
"git.aiterp.net/rpdata/api/model/character" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// CharactersArgs is args for characters query
|
|
|
// CharactersArgs is args for characters query
|
|
|
type CharactersArgs struct { |
|
|
type CharactersArgs struct { |
|
|
|
|
|
Filter *struct { |
|
|
IDs *[]string |
|
|
IDs *[]string |
|
|
Nicks *[]string |
|
|
Nicks *[]string |
|
|
|
|
|
Names *[]string |
|
|
Author *string |
|
|
Author *string |
|
|
|
|
|
Search *string |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Characters resolves the characters query
|
|
|
// Characters resolves the characters query
|
|
|
func (r *QueryResolver) Characters(ctx context.Context, args *CharactersArgs) ([]*types.CharacterResolver, error) { |
|
|
func (r *QueryResolver) Characters(ctx context.Context, args *CharactersArgs) ([]*types.CharacterResolver, error) { |
|
|
var chars []character.Character |
|
|
|
|
|
|
|
|
var characters []character.Character |
|
|
var err error |
|
|
var err error |
|
|
|
|
|
|
|
|
loader := loader.FromContext(ctx) |
|
|
|
|
|
if loader == nil { |
|
|
|
|
|
return nil, errors.New("no loader") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
filter := args.Filter |
|
|
|
|
|
if filter != nil { |
|
|
|
|
|
var ids []string |
|
|
|
|
|
var nicks []string |
|
|
|
|
|
var names []string |
|
|
|
|
|
|
|
|
switch { |
|
|
|
|
|
case args.IDs != nil: |
|
|
|
|
|
chars, err = character.ListIDs(*args.IDs...) |
|
|
|
|
|
case args.Nicks != nil: |
|
|
|
|
|
chars, err = character.ListNicks(*args.Nicks...) |
|
|
|
|
|
case args.Author != nil: |
|
|
|
|
|
chars, err = character.ListAuthor(*args.Author) |
|
|
|
|
|
default: |
|
|
|
|
|
chars, err = character.List() |
|
|
|
|
|
|
|
|
if filter.IDs != nil { |
|
|
|
|
|
ids = *filter.IDs |
|
|
|
|
|
} |
|
|
|
|
|
if filter.Nicks != nil { |
|
|
|
|
|
nicks = *filter.Nicks |
|
|
|
|
|
} |
|
|
|
|
|
if filter.Names != nil { |
|
|
|
|
|
names = *filter.Names |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
characters, err = character.ListFilter(ids, nicks, names, filter.Author, filter.Search) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
characters, err = character.List() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
resolvers := make([]*types.CharacterResolver, 0, len(chars)) |
|
|
|
|
|
for i := range chars { |
|
|
|
|
|
if chars[i].ID == "" { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
resolvers = append(resolvers, &types.CharacterResolver{C: chars[i]}) |
|
|
|
|
|
|
|
|
resolvers := make([]*types.CharacterResolver, 0, len(characters)) |
|
|
|
|
|
for _, character := range characters { |
|
|
|
|
|
resolvers = append(resolvers, &types.CharacterResolver{C: character}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return resolvers, nil |
|
|
return resolvers, nil |
|
|