Browse Source

Moved StoryResolver and TagResolver into resolvers/types package, updated references to it.

1.0
Gisle Aune 6 years ago
parent
commit
5fedce5899
  1. 103
      resolver/story.go
  2. 24
      resolver/tag.go
  3. 80
      resolver/types/story.go
  4. 16
      resolver/types/tag.go

103
resolver/story.go

@ -10,22 +10,19 @@ import (
"git.aiterp.net/rpdata/api/resolver/types"
)
// StoryResolver for the Story graphql type
type StoryResolver struct{ S story.Story }
// StoryArgs is args for story query
type StoryArgs struct {
ID string
}
// Story implements the story query
func (r *QueryResolver) Story(ctx context.Context, args *StoryArgs) (*StoryResolver, error) {
func (r *QueryResolver) Story(ctx context.Context, args *StoryArgs) (*types.StoryResolver, error) {
story, err := story.FindID(args.ID)
if err != nil {
return nil, err
}
return &StoryResolver{S: story}, nil
return &types.StoryResolver{S: story}, nil
}
// StoriesArg is args for stories query
@ -40,7 +37,7 @@ type StoriesArg struct {
}
// Stories implements the stories query
func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*StoryResolver, error) {
func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*types.StoryResolver, error) {
filter := args.Filter
author := ""
@ -85,9 +82,9 @@ func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*Story
return nil, err
}
resolvers := make([]*StoryResolver, len(stories))
resolvers := make([]*types.StoryResolver, len(stories))
for i, story := range stories {
resolvers[i] = &StoryResolver{S: story}
resolvers[i] = &types.StoryResolver{S: story}
}
return resolvers, nil
@ -107,7 +104,7 @@ type StoryAddArgs struct {
}
// AddStory implements the addStory mutation
func (r *MutationResolver) AddStory(ctx context.Context, args *StoryAddArgs) (*StoryResolver, error) {
func (r *MutationResolver) AddStory(ctx context.Context, args *StoryAddArgs) (*types.StoryResolver, error) {
input := args.Input
user := session.FromContext(ctx).User()
@ -159,7 +156,7 @@ func (r *MutationResolver) AddStory(ctx context.Context, args *StoryAddArgs) (*S
"author": input.Author,
})
return &StoryResolver{S: story}, nil
return &types.StoryResolver{S: story}, nil
}
// StoryTagAddArgs is args for the addStoryTag mutation
@ -171,7 +168,7 @@ type StoryTagAddArgs struct {
}
// AddStoryTag implements the addStoryTag mutation
func (r *MutationResolver) AddStoryTag(ctx context.Context, args *StoryTagAddArgs) (*StoryResolver, error) {
func (r *MutationResolver) AddStoryTag(ctx context.Context, args *StoryTagAddArgs) (*types.StoryResolver, error) {
input := args.Input
tag := story.Tag{Kind: input.Tag.Kind, Name: input.Tag.Name}
@ -199,7 +196,7 @@ func (r *MutationResolver) AddStoryTag(ctx context.Context, args *StoryTagAddArg
"name": tag.Name,
})
return &StoryResolver{S: story}, nil
return &types.StoryResolver{S: story}, nil
}
// StoryTagRemoveArgs is args for the removeStoryTag mutation
@ -211,7 +208,7 @@ type StoryTagRemoveArgs struct {
}
// RemoveStoryTag implements the removeStoryTag mutation
func (r *MutationResolver) RemoveStoryTag(ctx context.Context, args *StoryTagRemoveArgs) (*StoryResolver, error) {
func (r *MutationResolver) RemoveStoryTag(ctx context.Context, args *StoryTagRemoveArgs) (*types.StoryResolver, error) {
input := args.Input
tag := story.Tag{Kind: input.Tag.Kind, Name: input.Tag.Name}
@ -239,7 +236,7 @@ func (r *MutationResolver) RemoveStoryTag(ctx context.Context, args *StoryTagRem
"name": tag.Name,
})
return &StoryResolver{S: story}, nil
return &types.StoryResolver{S: story}, nil
}
// StoryEditArgs is args for the addStory mutation
@ -256,7 +253,7 @@ type StoryEditArgs struct {
}
// EditStory implements the editStory mutation
func (r *MutationResolver) EditStory(ctx context.Context, args *StoryEditArgs) (*StoryResolver, error) {
func (r *MutationResolver) EditStory(ctx context.Context, args *StoryEditArgs) (*types.StoryResolver, error) {
input := args.Input
user := session.FromContext(ctx).User()
@ -297,7 +294,7 @@ func (r *MutationResolver) EditStory(ctx context.Context, args *StoryEditArgs) (
"fictionalDate": input.FictionalDate,
})
return &StoryResolver{S: story}, nil
return &types.StoryResolver{S: story}, nil
}
// StoryRemoveArgs is args for the removeStory mutation
@ -306,7 +303,7 @@ type StoryRemoveArgs struct {
}
// RemoveStory implements the removeStory mutation
func (r *MutationResolver) RemoveStory(ctx context.Context, args *StoryRemoveArgs) (*StoryResolver, error) {
func (r *MutationResolver) RemoveStory(ctx context.Context, args *StoryRemoveArgs) (*types.StoryResolver, error) {
user := session.FromContext(ctx).User()
if user == nil || !user.Permitted("member", "story.edit") {
return nil, ErrUnauthorized
@ -328,75 +325,5 @@ func (r *MutationResolver) RemoveStory(ctx context.Context, args *StoryRemoveArg
go change.Submit("Story", "remove", user.ID, story.ID, nil)
return &StoryResolver{S: story}, nil
}
// ID resolves Story.id
func (r *StoryResolver) ID() string {
return r.S.ID
}
// Author resolves Story.author
func (r *StoryResolver) Author() string {
return r.S.Author
}
// Name resolves Story.name
func (r *StoryResolver) Name() string {
return r.S.Name
}
// Category resolves Story.category
func (r *StoryResolver) Category() string {
return r.S.Category
}
// Open resolves Story.open
func (r *StoryResolver) Open() bool {
return r.S.Open
}
// Listed resolves Story.listed
func (r *StoryResolver) Listed() bool {
return r.S.Listed
}
// Tags resolves Story.tags
func (r *StoryResolver) Tags() []*TagResolver {
resolvers := make([]*TagResolver, len(r.S.Tags))
for i, tag := range r.S.Tags {
resolvers[i] = &TagResolver{T: tag}
}
return resolvers
}
// Chapters resolves Story.chapters
func (r *StoryResolver) Chapters() ([]*types.ChapterResolver, error) {
chapters, err := r.S.Chapters()
if err != nil {
return nil, err
}
resolvers := make([]*types.ChapterResolver, len(chapters))
for i, chapter := range chapters {
resolvers[i] = &types.ChapterResolver{C: chapter}
}
return resolvers, nil
}
// CreatedDate resolves Story.createdDate
func (r *StoryResolver) CreatedDate() string {
return r.S.CreatedDate.Format(time.RFC3339Nano)
}
// FictionalDate resolves Story.fictionalDate
func (r *StoryResolver) FictionalDate() string {
return r.S.FictionalDate.Format(time.RFC3339Nano)
}
// UpdatedDate resolves Story.updatedDate
func (r *StoryResolver) UpdatedDate() string {
return r.S.UpdatedDate.Format(time.RFC3339Nano)
return &types.StoryResolver{S: story}, nil
}

24
resolver/tag.go

@ -1,9 +1,9 @@
package resolver
import "git.aiterp.net/rpdata/api/model/story"
// TagResolver for the Tag graphql type
type TagResolver struct{ T story.Tag }
import (
"git.aiterp.net/rpdata/api/model/story"
"git.aiterp.net/rpdata/api/resolver/types"
)
// TagInput resolves the TagInput input
type TagInput struct {
@ -12,26 +12,16 @@ type TagInput struct {
}
// Tags implements the tags query
func (r *QueryResolver) Tags() ([]*TagResolver, error) {
func (r *QueryResolver) Tags() ([]*types.TagResolver, error) {
tags, err := story.ListTags()
if err != nil {
return nil, err
}
resolvers := make([]*TagResolver, len(tags))
resolvers := make([]*types.TagResolver, len(tags))
for i, tag := range tags {
resolvers[i] = &TagResolver{T: tag}
resolvers[i] = &types.TagResolver{T: tag}
}
return resolvers, nil
}
// Kind resolves Tag.kind
func (r *TagResolver) Kind() string {
return r.T.Kind
}
// Name resolves Tag.name
func (r *TagResolver) Name() string {
return r.T.Name
}

80
resolver/types/story.go

@ -0,0 +1,80 @@
package types
import (
"time"
"git.aiterp.net/rpdata/api/model/story"
)
// StoryResolver for the Story graphql type
type StoryResolver struct{ S story.Story }
// ID resolves Story.id
func (r *StoryResolver) ID() string {
return r.S.ID
}
// Author resolves Story.author
func (r *StoryResolver) Author() string {
return r.S.Author
}
// Name resolves Story.name
func (r *StoryResolver) Name() string {
return r.S.Name
}
// Category resolves Story.category
func (r *StoryResolver) Category() string {
return r.S.Category
}
// Open resolves Story.open
func (r *StoryResolver) Open() bool {
return r.S.Open
}
// Listed resolves Story.listed
func (r *StoryResolver) Listed() bool {
return r.S.Listed
}
// Tags resolves Story.tags
func (r *StoryResolver) Tags() []*TagResolver {
resolvers := make([]*TagResolver, len(r.S.Tags))
for i, tag := range r.S.Tags {
resolvers[i] = &TagResolver{T: tag}
}
return resolvers
}
// Chapters resolves Story.chapters
func (r *StoryResolver) Chapters() ([]*ChapterResolver, error) {
chapters, err := r.S.Chapters()
if err != nil {
return nil, err
}
resolvers := make([]*ChapterResolver, len(chapters))
for i, chapter := range chapters {
resolvers[i] = &ChapterResolver{C: chapter}
}
return resolvers, nil
}
// CreatedDate resolves Story.createdDate
func (r *StoryResolver) CreatedDate() string {
return r.S.CreatedDate.Format(time.RFC3339Nano)
}
// FictionalDate resolves Story.fictionalDate
func (r *StoryResolver) FictionalDate() string {
return r.S.FictionalDate.Format(time.RFC3339Nano)
}
// UpdatedDate resolves Story.updatedDate
func (r *StoryResolver) UpdatedDate() string {
return r.S.UpdatedDate.Format(time.RFC3339Nano)
}

16
resolver/types/tag.go

@ -0,0 +1,16 @@
package types
import "git.aiterp.net/rpdata/api/model/story"
// TagResolver for the Tag graphql type
type TagResolver struct{ T story.Tag }
// Kind resolves Tag.kind
func (r *TagResolver) Kind() string {
return r.T.Kind
}
// Name resolves Tag.name
func (r *TagResolver) Name() string {
return r.T.Name
}
Loading…
Cancel
Save