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.
|
|
package mutations
import ( "context"
"git.aiterp.net/rpdata/api/graphql/resolver/types" "git.aiterp.net/rpdata/api/internal/auth" "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) { token := auth.TokenFromContext(ctx) if !token.Permitted("member", "story.edit") { return nil, ErrUnauthorized }
story, err := story.FindID(args.ID) if err != nil { return nil, err }
if story.Author != token.UserID && !token.Permitted("story.remove") { return nil, ErrPermissionDenied }
err = story.Remove() if err != nil { return nil, err }
go change.Submit("Story", "remove", token.UserID, story.ID, nil)
return &types.StoryResolver{S: story}, nil }
|