refs
import "github.com/Ask-Atlas/AskAtlas/api/internal/refs"
Package refs batches per-entity summaries for inline ref directives (ASK-208). The service fans out to the existing entity tables under their own visibility rules, then collates per-(type, id) entries into a single map.
Index
- func Key(t RefType, id uuid.UUID) string
- type CourseInfo
- type CreatorInfo
- type Ref
- type RefType
- type Repository
- type SchoolInfo
- type Service
- type Summary
func Key
func Key(t RefType, id uuid.UUID) string
Key formats a (type, id) pair into the wire key used in the response map. Exposed so handler + tests share the canonical form.
type CourseInfo
type CourseInfo struct {
Department string
Number string
}
type CreatorInfo
type CreatorInfo struct {
FirstName string
LastName string
}
type Ref
Ref is a (type, id) request pair. Service dedupes on the pair before running lookups.
type Ref struct {
Type RefType
ID uuid.UUID
}
type RefType
RefType is the stable wire identifier for each ref directive.
type RefType string
const (
TypeStudyGuide RefType = "sg"
TypeQuiz RefType = "quiz"
TypeFile RefType = "file"
TypeCourse RefType = "course"
)
type Repository
Repository is the data-access interface required by the refs Service.
type Repository interface {
ListStudyGuideRefSummaries(ctx context.Context, arg db.ListStudyGuideRefSummariesParams) ([]db.ListStudyGuideRefSummariesRow, error)
ListQuizRefSummaries(ctx context.Context, ids []pgtype.UUID) ([]db.ListQuizRefSummariesRow, error)
ListFileRefSummaries(ctx context.Context, arg db.ListFileRefSummariesParams) ([]db.ListFileRefSummariesRow, error)
ListCourseRefSummaries(ctx context.Context, ids []pgtype.UUID) ([]db.ListCourseRefSummariesRow, error)
}
func NewSQLCRepository
func NewSQLCRepository(queries *db.Queries) Repository
NewSQLCRepository returns a Repository backed by sqlc-generated Postgres queries.
type SchoolInfo
type SchoolInfo struct {
Name string
Acronym string
}
type Service
Service is the business-logic layer for the batch refs/resolve endpoint. Given a list of (type, id) refs it dedupes by pair, fans out one query per type in parallel, and returns a map keyed "type:id". Keys for refs the viewer can't see or that don't exist are present in the map with a nil Summary -- the handler layer is responsible for emitting JSON null in those slots.
type Service struct {
// contains filtered or unexported fields
}
func NewService
func NewService(repo Repository) *Service
NewService creates a new Service instance.
func (*Service) Resolve
func (s *Service) Resolve(ctx context.Context, viewerID uuid.UUID, refs []Ref) (map[string]*Summary, error)
Resolve batches per-type lookups and collates per-(type, id). Every request ref appears in the result map; absent entries (nil Summary) correspond to deleted / invisible / nonexistent entities.
type Summary
Summary is the compact per-entity payload returned by the service. Only the fields for the matching Type are populated -- see RefSummary in the OpenAPI schema.
type Summary struct {
Type RefType
ID uuid.UUID
// sg
Title string
Course *CourseInfo
QuizCount *int
IsRecommended *bool
// quiz
QuestionCount *int
Creator *CreatorInfo
// file
Name string
Size *int64
MimeType string
Status string
// course
Department string
Number string
School *SchoolInfo
}
Generated by gomarkdoc