package types import ( "context" "git.aiterp.net/rpdata/api/repositories" "git.aiterp.net/rpdata/api/services" "github.com/globalsign/mgo" "time" "git.aiterp.net/rpdata/api/models" ) type commentResolver struct { characters *services.CharacterService } func (r *commentResolver) Character(ctx context.Context, obj *models.Comment) (*models.Character, error) { if obj.CharacterID == "" { return nil, nil } character, err := r.characters.Find(ctx, obj.CharacterID) if err != nil { if err == repositories.ErrNotFound || err == mgo.ErrNotFound { return nil, nil } return nil, err } return character, nil } func (r *commentResolver) FictionalDate(ctx context.Context, obj *models.Comment) (*time.Time, error) { if obj.FictionalDate.IsZero() { return nil, nil } return &obj.FictionalDate, nil } // CommentResolver is a resolver func CommentResolver(s *services.Bundle) *commentResolver { return &commentResolver{characters: s.Characters} }