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.
117 lines
2.3 KiB
117 lines
2.3 KiB
package types
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"git.aiterp.net/rpdata/api/loader"
|
|
"git.aiterp.net/rpdata/api/model/log"
|
|
)
|
|
|
|
// LogResolver for the Log graphql type
|
|
type LogResolver struct{ L log.Log }
|
|
|
|
// ID resolves Log.id
|
|
func (r *LogResolver) ID() string {
|
|
return r.L.ID
|
|
}
|
|
|
|
// ShortID resolves Log.shortId
|
|
func (r *LogResolver) ShortID() string {
|
|
return r.L.ShortID
|
|
}
|
|
|
|
// Date resolves Log.date
|
|
func (r *LogResolver) Date() string {
|
|
return r.L.Date.Format(time.RFC3339Nano)
|
|
}
|
|
|
|
// ChannelName resolves Log.channelName
|
|
func (r *LogResolver) ChannelName() string {
|
|
return r.L.Channel
|
|
}
|
|
|
|
// Channel resolves Log.channe
|
|
func (r *LogResolver) Channel(ctx context.Context) (*ChannelResolver, error) {
|
|
loader := loader.FromContext(ctx)
|
|
if loader == nil {
|
|
return nil, errors.New("no loader")
|
|
}
|
|
|
|
channel, err := loader.Channel("name", r.L.Channel)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &ChannelResolver{C: channel}, nil
|
|
}
|
|
|
|
// Title resolves Log.title
|
|
func (r *LogResolver) Title() string {
|
|
return r.L.Title
|
|
}
|
|
|
|
// Event resolves Log.event
|
|
func (r *LogResolver) Event() string {
|
|
return r.L.Event
|
|
}
|
|
|
|
// Description resolves Log.description
|
|
func (r *LogResolver) Description() string {
|
|
return r.L.Description
|
|
}
|
|
|
|
// Open resolves Log.open
|
|
func (r *LogResolver) Open() bool {
|
|
return r.L.Open
|
|
}
|
|
|
|
// Characters resolves Log.characters
|
|
func (r *LogResolver) Characters(ctx context.Context) ([]*CharacterResolver, error) {
|
|
loader := loader.FromContext(ctx)
|
|
if loader == nil {
|
|
return nil, errors.New("no loader")
|
|
}
|
|
|
|
chars, err := loader.Characters("id", r.L.CharacterIDs...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resolvers := make([]*CharacterResolver, 0, len(chars))
|
|
for i := range chars {
|
|
if chars[i].ID == "" {
|
|
continue
|
|
}
|
|
|
|
resolvers = append(resolvers, &CharacterResolver{C: chars[i]})
|
|
}
|
|
|
|
return resolvers, nil
|
|
}
|
|
|
|
// Posts resolves Log.posts
|
|
func (r *LogResolver) Posts(ctx context.Context, args *LogPostArgs) ([]*PostResolver, error) {
|
|
var kinds []string
|
|
if args.Kinds != nil {
|
|
kinds = *args.Kinds
|
|
}
|
|
|
|
posts, err := r.L.Posts(kinds...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resolvers := make([]*PostResolver, len(posts))
|
|
for i := range posts {
|
|
resolvers[i] = &PostResolver{posts[i]}
|
|
}
|
|
|
|
return resolvers, nil
|
|
}
|
|
|
|
// LogPostArgs is an arg
|
|
type LogPostArgs struct {
|
|
Kinds *[]string
|
|
}
|