feat: add ontology material ingestion

This commit is contained in:
user
2026-04-26 17:49:35 +09:00
parent a413f1ef15
commit 4936cdf4c9
19 changed files with 766 additions and 13 deletions

View File

@@ -0,0 +1,48 @@
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())
}