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/log" ) // PostRemoveArgs is args for the removePost mutation type PostRemoveArgs struct { ID string } // RemovePost resolves the removePost mutation func (r *MutationResolver) RemovePost(ctx context.Context, args PostRemoveArgs) (*types.PostResolver, error) { user := session.FromContext(ctx).User() if user == nil || !user.Permitted("post.remove") { return nil, ErrUnauthorized } post, err := log.RemovePost(args.ID) if err != nil { return nil, err } go change.Submit("Post", "remove", user.ID, post.ID, map[string]interface{}{ "logId": post.LogID, }) go log.UpdateCharacters(post.LogID) return &types.PostResolver{P: post}, nil }