feat: add progression readiness api
This commit is contained in:
46
internal/httpapi/progression.go
Normal file
46
internal/httpapi/progression.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"tutor/internal/learnermemory"
|
||||
)
|
||||
|
||||
func (h Handler) getReadinessMap(w http.ResponseWriter, r *http.Request) {
|
||||
if h.progress == nil {
|
||||
writeError(w, http.StatusNotFound, "progression not configured")
|
||||
return
|
||||
}
|
||||
|
||||
readiness, err := h.progress.ReadinessMap(r.PathValue("userID"))
|
||||
if errors.Is(err, learnermemory.ErrProfileNotFound) {
|
||||
writeError(w, http.StatusNotFound, "learner memory not found")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
writeJSON(w, http.StatusOK, readiness)
|
||||
}
|
||||
|
||||
func (h Handler) getNextChallenge(w http.ResponseWriter, r *http.Request) {
|
||||
if h.progress == nil {
|
||||
writeError(w, http.StatusNotFound, "progression not configured")
|
||||
return
|
||||
}
|
||||
|
||||
challenge, err := h.progress.NextChallenge(r.PathValue("userID"))
|
||||
if errors.Is(err, learnermemory.ErrProfileNotFound) {
|
||||
writeError(w, http.StatusNotFound, "learner memory not found")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
writeJSON(w, http.StatusOK, challenge)
|
||||
}
|
||||
Reference in New Issue
Block a user