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/session" "git.aiterp.net/rpdata/api/model/change" "git.aiterp.net/rpdata/api/model/log" )
// PostMoveArgs is args for movePost mutation
type PostMoveArgs struct { Input *struct { ID string ToPosition int32 } }
// MovePost resolves the movePost mutation
func (r *MutationResolver) MovePost(ctx context.Context, args *PostMoveArgs) (*types.PostResolver, error) { input := args.Input
user := session.FromContext(ctx).User() if user == nil || !user.Permitted("post.move") { return nil, ErrUnauthorized }
post, err := log.FindPostID(input.ID) if err != nil { return nil, err }
err = post.Move(int(input.ToPosition)) if err != nil { return nil, err }
go change.Submit("Post", "move", user.ID, post.ID, map[string]interface{}{ "logId": post.LogID, "targetIndex": input.ToPosition, })
return &types.PostResolver{P: post}, nil }
|