|
|
package types
import ( "context" "errors"
"git.aiterp.net/rpdata/api/internal/loader" "git.aiterp.net/rpdata/api/models" "git.aiterp.net/rpdata/api/models/posts" )
type logResolver struct{}
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) { loader := loader.FromContext(ctx) if loader == nil { return nil, errors.New("no loader") }
characters, err := loader.Characters("id", log.CharacterIDs...) if err != nil { return nil, err }
characters2 := make([]*models.Character, len(characters)) for i := range characters { characters2[i] = &characters[i] }
return characters2, nil }
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
var LogResolver logResolver
|