|
|
package types
import ( "context" "git.aiterp.net/rpdata/api/services"
"git.aiterp.net/rpdata/api/models" )
type logResolver struct { logs *services.LogService characters *services.CharacterService channels *services.ChannelService }
func (r *logResolver) Channel(ctx context.Context, log *models.Log) (*models.Channel, error) { return r.channels.Find(ctx, log.ChannelName) }
func (r *logResolver) Characters(ctx context.Context, log *models.Log) ([]*models.Character, error) { if len(log.CharacterIDs) == 0 { return []*models.Character{}, nil }
return r.characters.List(ctx, models.CharacterFilter{ IDs: log.CharacterIDs, }) }
func (r *logResolver) Posts(ctx context.Context, log *models.Log, kinds []string) ([]*models.Post, error) { return r.logs.ListPosts(ctx, &models.PostFilter{LogID: &log.ShortID}) }
func (r *logResolver) NextLogs(ctx context.Context, obj *models.Log) ([]*models.LogSuggestion, error) { return r.logs.NextLogs(ctx, obj) }
func (r *logResolver) PrevLogs(ctx context.Context, obj *models.Log) ([]*models.LogSuggestion, error) { return r.logs.PrevLogs(ctx, obj) }
// LogResolver is a resolver
func LogResolver(s *services.Bundle) *logResolver { return &logResolver{characters: s.Characters, logs: s.Logs, channels: s.Channels} }
|