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.

45 lines
1001 B

  1. package mutations
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/graphql/resolver/types"
  5. "git.aiterp.net/rpdata/api/internal/session"
  6. "git.aiterp.net/rpdata/api/model/change"
  7. "git.aiterp.net/rpdata/api/model/log"
  8. )
  9. // PostMoveArgs is args for movePost mutation
  10. type PostMoveArgs struct {
  11. Input *struct {
  12. ID string
  13. ToPosition int32
  14. }
  15. }
  16. // MovePost resolves the movePost mutation
  17. func (r *MutationResolver) MovePost(ctx context.Context, args *PostMoveArgs) (*types.PostResolver, error) {
  18. input := args.Input
  19. user := session.FromContext(ctx).User()
  20. if user == nil || !user.Permitted("post.move") {
  21. return nil, ErrUnauthorized
  22. }
  23. post, err := log.FindPostID(input.ID)
  24. if err != nil {
  25. return nil, err
  26. }
  27. err = post.Move(int(input.ToPosition))
  28. if err != nil {
  29. return nil, err
  30. }
  31. go change.Submit("Post", "move", user.ID, post.ID, map[string]interface{}{
  32. "logId": post.LogID,
  33. "targetIndex": input.ToPosition,
  34. })
  35. return &types.PostResolver{P: post}, nil
  36. }