refactor: drop the quiz import and the golem15.quizzes dependency

golem15.quizzes now serves its own import at /api/v1/quizzes/import behind
the same shared API token.
This commit is contained in:
Jakub Zych
2026-10-04 23:15:01 +02:00
parent 97000dcd1e
commit 840935d22d
6 changed files with 7 additions and 52 deletions

View File

@@ -12,7 +12,6 @@ import (
"time"
"unicode"
quizzes "git.golem15.com/golem15/sm-quizzes-plugin/classes"
usermodels "git.golem15.com/golem15/sm-user-plugin/models"
"git.golem15.com/golem15/summercms/modules/bouncer"
"git.golem15.com/golem15/summercms/modules/lagoon"
@@ -134,41 +133,6 @@ func (h *Handlers) ApplySeed(w http.ResponseWriter, r *http.Request) {
})
}
// ImportQuiz answers POST /quizzes?replace=: quizzes:import over HTTP. The
// body is the quiz document of golem15.quizzes. An existing slug is a 409
// unless replace is on.
func (h *Handlers) ImportQuiz(w http.ResponseWriter, r *http.Request) {
raw, ok := body(w, r)
if !ok {
return
}
doc, err := quizzes.ParseImport(raw)
if err != nil {
writeInvalid(w, err.Error())
return
}
db, ok := h.db(w, r)
if !ok {
return
}
res, err := quizzes.Import(r.Context(), db, doc, flag(r, "replace"))
if errors.Is(err, quizzes.ErrQuizExists) {
wire.WriteJSON(w, http.StatusConflict, map[string]any{"error": true, "message": "A quiz with the slug " + doc.Slug + " already exists; pass replace=1 to replace its questions."})
return
}
if err != nil {
writeOpaque500(w)
return
}
writeData(w, map[string]any{
"id": res.Quiz.ID,
"slug": res.Quiz.Slug,
"created": res.Created,
"questions": res.Questions,
"answers": res.Answers,
})
}
// managedMaterialJSON is a material as the management API shows it: drafts
// too, so published_at may be null.
type managedMaterialJSON struct {