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
1005 B

  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. // LogResolver is a resolver
  27. func LogResolver(s *services.Bundle) *logResolver {
  28. return &logResolver{characters: s.Characters, logs: s.Logs, channels: s.Channels}
  29. }