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.

37 lines
903 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/story"
  8. )
  9. // RemoveChapterArgs is args for the addChapter mutation
  10. type RemoveChapterArgs struct {
  11. ID string
  12. }
  13. // RemoveChapter resolves the removeChapter mutation
  14. func (r *MutationResolver) RemoveChapter(ctx context.Context, args *RemoveChapterArgs) (*types.ChapterResolver, error) {
  15. user := session.FromContext(ctx).User()
  16. if user == nil || !user.Permitted("member", "chapter.edit") {
  17. return nil, ErrUnauthorized
  18. }
  19. chapter, err := story.FindChapterID(args.ID)
  20. if err != nil {
  21. return nil, err
  22. }
  23. err = chapter.Remove()
  24. if err != nil {
  25. return nil, err
  26. }
  27. go change.Submit("Chapter", "remove", user.ID, chapter.ID, nil)
  28. return &types.ChapterResolver{C: chapter}, nil
  29. }