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.

96 lines
2.0 KiB

  1. package resolver
  2. import (
  3. "context"
  4. "time"
  5. "git.aiterp.net/rpdata/api/model/story"
  6. )
  7. // StoryResolver for the Story graphql type
  8. type StoryResolver struct{ S story.Story }
  9. // StoryArgs is args for channel query
  10. type StoryArgs struct {
  11. ID string
  12. }
  13. // Story implements the channel query
  14. func (r *QueryResolver) Story(ctx context.Context, args *StoryArgs) (*StoryResolver, error) {
  15. story, err := story.FindID(args.ID)
  16. if err != nil {
  17. return nil, err
  18. }
  19. return &StoryResolver{S: story}, nil
  20. }
  21. // ID resolves Story.id
  22. func (r *StoryResolver) ID() string {
  23. return r.S.ID
  24. }
  25. // Author resolves Story.author
  26. func (r *StoryResolver) Author() string {
  27. return r.S.Author
  28. }
  29. // Name resolves Story.name
  30. func (r *StoryResolver) Name() string {
  31. return r.S.Name
  32. }
  33. // Category resolves Story.category
  34. func (r *StoryResolver) Category() string {
  35. return r.S.Category
  36. }
  37. // Open resolves Story.open
  38. func (r *StoryResolver) Open() bool {
  39. return r.S.Open
  40. }
  41. // Listed resolves Story.listed
  42. func (r *StoryResolver) Listed() bool {
  43. return r.S.Listed
  44. }
  45. // Tags resolves Story.tags
  46. func (r *StoryResolver) Tags() []*TagResolver {
  47. resolvers := make([]*TagResolver, len(r.S.Tags))
  48. for i, tag := range r.S.Tags {
  49. resolvers[i] = &TagResolver{T: tag}
  50. }
  51. return resolvers
  52. }
  53. // Chapters resolves Story.chapters
  54. func (r *StoryResolver) Chapters() ([]*ChapterResolver, error) {
  55. chapters, err := r.S.Chapters()
  56. if err != nil {
  57. return nil, err
  58. }
  59. resolvers := make([]*ChapterResolver, len(chapters))
  60. for i, chapter := range chapters {
  61. resolvers[i] = &ChapterResolver{C: chapter}
  62. }
  63. return resolvers, nil
  64. }
  65. // CreatedDate resolves Story.createdDate
  66. func (r *StoryResolver) CreatedDate() string {
  67. return r.S.CreatedDate.Format(time.RFC3339Nano)
  68. }
  69. // FictionalDate resolves Story.fictionalDate
  70. func (r *StoryResolver) FictionalDate() string {
  71. return r.S.FictionalDate.Format(time.RFC3339Nano)
  72. }
  73. // UpdatedDate resolves Story.updatedDate
  74. func (r *StoryResolver) UpdatedDate() string {
  75. return r.S.UpdatedDate.Format(time.RFC3339Nano)
  76. }