Browse Source

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

1.0
Gisle Aune 7 years ago
parent
commit
fba499024b
  1. 60
      resolver/chapter.go
  2. 7
      resolver/story.go
  3. 50
      resolver/types/chapter.go

60
resolver/chapter.go

@ -7,24 +7,22 @@ import (
"git.aiterp.net/rpdata/api/internal/session"
"git.aiterp.net/rpdata/api/model/change"
"git.aiterp.net/rpdata/api/model/story"
"git.aiterp.net/rpdata/api/resolver/types"
)
// ChapterResolver for the Chapter graphql type
type ChapterResolver struct{ C story.Chapter }
// ChapterArgs is args for chapter query
type ChapterArgs struct {
ID string
}
// Chapter implements the chapter query
func (r *QueryResolver) Chapter(ctx context.Context, args *ChapterArgs) (*ChapterResolver, error) {
func (r *QueryResolver) Chapter(ctx context.Context, args *ChapterArgs) (*types.ChapterResolver, error) {
chapter, err := story.FindChapterID(args.ID)
if err != nil {
return nil, err
}
return &ChapterResolver{C: chapter}, nil
return &types.ChapterResolver{C: chapter}, nil
}
// AddChapterArgs is args for the addChapter mutation
@ -39,7 +37,7 @@ type AddChapterArgs struct {
}
// AddChapter implements the addChapter mutation
func (r *MutationResolver) AddChapter(ctx context.Context, args *AddChapterArgs) (*ChapterResolver, error) {
func (r *MutationResolver) AddChapter(ctx context.Context, args *AddChapterArgs) (*types.ChapterResolver, error) {
input := args.Input
user := session.FromContext(ctx).User()
@ -80,7 +78,7 @@ func (r *MutationResolver) AddChapter(ctx context.Context, args *AddChapterArgs)
"fictionalDate": fictionalDate,
})
return &ChapterResolver{C: chapter}, nil
return &types.ChapterResolver{C: chapter}, nil
}
// EditChapterArgs is args for the editChapter mutation
@ -94,7 +92,7 @@ type EditChapterArgs struct {
}
// EditChapter implements the editChapter mutation
func (r *MutationResolver) EditChapter(ctx context.Context, args *EditChapterArgs) (*ChapterResolver, error) {
func (r *MutationResolver) EditChapter(ctx context.Context, args *EditChapterArgs) (*types.ChapterResolver, error) {
input := args.Input
user := session.FromContext(ctx).User()
@ -132,7 +130,7 @@ func (r *MutationResolver) EditChapter(ctx context.Context, args *EditChapterArg
"fictionalDate": fictionalDate,
})
return &ChapterResolver{C: chapter}, nil
return &types.ChapterResolver{C: chapter}, nil
}
// DeleteChapterArgs is args for the addChapter mutation
@ -141,7 +139,7 @@ type DeleteChapterArgs struct {
}
// RemoveChapter implements the removeChapter mutation
func (r *MutationResolver) RemoveChapter(ctx context.Context, args *DeleteChapterArgs) (*ChapterResolver, error) {
func (r *MutationResolver) RemoveChapter(ctx context.Context, args *DeleteChapterArgs) (*types.ChapterResolver, error) {
user := session.FromContext(ctx).User()
if user == nil || !user.Permitted("member", "chapter.edit") {
return nil, ErrUnauthorized
@ -159,45 +157,5 @@ func (r *MutationResolver) RemoveChapter(ctx context.Context, args *DeleteChapte
go change.Submit("Chapter", "remove", user.ID, chapter.ID, nil)
return &ChapterResolver{C: chapter}, nil
}
// ID resolves Chapter.id
func (r *ChapterResolver) ID() string {
return r.C.ID
}
// StoryID resolves Chapter.storyId
func (r *ChapterResolver) StoryID() string {
return r.C.StoryID
}
// Title resolves Chapter.title
func (r *ChapterResolver) Title() string {
return r.C.Title
}
// Author resolves Chapter.author
func (r *ChapterResolver) Author() string {
return r.C.Author
}
// Source resolves Chapter.source
func (r *ChapterResolver) Source() string {
return r.C.Source
}
// CreatedDate resolves Chapter.createdDate
func (r *ChapterResolver) CreatedDate() string {
return r.C.CreatedDate.Format(time.RFC3339Nano)
}
// FictionalDate resolves Chapter.fictionalDate
func (r *ChapterResolver) FictionalDate() string {
return r.C.FictionalDate.Format(time.RFC3339Nano)
}
// EditedDate resolves Chapter.editedDate
func (r *ChapterResolver) EditedDate() string {
return r.C.EditedDate.Format(time.RFC3339Nano)
return &types.ChapterResolver{C: chapter}, nil
}

7
resolver/story.go

@ -7,6 +7,7 @@ import (
"git.aiterp.net/rpdata/api/internal/session"
"git.aiterp.net/rpdata/api/model/change"
"git.aiterp.net/rpdata/api/model/story"
"git.aiterp.net/rpdata/api/resolver/types"
)
// StoryResolver for the Story graphql type
@ -371,15 +372,15 @@ func (r *StoryResolver) Tags() []*TagResolver {
}
// Chapters resolves Story.chapters
func (r *StoryResolver) Chapters() ([]*ChapterResolver, error) {
func (r *StoryResolver) Chapters() ([]*types.ChapterResolver, error) {
chapters, err := r.S.Chapters()
if err != nil {
return nil, err
}
resolvers := make([]*ChapterResolver, len(chapters))
resolvers := make([]*types.ChapterResolver, len(chapters))
for i, chapter := range chapters {
resolvers[i] = &ChapterResolver{C: chapter}
resolvers[i] = &types.ChapterResolver{C: chapter}
}
return resolvers, nil

50
resolver/types/chapter.go

@ -0,0 +1,50 @@
package types
import (
"time"
"git.aiterp.net/rpdata/api/model/story"
)
// ChapterResolver for the Chapter graphql type
type ChapterResolver struct{ C story.Chapter }
// ID resolves Chapter.id
func (r *ChapterResolver) ID() string {
return r.C.ID
}
// StoryID resolves Chapter.storyId
func (r *ChapterResolver) StoryID() string {
return r.C.StoryID
}
// Title resolves Chapter.title
func (r *ChapterResolver) Title() string {
return r.C.Title
}
// Author resolves Chapter.author
func (r *ChapterResolver) Author() string {
return r.C.Author
}
// Source resolves Chapter.source
func (r *ChapterResolver) Source() string {
return r.C.Source
}
// CreatedDate resolves Chapter.createdDate
func (r *ChapterResolver) CreatedDate() string {
return r.C.CreatedDate.Format(time.RFC3339Nano)
}
// FictionalDate resolves Chapter.fictionalDate
func (r *ChapterResolver) FictionalDate() string {
return r.C.FictionalDate.Format(time.RFC3339Nano)
}
// EditedDate resolves Chapter.editedDate
func (r *ChapterResolver) EditedDate() string {
return r.C.EditedDate.Format(time.RFC3339Nano)
}
Loading…
Cancel
Save