graph2: Added move mutation to chapter.
the build was successful

This commit is contained in:
2018-10-27 14:59:47 +02:00
parent cf545cde3b
commit 9affdbd20e
4 changed files with 63 additions and 0 deletions
+23
View File
@@ -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)
}
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) {
chapter, err := chapters.FindID(input.ID)
if err != nil {
+3
View File
@@ -81,6 +81,9 @@ type Mutation {
# Edit a chapter
editChapter(input: ChapterEditInput!): Chapter!
# Move a chapter
moveChapter(input: ChapterMoveInput!): Chapter!
# Remove a chapter
removeChapter(input: ChapterRemoveInput!): Chapter!
+9
View File
@@ -61,6 +61,15 @@ input ChapterEditInput {
clearFictionalDate: Boolean
}
# Input for moveChapter mutation
input ChapterMoveInput {
# The chapter to move
id: String!
# The story to move it to
storyId: String!
}
# Input for removeChapter mutation
input ChapterRemoveInput {
# The chapter to remove