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.
|
|
package mutations
import ( "context"
"git.aiterp.net/rpdata/api/graphql/resolver/types" "git.aiterp.net/rpdata/api/internal/session" "git.aiterp.net/rpdata/api/model/change" "git.aiterp.net/rpdata/api/model/channel" )
// ChannelAddArgs is input for the addChannel mutation
type ChannelAddArgs struct { Input *struct { Name string Logged *bool Hub *bool EventName *string LocationName *string } }
// AddChannel resolves the addChannel mutation
func (r *MutationResolver) AddChannel(ctx context.Context, args *ChannelAddArgs) (*types.ChannelResolver, error) { input := args.Input
user := session.FromContext(ctx).User() if user == nil || !user.Permitted("channel.add") { return nil, ErrUnauthorized }
logged := input.Logged != nil && *input.Logged
hub := input.Hub != nil && *input.Hub
eventName := "" if input.EventName != nil { eventName = *input.EventName }
locationName := "" if input.LocationName != nil { locationName = *input.LocationName }
channel, err := channel.New(input.Name, logged, hub, eventName, locationName) if err != nil { return nil, err }
go change.Submit("Channel", "add", user.ID, channel.Name, map[string]interface{}{ "logged": channel.Logged, "hub": channel.Hub, "location": input.LocationName, "event": input.EventName, })
return &types.ChannelResolver{C: channel}, nil }
|