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
985 B

  1. package mutations
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/graphql/resolver/types"
  5. "git.aiterp.net/rpdata/api/internal/auth"
  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. token := auth.TokenFromContext(ctx)
  20. if !token.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", token.UserID, post.ID, map[string]interface{}{
  32. "logId": post.LogID,
  33. "targetIndex": input.ToPosition,
  34. })
  35. return &types.PostResolver{P: post}, nil
  36. }