|
@ -48,6 +48,29 @@ func (r *mutationResolver) AddChapter(ctx context.Context, input input.ChapterAd |
|
|
return chapters.Add(story, input.Title, author, input.Source, time.Now(), input.FictionalDate) |
|
|
return chapters.Add(story, input.Title, author, input.Source, time.Now(), input.FictionalDate) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (r *mutationResolver) MoveChapter(ctx context.Context, input input.ChapterMoveInput) (models.Chapter, error) { |
|
|
|
|
|
chapter, err := chapters.FindID(input.ID) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return models.Chapter{}, errors.New("Chapter not found") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
token := auth.TokenFromContext(ctx) |
|
|
|
|
|
if !token.Authenticated() || !token.PermittedUser(chapter.Author, "member", "chapter.move") { |
|
|
|
|
|
return models.Chapter{}, errors.New("You are not allowed to move this chapter") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
target, err := stories.FindID(input.StoryID) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return models.Chapter{}, errors.New("Target story not found") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !target.Open && !token.PermittedUser(target.Author, "member", "chapter.move") { |
|
|
|
|
|
return models.Chapter{}, errors.New("You are not permitted to move chapters to this story") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return chapters.Move(chapter, target) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (r *mutationResolver) EditChapter(ctx context.Context, input input.ChapterEditInput) (models.Chapter, error) { |
|
|
func (r *mutationResolver) EditChapter(ctx context.Context, input input.ChapterEditInput) (models.Chapter, error) { |
|
|
chapter, err := chapters.FindID(input.ID) |
|
|
chapter, err := chapters.FindID(input.ID) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|