package resolvers import ( "context" "time" "git.aiterp.net/rpdata/api/graph2/graphcore" "git.aiterp.net/rpdata/api/models" ) // Queries func (r *queryResolver) Comment(ctx context.Context, id string) (*models.Comment, error) { return r.s.Stories.FindComment(ctx, id) } // Mutations func (r *mutationResolver) AddComment(ctx context.Context, input graphcore.CommentAddInput) (*models.Comment, error) { chapter, err := r.s.Stories.FindChapter(ctx, input.ChapterID) if err != nil { return nil, err } subject := "" if input.Subject != nil { subject = *input.Subject } fictionalDate := time.Time{} if input.FictionalDate != nil { fictionalDate = *input.FictionalDate } return r.s.Stories.CreateComment(ctx, *chapter, subject, "", input.Source, input.CharacterName, input.CharacterID, time.Now(), fictionalDate) } func (r *mutationResolver) EditComment(ctx context.Context, input graphcore.CommentEditInput) (*models.Comment, error) { comment, err := r.s.Stories.FindComment(ctx, input.CommentID) if err != nil { return nil, err } fictionalDate := input.FictionalDate if input.ClearFictionalDate != nil && *input.ClearFictionalDate { fictionalDate = &time.Time{} } return r.s.Stories.EditComment(ctx, comment, input.Source, input.CharacterName, input.CharacterID, input.Subject, fictionalDate) } func (r *mutationResolver) RemoveComment(ctx context.Context, input graphcore.CommentRemoveInput) (*models.Comment, error) { comment, err := r.s.Stories.FindComment(ctx, input.CommentID) if err != nil { return nil, err } err = r.s.Stories.RemoveComment(ctx, comment) if err != nil { return nil, err } return comment, nil }