Browse Source

Moved ChannelResolver into resolvers/types package, updated references to it.

1.0
Gisle Aune 6 years ago
parent
commit
cc765e220a
  1. 59
      resolver/channel.go
  2. 5
      resolver/log.go
  3. 39
      resolver/types/channel.go

59
resolver/channel.go

@ -6,24 +6,22 @@ import (
"git.aiterp.net/rpdata/api/internal/session"
"git.aiterp.net/rpdata/api/model/change"
"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
type ChannelArgs struct {
Name string
}
// 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)
if err != nil {
return nil, err
}
return &ChannelResolver{C: channel}, nil
return &types.ChannelResolver{C: channel}, nil
}
// ChannelsArgs is args for channel query
@ -32,15 +30,15 @@ type ChannelsArgs struct {
}
// 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)
if err != nil {
return nil, err
}
resolvers := make([]*ChannelResolver, len(channels))
resolvers := make([]*types.ChannelResolver, len(channels))
for i := range channels {
resolvers[i] = &ChannelResolver{C: channels[i]}
resolvers[i] = &types.ChannelResolver{C: channels[i]}
}
return resolvers, nil
@ -58,7 +56,7 @@ type ChannelAddArgs struct {
}
// 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
user := session.FromContext(ctx).User()
@ -92,7 +90,7 @@ func (r *MutationResolver) AddChannel(ctx context.Context, args *ChannelAddArgs)
"event": input.EventName,
})
return &ChannelResolver{C: channel}, nil
return &types.ChannelResolver{C: channel}, nil
}
// ChannelEditArgs is input for the editChannel mutation
@ -107,7 +105,7 @@ type ChannelEditArgs struct {
}
// 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
user := session.FromContext(ctx).User()
@ -132,11 +130,11 @@ func (r *MutationResolver) EditChannel(ctx context.Context, args *ChannelEditArg
"event": input.EventName,
})
return &ChannelResolver{C: channel}, nil
return &types.ChannelResolver{C: channel}, nil
}
// 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()
if user == nil || !user.Permitted("channel.remove") {
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)
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
}

5
resolver/log.go

@ -7,6 +7,7 @@ import (
"git.aiterp.net/rpdata/api/loader"
"git.aiterp.net/rpdata/api/model/change"
"git.aiterp.net/rpdata/api/resolver/types"
"git.aiterp.net/rpdata/api/internal/session"
"git.aiterp.net/rpdata/api/model/log"
@ -258,7 +259,7 @@ func (r *LogResolver) ChannelName() string {
}
// Channel resolves Log.channe
func (r *LogResolver) Channel(ctx context.Context) (*ChannelResolver, error) {
func (r *LogResolver) Channel(ctx context.Context) (*types.ChannelResolver, error) {
loader := loader.FromContext(ctx)
if loader == nil {
return nil, errors.New("no loader")
@ -269,7 +270,7 @@ func (r *LogResolver) Channel(ctx context.Context) (*ChannelResolver, error) {
return nil, err
}
return &ChannelResolver{C: channel}, nil
return &types.ChannelResolver{C: channel}, nil
}
// Title resolves Log.title

39
resolver/types/channel.go

@ -0,0 +1,39 @@
package types
import "git.aiterp.net/rpdata/api/model/channel"
// ChannelResolver for the Channel graphql type
type ChannelResolver struct{ C channel.Channel }
// 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
}
Loading…
Cancel
Save