Moved channels to new system, fixed change insert not working.
the build was successful

This commit is contained in:
2019-06-24 20:30:14 +02:00
parent f46b6f0774
commit acb6b637a5
16 changed files with 498 additions and 97 deletions
+17 -62
View File
@@ -2,93 +2,48 @@ package resolvers
import (
"context"
"errors"
"git.aiterp.net/rpdata/api/graph2/graphcore"
"git.aiterp.net/rpdata/api/internal/auth"
"git.aiterp.net/rpdata/api/models"
"git.aiterp.net/rpdata/api/models/changekeys"
"git.aiterp.net/rpdata/api/models/changes"
"git.aiterp.net/rpdata/api/models/channels"
)
// Queries
func (r *queryResolver) Channel(ctx context.Context, name string) (*models.Channel, error) {
channel, err := channels.FindName(name)
if err != nil {
return nil, err
}
return &channel, nil
return r.s.Channels.Find(ctx, name)
}
func (r *queryResolver) Channels(ctx context.Context, filter *channels.Filter) ([]*models.Channel, error) {
channels, err := channels.List(filter)
if err != nil {
return nil, err
func (r *queryResolver) Channels(ctx context.Context, filter *models.ChannelFilter) ([]*models.Channel, error) {
if filter == nil {
filter = &models.ChannelFilter{}
}
channels2 := make([]*models.Channel, len(channels))
for i := range channels {
channels2[i] = &channels[i]
}
return channels2, nil
return r.s.Channels.List(ctx, *filter)
}
// Mutations
func (r *mutationResolver) AddChannel(ctx context.Context, input graphcore.ChannelAddInput) (*models.Channel, error) {
token := auth.TokenFromContext(ctx)
if !token.Authenticated() || !token.Permitted("channel.add") {
return nil, errors.New("You are not permitted to add channels")
}
logged := input.Logged != nil && *input.Logged
hub := input.Hub != nil && *input.Hub
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
}
channel, err := channels.Add(input.Name, logged, hub, eventName, locationName)
if err != nil {
return nil, errors.New("Failed to add channel: " + err.Error())
eventName := ""
if input.LocationName != nil {
eventName = *input.EventName
}
go changes.Submit("Channel", "add", token.UserID, true, changekeys.Listed(channel), channel)
return &channel, nil
return r.s.Channels.Create(ctx, input.Name, logged, hub, eventName, locationName)
}
func (r *mutationResolver) EditChannel(ctx context.Context, input graphcore.ChannelEditInput) (*models.Channel, error) {
token := auth.TokenFromContext(ctx)
if !token.Authenticated() || !token.Permitted("channel.edit") {
return nil, errors.New("You are not permitted to edit channels")
}
channel, err := channels.FindName(input.Name)
if err != nil {
return nil, errors.New("Channel not found")
}
channel, err = channels.Edit(channel, input.Logged, input.Hub, input.EventName, input.LocationName)
if err != nil {
return nil, errors.New("Failed to edit channel: " + err.Error())
}
go changes.Submit("Channel", "edit", token.UserID, true, changekeys.Listed(channel), channel)
return &channel, nil
return r.s.Channels.Update(ctx, input.Name, models.ChannelUpdate{
Logged: input.Logged,
Hub: input.Hub,
EventName: input.EventName,
LocationName: input.LocationName,
})
}