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.

49 lines
1.3 KiB

  1. package resolvers
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/graph2/graphcore"
  5. "git.aiterp.net/rpdata/api/models"
  6. )
  7. // Queries
  8. func (r *queryResolver) Channel(ctx context.Context, name string) (*models.Channel, error) {
  9. return r.s.Channels.Find(ctx, name)
  10. }
  11. func (r *queryResolver) Channels(ctx context.Context, filter *models.ChannelFilter) ([]*models.Channel, error) {
  12. if filter == nil {
  13. filter = &models.ChannelFilter{}
  14. }
  15. return r.s.Channels.List(ctx, *filter)
  16. }
  17. // Mutations
  18. func (r *mutationResolver) AddChannel(ctx context.Context, input graphcore.ChannelAddInput) (*models.Channel, error) {
  19. logged := input.Logged != nil && *input.Logged
  20. hub := input.Hub != nil && *input.Hub
  21. locationName := ""
  22. if input.LocationName != nil {
  23. locationName = *input.LocationName
  24. }
  25. eventName := ""
  26. if input.LocationName != nil {
  27. eventName = *input.EventName
  28. }
  29. return r.s.Channels.Create(ctx, input.Name, logged, hub, eventName, locationName)
  30. }
  31. func (r *mutationResolver) EditChannel(ctx context.Context, input graphcore.ChannelEditInput) (*models.Channel, error) {
  32. return r.s.Channels.Update(ctx, input.Name, models.ChannelUpdate{
  33. Logged: input.Logged,
  34. Hub: input.Hub,
  35. EventName: input.EventName,
  36. LocationName: input.LocationName,
  37. })
  38. }