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.

66 lines
1.4 KiB

  1. package resolver
  2. import (
  3. "context"
  4. "time"
  5. "git.aiterp.net/rpdata/api/model/story"
  6. )
  7. // ChapterResolver for the Chapter graphql type
  8. type ChapterResolver struct{ C story.Chapter }
  9. // ChapterArgs is args for channel query
  10. type ChapterArgs struct {
  11. ID string
  12. }
  13. // Chapter implements the channel query
  14. func (r *QueryResolver) Chapter(ctx context.Context, args *ChapterArgs) (*ChapterResolver, error) {
  15. chapter, err := story.FindChapterID(args.ID)
  16. if err != nil {
  17. return nil, err
  18. }
  19. return &ChapterResolver{C: chapter}, nil
  20. }
  21. // ID resolves Chapter.id
  22. func (r *ChapterResolver) ID() string {
  23. return r.C.ID
  24. }
  25. // StoryID resolves Chapter.storyId
  26. func (r *ChapterResolver) StoryID() string {
  27. return r.C.StoryID
  28. }
  29. // Title resolves Chapter.title
  30. func (r *ChapterResolver) Title() string {
  31. return r.C.Title
  32. }
  33. // Author resolves Chapter.author
  34. func (r *ChapterResolver) Author() string {
  35. return r.C.Author
  36. }
  37. // Source resolves Chapter.source
  38. func (r *ChapterResolver) Source() string {
  39. return r.C.Source
  40. }
  41. // CreatedDate resolves Chapter.createdDate
  42. func (r *ChapterResolver) CreatedDate() string {
  43. return r.C.CreatedDate.Format(time.RFC3339Nano)
  44. }
  45. // FictionalDate resolves Chapter.fictionalDate
  46. func (r *ChapterResolver) FictionalDate() string {
  47. return r.C.FictionalDate.Format(time.RFC3339Nano)
  48. }
  49. // EditedDate resolves Chapter.editedDate
  50. func (r *ChapterResolver) EditedDate() string {
  51. return r.C.EditedDate.Format(time.RFC3339Nano)
  52. }