Files

49 lines
1.0 KiB
Go
Raw Permalink Normal View History

2026-04-26 17:49:35 +09:00
package httpapi
import (
"encoding/json"
"net/http"
"tutor/internal/ontology"
)
type ingestMaterialRequest struct {
Title string `json:"title"`
SourceType string `json:"source_type"`
Body string `json:"body"`
}
func (h Handler) ingestMaterial(w http.ResponseWriter, r *http.Request) {
if h.ontology == nil {
writeError(w, http.StatusNotFound, "ontology not configured")
return
}
var req ingestMaterialRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeError(w, http.StatusBadRequest, "invalid JSON body")
return
}
result, err := h.ontology.Ingest(ontology.IngestInput{
Title: req.Title,
SourceType: req.SourceType,
Body: req.Body,
})
if err != nil {
writeError(w, http.StatusBadRequest, err.Error())
return
}
writeJSON(w, http.StatusCreated, result)
}
func (h Handler) getOntology(w http.ResponseWriter, _ *http.Request) {
if h.ontology == nil {
writeError(w, http.StatusNotFound, "ontology not configured")
return
}
writeJSON(w, http.StatusOK, h.ontology.Snapshot())
}