package mutations import ( "context" "git.aiterp.net/rpdata/api/graphql/resolver/types" "git.aiterp.net/rpdata/api/internal/session" "git.aiterp.net/rpdata/api/model/change" "git.aiterp.net/rpdata/api/model/story" ) // StoryRemoveArgs is args for the removeStory mutation type StoryRemoveArgs struct { ID string } // RemoveStory resolves the removeStory mutation func (r *MutationResolver) RemoveStory(ctx context.Context, args *StoryRemoveArgs) (*types.StoryResolver, error) { user := session.FromContext(ctx).User() if user == nil || !user.Permitted("member", "story.edit") { return nil, ErrUnauthorized } story, err := story.FindID(args.ID) if err != nil { return nil, err } if story.Author != user.ID && !user.Permitted("story.remove") { return nil, ErrPermissionDenied } err = story.Remove() if err != nil { return nil, err } go change.Submit("Story", "remove", user.ID, story.ID, nil) return &types.StoryResolver{S: story}, nil }