GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

64 lines
1.6 KiB

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
}