Documentation
¶
Overview ¶
Package course is the course use cases and their model.
It owns which backend to try and in what order. There is no central dispatcher: a feature knows its own alternatives and its own tolerance for incomplete answers, and a shared one would have to learn all of that for every feature.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface {
Name() site.BackendKind
Requirement() site.Requirement
List(ctx context.Context, q ListQuery) (ListResult, error)
}
Backend is one way of listing courses. A feature declares the interface it needs; adapters in other packages satisfy it.
type ListQuery ¶
type ListQuery struct {
// Limit caps the number of courses returned. Zero means the backend's
// default.
Limit int
// Cursor continues a previous listing. It is opaque to callers.
Cursor string
// Current keeps only the courses running now. A student's enrolments
// span every term they have taken, and the question they usually have is
// about this one.
Current bool
}
ListQuery limits a listing.
type ListResult ¶
type ListResult struct {
Courses []Summary
// Provenance tells the caller which backend answered and whether anything
// is missing, so an agent can tell "no value" from "could not fetch".
Provenance site.Provenance
NextCursor string
}
ListResult is a listing plus how it was obtained.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service lists courses, trying its backends in order.
func NewService ¶
NewService builds a Service. The order is the preference order, and the composition root decides it.
func (*Service) List ¶
func (s *Service) List(ctx context.Context, capabilities *site.Capabilities, q ListQuery) (ListResult, error)
List returns the courses this account is enrolled in.
Backends whose requirements are not met are skipped without a request. Once a request has been made, only a "this route cannot do it" error allows the next backend to be tried; anything else is returned as-is so a permission or network problem is never disguised as a missing feature.
type Summary ¶
type Summary struct {
ID string
ShortName string
FullName string
// StartDate and EndDate are nil when the course does not set them. Moodle
// sends 0 for "unset", which must not become 1970.
StartDate *time.Time
EndDate *time.Time
Visible bool
// Progress is nil when the site does not report it, which is different
// from a course at 0%.
Progress *float64
}
Summary is one course as this tool understands it.
It is not Moodle's shape: the adapter maps upstream fields onto this, so a change on their side stops at the adapter instead of reaching the JSON contract.