package types import ( "context" "errors" "git.aiterp.net/rpdata/api/services" "git.aiterp.net/rpdata/api/internal/loader" "git.aiterp.net/rpdata/api/models" "git.aiterp.net/rpdata/api/models/posts" ) type logResolver struct { characters *services.CharacterService } func (r *logResolver) Channel(ctx context.Context, log *models.Log) (*models.Channel, error) { loader := loader.FromContext(ctx) if loader == nil { return nil, errors.New("no loader") } return loader.Channel("name", 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) { posts, err := posts.List(&posts.Filter{LogID: &log.ShortID, Kind: kinds, Limit: 0}) if err != nil { return nil, err } posts2 := make([]*models.Post, len(posts)) for i := range posts { posts2[i] = &posts[i] } return posts2, nil } // LogResolver is a resolver func LogResolver(s *services.Bundle) *logResolver { return &logResolver{characters: s.Characters} }