feat: materials by zjazd in the student API and admin

The material admin form gets the "Na zjazd" picker, every student
material JSON carries meeting_id, and GET /materials accepts meeting=
inside the published-only scope, so the Pulpit hero can list the
zjazd's materials next to its readings.
This commit is contained in:
Jakub Zych
2026-10-27 01:44:38 +01:00
parent 3241cc9894
commit ff2f97eb2b
9 changed files with 58 additions and 16 deletions

View File

@@ -21,15 +21,19 @@ func published(q *gorm.DB, now time.Time) *gorm.DB {
// materialFilter holds the validated filters of /materials.
type materialFilter struct {
CourseID uint
Tag string
Type string
CourseID uint
MeetingID uint
Tag string
Type string
}
func (f materialFilter) apply(q *gorm.DB) *gorm.DB {
if f.CourseID != 0 {
q = q.Where("jz_bm_materials.course_id = ?", f.CourseID)
}
if f.MeetingID != 0 {
q = q.Where("jz_bm_materials.meeting_id = ?", f.MeetingID)
}
if f.Type != "" {
q = q.Where("jz_bm_materials.type = ?", f.Type)
}
@@ -94,13 +98,13 @@ func materialsJSON(db *gorm.DB, rows []models.Material) ([]materialListJSON, err
return out, nil
}
// Materials answers GET /materials?course=&tag=&type=&page=&per_page=: a
// page of published materials in the {data, meta} shape of lagoon.Paginate.
// Materials answers GET /materials?course=&meeting=&tag=&type=&page=&per_page=:
// a page of published materials in the {data, meta} shape of lagoon.Paginate.
func (h *Handlers) Materials(w http.ResponseWriter, r *http.Request) {
if _, ok := h.caller(w, r); !ok {
return
}
in := query(r, "course", "tag", "type", "page", "per_page")
in := query(r, "course", "meeting", "tag", "type", "page", "per_page")
if !h.validate(w, r, in, materialsRules) {
return
}
@@ -108,7 +112,7 @@ func (h *Handlers) Materials(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
filter := materialFilter{CourseID: uintParam(in, "course"), Tag: strings.TrimSpace(str(in, "tag")), Type: str(in, "type")}
filter := materialFilter{CourseID: uintParam(in, "course"), MeetingID: uintParam(in, "meeting"), Tag: strings.TrimSpace(str(in, "tag")), Type: str(in, "type")}
page := min(intParam(in, "page", 1), 100000)
perPage := intParam(in, "per_page", h.perPage())
rows, total, err := listMaterials(db, h.now(), filter, page, perPage)