You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
950 B
43 lines
950 B
package queries
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
|
"git.aiterp.net/rpdata/api/model/character"
|
|
)
|
|
|
|
// ErrIncorrectArguments is returned by character query.
|
|
var ErrIncorrectArguments = errors.New("You can only query character by ID or Nick")
|
|
|
|
// CharacterArgs is args for character query
|
|
type CharacterArgs struct {
|
|
ID *string
|
|
Nick *string
|
|
}
|
|
|
|
// Character resolves the character query
|
|
func (r *QueryResolver) Character(ctx context.Context, args *CharacterArgs) (*types.CharacterResolver, error) {
|
|
var char character.Character
|
|
var err error
|
|
|
|
if args.Nick != nil && args.ID != nil {
|
|
return nil, ErrIncorrectArguments
|
|
}
|
|
|
|
switch {
|
|
case args.ID != nil:
|
|
char, err = character.FindID(*args.ID)
|
|
case args.Nick != nil:
|
|
char, err = character.FindNick(*args.Nick)
|
|
default:
|
|
err = ErrIncorrectArguments
|
|
}
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &types.CharacterResolver{C: char}, nil
|
|
}
|