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
869 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. // 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. user := session.FromContext(ctx).User()
  16. if user == nil || !user.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", user.ID, post.ID, map[string]interface{}{
  24. "logId": post.LogID,
  25. })
  26. go log.UpdateCharacters(post.LogID)
  27. return &types.PostResolver{P: post}, nil
  28. }