feat: add ontology material ingestion
This commit is contained in:
48
internal/httpapi/ontology.go
Normal file
48
internal/httpapi/ontology.go
Normal 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())
|
||||
}
|
||||
Reference in New Issue
Block a user