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.

35 lines
766 B

  1. package types
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/services"
  5. "time"
  6. "git.aiterp.net/rpdata/api/models"
  7. )
  8. type chapterResolver struct {
  9. stories *services.StoryService
  10. }
  11. func (r *chapterResolver) FictionalDate(ctx context.Context, chapter *models.Chapter) (*time.Time, error) {
  12. if chapter.FictionalDate.IsZero() {
  13. return nil, nil
  14. }
  15. return &chapter.FictionalDate, nil
  16. }
  17. func (r *chapterResolver) Comments(ctx context.Context, chapter *models.Chapter, limit *int) ([]*models.Comment, error) {
  18. if limit == nil {
  19. limit = new(int)
  20. *limit = 0
  21. }
  22. return r.stories.ListComments(ctx, *chapter, *limit)
  23. }
  24. // ChapterResolver is a resolver
  25. func ChapterResolver(s *services.Bundle) *chapterResolver {
  26. return &chapterResolver{stories: s.Stories}
  27. }