GraphQL API and utilities for the rpdata project
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.

60 lines
1.2 KiB

  1. package queries
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/graphql/resolver/types"
  5. "git.aiterp.net/rpdata/api/model/character"
  6. )
  7. // CharactersArgs is args for characters query
  8. type CharactersArgs struct {
  9. Filter *struct {
  10. IDs *[]string
  11. Nicks *[]string
  12. Names *[]string
  13. Author *string
  14. Search *string
  15. Logged *bool
  16. }
  17. }
  18. // Characters resolves the characters query
  19. func (r *QueryResolver) Characters(ctx context.Context, args *CharactersArgs) ([]*types.CharacterResolver, error) {
  20. var characters []character.Character
  21. var err error
  22. filter := args.Filter
  23. if filter != nil {
  24. var ids []string
  25. var nicks []string
  26. var names []string
  27. if filter.IDs != nil {
  28. ids = *filter.IDs
  29. }
  30. if filter.Nicks != nil {
  31. nicks = *filter.Nicks
  32. }
  33. if filter.Names != nil {
  34. names = *filter.Names
  35. }
  36. characters, err = character.ListFilter(ids, nicks, names, filter.Author, filter.Search, filter.Logged)
  37. if err != nil {
  38. return nil, err
  39. }
  40. } else {
  41. characters, err = character.List()
  42. if err != nil {
  43. return nil, err
  44. }
  45. }
  46. resolvers := make([]*types.CharacterResolver, 0, len(characters))
  47. for _, character := range characters {
  48. resolvers = append(resolvers, &types.CharacterResolver{C: character})
  49. }
  50. return resolvers, nil
  51. }