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.

36 lines
853 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. // PostRemoveArgs is args for the removePost mutation
  10. type PostRemoveArgs struct {
  11. ID string
  12. }
  13. // RemovePost resolves the removePost mutation
  14. func (r *MutationResolver) RemovePost(ctx context.Context, args PostRemoveArgs) (*types.PostResolver, error) {
  15. token := auth.TokenFromContext(ctx)
  16. if !token.Permitted("post.remove") {
  17. return nil, ErrUnauthorized
  18. }
  19. post, err := log.RemovePost(args.ID)
  20. if err != nil {
  21. return nil, err
  22. }
  23. go change.Submit("Post", "remove", token.UserID, post.ID, map[string]interface{}{
  24. "logId": post.LogID,
  25. })
  26. go log.UpdateCharacters(post.LogID)
  27. return &types.PostResolver{P: post}, nil
  28. }