|
@ -6,24 +6,22 @@ import ( |
|
|
"git.aiterp.net/rpdata/api/internal/session" |
|
|
"git.aiterp.net/rpdata/api/internal/session" |
|
|
"git.aiterp.net/rpdata/api/model/change" |
|
|
"git.aiterp.net/rpdata/api/model/change" |
|
|
"git.aiterp.net/rpdata/api/model/channel" |
|
|
"git.aiterp.net/rpdata/api/model/channel" |
|
|
|
|
|
"git.aiterp.net/rpdata/api/resolver/types" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// ChannelResolver for the Channel graphql type
|
|
|
|
|
|
type ChannelResolver struct{ C channel.Channel } |
|
|
|
|
|
|
|
|
|
|
|
// ChannelArgs is args for channel query
|
|
|
// ChannelArgs is args for channel query
|
|
|
type ChannelArgs struct { |
|
|
type ChannelArgs struct { |
|
|
Name string |
|
|
Name string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Channel implements the channel query
|
|
|
// Channel implements the channel query
|
|
|
func (r *QueryResolver) Channel(ctx context.Context, args *ChannelArgs) (*ChannelResolver, error) { |
|
|
|
|
|
|
|
|
func (r *QueryResolver) Channel(ctx context.Context, args *ChannelArgs) (*types.ChannelResolver, error) { |
|
|
channel, err := channel.FindName(args.Name) |
|
|
channel, err := channel.FindName(args.Name) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return &ChannelResolver{C: channel}, nil |
|
|
|
|
|
|
|
|
return &types.ChannelResolver{C: channel}, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// ChannelsArgs is args for channel query
|
|
|
// ChannelsArgs is args for channel query
|
|
@ -32,15 +30,15 @@ type ChannelsArgs struct { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Channels implements the channels query
|
|
|
// Channels implements the channels query
|
|
|
func (r *QueryResolver) Channels(ctx context.Context, args *ChannelsArgs) ([]*ChannelResolver, error) { |
|
|
|
|
|
|
|
|
func (r *QueryResolver) Channels(ctx context.Context, args *ChannelsArgs) ([]*types.ChannelResolver, error) { |
|
|
channels, err := channel.List(args.Logged != nil && *args.Logged) |
|
|
channels, err := channel.List(args.Logged != nil && *args.Logged) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
resolvers := make([]*ChannelResolver, len(channels)) |
|
|
|
|
|
|
|
|
resolvers := make([]*types.ChannelResolver, len(channels)) |
|
|
for i := range channels { |
|
|
for i := range channels { |
|
|
resolvers[i] = &ChannelResolver{C: channels[i]} |
|
|
|
|
|
|
|
|
resolvers[i] = &types.ChannelResolver{C: channels[i]} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return resolvers, nil |
|
|
return resolvers, nil |
|
@ -58,7 +56,7 @@ type ChannelAddArgs struct { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// AddChannel resolves the addChannel mutation
|
|
|
// AddChannel resolves the addChannel mutation
|
|
|
func (r *MutationResolver) AddChannel(ctx context.Context, args *ChannelAddArgs) (*ChannelResolver, error) { |
|
|
|
|
|
|
|
|
func (r *MutationResolver) AddChannel(ctx context.Context, args *ChannelAddArgs) (*types.ChannelResolver, error) { |
|
|
input := args.Input |
|
|
input := args.Input |
|
|
|
|
|
|
|
|
user := session.FromContext(ctx).User() |
|
|
user := session.FromContext(ctx).User() |
|
@ -92,7 +90,7 @@ func (r *MutationResolver) AddChannel(ctx context.Context, args *ChannelAddArgs) |
|
|
"event": input.EventName, |
|
|
"event": input.EventName, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
return &ChannelResolver{C: channel}, nil |
|
|
|
|
|
|
|
|
return &types.ChannelResolver{C: channel}, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// ChannelEditArgs is input for the editChannel mutation
|
|
|
// ChannelEditArgs is input for the editChannel mutation
|
|
@ -107,7 +105,7 @@ type ChannelEditArgs struct { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// EditChannel resolves the editChannel mutation
|
|
|
// EditChannel resolves the editChannel mutation
|
|
|
func (r *MutationResolver) EditChannel(ctx context.Context, args *ChannelEditArgs) (*ChannelResolver, error) { |
|
|
|
|
|
|
|
|
func (r *MutationResolver) EditChannel(ctx context.Context, args *ChannelEditArgs) (*types.ChannelResolver, error) { |
|
|
input := args.Input |
|
|
input := args.Input |
|
|
|
|
|
|
|
|
user := session.FromContext(ctx).User() |
|
|
user := session.FromContext(ctx).User() |
|
@ -132,11 +130,11 @@ func (r *MutationResolver) EditChannel(ctx context.Context, args *ChannelEditArg |
|
|
"event": input.EventName, |
|
|
"event": input.EventName, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
return &ChannelResolver{C: channel}, nil |
|
|
|
|
|
|
|
|
return &types.ChannelResolver{C: channel}, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// RemoveChannel resolves the editChannel mutation
|
|
|
// RemoveChannel resolves the editChannel mutation
|
|
|
func (r *MutationResolver) RemoveChannel(ctx context.Context, args ChannelArgs) (*ChannelResolver, error) { |
|
|
|
|
|
|
|
|
func (r *MutationResolver) RemoveChannel(ctx context.Context, args ChannelArgs) (*types.ChannelResolver, error) { |
|
|
user := session.FromContext(ctx).User() |
|
|
user := session.FromContext(ctx).User() |
|
|
if user == nil || !user.Permitted("channel.remove") { |
|
|
if user == nil || !user.Permitted("channel.remove") { |
|
|
return nil, ErrUnauthorized |
|
|
return nil, ErrUnauthorized |
|
@ -154,38 +152,5 @@ func (r *MutationResolver) RemoveChannel(ctx context.Context, args ChannelArgs) |
|
|
|
|
|
|
|
|
go change.Submit("Channel", "remove", user.ID, channel.Name, nil) |
|
|
go change.Submit("Channel", "remove", user.ID, channel.Name, nil) |
|
|
|
|
|
|
|
|
return &ChannelResolver{C: channel}, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Name resolves channel.name
|
|
|
|
|
|
func (r *ChannelResolver) Name() string { |
|
|
|
|
|
return r.C.Name |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Logged resolves channel.logged
|
|
|
|
|
|
func (r *ChannelResolver) Logged() bool { |
|
|
|
|
|
return r.C.Logged |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Hub resolves channel.hub
|
|
|
|
|
|
func (r *ChannelResolver) Hub() bool { |
|
|
|
|
|
return r.C.Hub |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// EventName resolves channel.eventName
|
|
|
|
|
|
func (r *ChannelResolver) EventName() *string { |
|
|
|
|
|
if r.C.Event == "" { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return &r.C.Event |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// LocationName resolves channel.locationName
|
|
|
|
|
|
func (r *ChannelResolver) LocationName() *string { |
|
|
|
|
|
if r.C.Location == "" { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return &r.C.Location |
|
|
|
|
|
|
|
|
return &types.ChannelResolver{C: channel}, nil |
|
|
} |
|
|
} |