Adopt SummerCMS v0.1.1 admin features

Datepickers on native time.Time / lagoon.Date fields, file uploads on
materials, readings and class sessions managed from the course form
(course_id made nullable).
This commit is contained in:
Jakub Zych
2026-10-03 06:03:34 +02:00
parent ac2e2ddd7b
commit 71b848a376
39 changed files with 475 additions and 373 deletions

View File

@@ -2,6 +2,15 @@ package api
import "git.golem15.com/jakub/sm-bm-plugin/models"
// idOf is the value of an optional id, 0 when it is nil. The API serves only
// sessions and readings that have a course, so their course_id is set.
func idOf(id *uint) uint {
if id == nil {
return 0
}
return *id
}
// courseRef is the short form of a course embedded in other records.
type courseRef struct {
ID uint `json:"id"`
@@ -83,7 +92,7 @@ type meetingJSON struct {
}
func newMeetingJSON(m models.Meeting, sessions int64) meetingJSON {
return meetingJSON{ID: m.ID, Number: m.Number, StartsOn: string(m.StartsOn), EndsOn: string(m.EndsOn), Notes: m.Notes, SessionsCount: sessions}
return meetingJSON{ID: m.ID, Number: m.Number, StartsOn: m.StartsOn.String(), EndsOn: m.EndsOn.String(), Notes: m.Notes, SessionsCount: sessions}
}
// sessionJSON is one class session with its course.
@@ -104,10 +113,10 @@ type sessionJSON struct {
func newSessionJSON(s models.ClassSession) sessionJSON {
out := sessionJSON{
ID: s.ID,
CourseID: s.CourseID,
CourseID: idOf(s.CourseID),
MeetingID: s.MeetingID,
StartsAt: string(s.StartsAt),
EndsAt: string(s.EndsAt),
StartsAt: models.FormatDateTime(s.StartsAt),
EndsAt: models.FormatDateTime(s.EndsAt),
Room: s.Room,
Kind: s.Kind,
Notes: s.Notes,
@@ -146,7 +155,7 @@ func newDeadlinesJSON(rows []models.Deadline) []deadlineJSON {
out = append(out, deadlineJSON{
ID: d.ID,
Title: d.Title,
DueAt: string(d.DueAt),
DueAt: models.FormatDateTime(d.DueAt),
Kind: d.Kind,
Description: d.Description,
CourseID: d.CourseID,
@@ -212,7 +221,7 @@ func newMaterialListJSON(m models.Material, files int64) materialListJSON {
FilesCount: files,
}
if m.PublishedAt != nil {
out.PublishedAt = string(*m.PublishedAt)
out.PublishedAt = models.FormatDateTime(*m.PublishedAt)
}
return out
}