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.

43 lines
936 B

  1. package queries
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/graphql/resolver/types"
  5. "git.aiterp.net/rpdata/api/model/channel"
  6. )
  7. // ChannelsArgs is args for channel query
  8. type ChannelsArgs struct {
  9. Filter *struct {
  10. Logged *bool
  11. EventName *string
  12. LocationName *string
  13. }
  14. }
  15. // Channels resolves the channels query
  16. func (r *QueryResolver) Channels(ctx context.Context, args *ChannelsArgs) ([]*types.ChannelResolver, error) {
  17. var channels []channel.Channel
  18. var err error
  19. filter := args.Filter
  20. if filter != nil {
  21. channels, err = channel.List(filter.Logged, filter.EventName, filter.LocationName)
  22. if err != nil {
  23. return nil, err
  24. }
  25. } else {
  26. channels, err = channel.List(nil, nil, nil)
  27. if err != nil {
  28. return nil, err
  29. }
  30. }
  31. resolvers := make([]*types.ChannelResolver, len(channels))
  32. for i := range channels {
  33. resolvers[i] = &types.ChannelResolver{C: channels[i]}
  34. }
  35. return resolvers, nil
  36. }