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.

45 lines
1.3 KiB

  1. package types
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/services"
  5. "git.aiterp.net/rpdata/api/models"
  6. )
  7. type logResolver struct {
  8. logs *services.LogService
  9. characters *services.CharacterService
  10. channels *services.ChannelService
  11. }
  12. func (r *logResolver) Channel(ctx context.Context, log *models.Log) (*models.Channel, error) {
  13. return r.channels.Find(ctx, log.ChannelName)
  14. }
  15. func (r *logResolver) Characters(ctx context.Context, log *models.Log) ([]*models.Character, error) {
  16. if len(log.CharacterIDs) == 0 {
  17. return []*models.Character{}, nil
  18. }
  19. return r.characters.List(ctx, models.CharacterFilter{
  20. IDs: log.CharacterIDs,
  21. })
  22. }
  23. func (r *logResolver) Posts(ctx context.Context, log *models.Log, kinds []string) ([]*models.Post, error) {
  24. return r.logs.ListPosts(ctx, &models.PostFilter{LogID: &log.ShortID})
  25. }
  26. func (r *logResolver) NextLogs(ctx context.Context, obj *models.Log) ([]*models.LogSuggestion, error) {
  27. return r.logs.NextLogs(ctx, obj)
  28. }
  29. func (r *logResolver) PrevLogs(ctx context.Context, obj *models.Log) ([]*models.LogSuggestion, error) {
  30. return r.logs.PrevLogs(ctx, obj)
  31. }
  32. // LogResolver is a resolver
  33. func LogResolver(s *services.Bundle) *logResolver {
  34. return &logResolver{characters: s.Characters, logs: s.Logs, channels: s.Channels}
  35. }