package resolvers import ( "context" "time" "git.aiterp.net/rpdata/api/graph2/graphcore" "git.aiterp.net/rpdata/api/models" ) // Queries func (r *queryResolver) Chapter(ctx context.Context, id string) (*models.Chapter, error) { return r.s.Stories.FindChapter(ctx, id) } // Mutations func (r *mutationResolver) AddChapter(ctx context.Context, input graphcore.ChapterAddInput) (*models.Chapter, error) { story, err := r.s.Stories.FindStory(ctx, input.StoryID) if err != nil { return nil, err } commentMode := models.ChapterCommentModeDisabled if input.CommentMode != nil { commentMode = *input.CommentMode } return r.s.Stories.CreateChapter(ctx, *story, input.Title, input.Source, input.Author, time.Now(), input.FictionalDate, commentMode) } func (r *mutationResolver) MoveChapter(ctx context.Context, input graphcore.ChapterMoveInput) (*models.Chapter, error) { chapter, err := r.s.Stories.FindChapter(ctx, input.ID) if err != nil { return nil, err } from, err := r.s.Stories.FindStory(ctx, chapter.StoryID) if err != nil { return nil, err } to, err := r.s.Stories.FindStory(ctx, input.StoryID) if err != nil { return nil, err } return r.s.Stories.MoveChapter(ctx, chapter, *from, *to) } func (r *mutationResolver) EditChapter(ctx context.Context, input graphcore.ChapterEditInput) (*models.Chapter, error) { chapter, err := r.s.Stories.FindChapter(ctx, input.ID) if err != nil { return nil, err } return r.s.Stories.EditChapter(ctx, chapter, input.Title, input.Source, input.FictionalDate, input.CommentMode, input.CommentsLocked) } func (r *mutationResolver) RemoveChapter(ctx context.Context, input graphcore.ChapterRemoveInput) (*models.Chapter, error) { chapter, err := r.s.Stories.FindChapter(ctx, input.ID) if err != nil { return nil, err } err = r.s.Stories.RemoveChapter(ctx, chapter) if err != nil { return nil, err } return chapter, nil }