|
@ -2,11 +2,16 @@ package queries |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"context" |
|
|
"context" |
|
|
|
|
|
"errors" |
|
|
|
|
|
|
|
|
|
|
|
"git.aiterp.net/rpdata/api/graph2/input" |
|
|
|
|
|
"git.aiterp.net/rpdata/api/internal/auth" |
|
|
"git.aiterp.net/rpdata/api/models" |
|
|
"git.aiterp.net/rpdata/api/models" |
|
|
"git.aiterp.net/rpdata/api/models/channels" |
|
|
"git.aiterp.net/rpdata/api/models/channels" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Queries
|
|
|
|
|
|
|
|
|
func (r *resolver) Channel(ctx context.Context, name string) (models.Channel, error) { |
|
|
func (r *resolver) Channel(ctx context.Context, name string) (models.Channel, error) { |
|
|
return channels.FindName(name) |
|
|
return channels.FindName(name) |
|
|
} |
|
|
} |
|
@ -14,3 +19,45 @@ func (r *resolver) Channel(ctx context.Context, name string) (models.Channel, er |
|
|
func (r *resolver) Channels(ctx context.Context, filter *channels.Filter) ([]models.Channel, error) { |
|
|
func (r *resolver) Channels(ctx context.Context, filter *channels.Filter) ([]models.Channel, error) { |
|
|
return channels.List(filter) |
|
|
return channels.List(filter) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Mutations
|
|
|
|
|
|
|
|
|
|
|
|
func (r *mutationResolver) AddChannel(ctx context.Context, input input.ChannelAddInput) (models.Channel, error) { |
|
|
|
|
|
token := auth.TokenFromContext(ctx) |
|
|
|
|
|
if !token.Authenticated() || !token.Permitted("channel.add") { |
|
|
|
|
|
return models.Channel{}, errors.New("You are not permitted to add channels") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
logged := false |
|
|
|
|
|
if input.Logged != nil { |
|
|
|
|
|
logged = *input.Logged |
|
|
|
|
|
} |
|
|
|
|
|
hub := false |
|
|
|
|
|
if input.Hub != nil { |
|
|
|
|
|
hub = *input.Hub |
|
|
|
|
|
} |
|
|
|
|
|
eventName := "" |
|
|
|
|
|
if input.EventName != nil { |
|
|
|
|
|
eventName = *input.EventName |
|
|
|
|
|
} |
|
|
|
|
|
locationName := "" |
|
|
|
|
|
if input.LocationName != nil { |
|
|
|
|
|
locationName = *input.LocationName |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return channels.Add(input.Name, logged, hub, eventName, locationName) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (r *mutationResolver) EditChannel(ctx context.Context, input input.ChannelEditInput) (models.Channel, error) { |
|
|
|
|
|
token := auth.TokenFromContext(ctx) |
|
|
|
|
|
if !token.Authenticated() || !token.Permitted("channel.edit") { |
|
|
|
|
|
return models.Channel{}, errors.New("You are not permitted to edit channels") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
channel, err := channels.FindName(input.Name) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return models.Channel{}, errors.New("Channel not found") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return channels.Edit(channel, input.Logged, input.Hub, input.EventName, input.LocationName) |
|
|
|
|
|
} |