2024-06-24 23:34:10 +00:00
|
|
|
package graph
|
|
|
|
|
|
|
|
// This file will be automatically regenerated based on the schema, any resolver implementations
|
|
|
|
// will be copied through when generating and any unknown code will be moved to the end.
|
|
|
|
// Code generated by github.com/99designs/gqlgen version v0.17.49
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.obamna.ru/erius/ozon-task/graph/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AddPost is the resolver for the add_post field.
|
2024-06-26 01:45:04 +00:00
|
|
|
func (r *mutationResolver) AddPost(ctx context.Context, input model.PostInput) (*model.AddResult, error) {
|
|
|
|
return r.Storage.AddPost(&input)
|
2024-06-24 23:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddComment is the resolver for the add_comment field.
|
2024-06-26 01:45:04 +00:00
|
|
|
func (r *mutationResolver) AddComment(ctx context.Context, input model.CommentInput) (*model.AddResult, error) {
|
2024-06-24 23:34:10 +00:00
|
|
|
if len(input.Contents) > model.CommentLengthLimit {
|
|
|
|
return nil, fmt.Errorf("exceeded max comment length of %d chars", model.CommentLengthLimit)
|
|
|
|
}
|
2024-06-26 01:45:04 +00:00
|
|
|
switch {
|
|
|
|
case input.ParentPostID != nil:
|
|
|
|
return r.Storage.AddCommentToPost(&input)
|
|
|
|
case input.ParentCommentID != nil:
|
|
|
|
return r.Storage.AddReplyToComment(&input)
|
|
|
|
default:
|
2024-06-24 23:34:10 +00:00
|
|
|
return nil, fmt.Errorf("parent post or parent comment ids weren't specified")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mutation returns MutationResolver implementation.
|
|
|
|
func (r *Resolver) Mutation() MutationResolver { return &mutationResolver{r} }
|
|
|
|
|
|
|
|
type mutationResolver struct{ *Resolver }
|