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

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}
}