48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
|
|
package httpapi
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"tutor/internal/teachingassets"
|
||
|
|
"tutor/internal/workflows"
|
||
|
|
)
|
||
|
|
|
||
|
|
type generateTeachingAssetPromptRequest struct {
|
||
|
|
ConceptID string `json:"concept_id"`
|
||
|
|
AssetType workflows.AssetType `json:"asset_type"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h Handler) generateTeachingAssetPrompt(w http.ResponseWriter, r *http.Request) {
|
||
|
|
if h.assets == nil {
|
||
|
|
writeError(w, http.StatusNotFound, "teaching assets not configured")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
var req generateTeachingAssetPromptRequest
|
||
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||
|
|
writeError(w, http.StatusBadRequest, "invalid JSON body")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
prompt, err := h.assets.GeneratePrompt(teachingassets.GenerateInput{
|
||
|
|
ConceptID: req.ConceptID,
|
||
|
|
AssetType: req.AssetType,
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
writeError(w, http.StatusBadRequest, err.Error())
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
writeJSON(w, http.StatusCreated, prompt)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h Handler) getTeachingAssets(w http.ResponseWriter, _ *http.Request) {
|
||
|
|
if h.assets == nil {
|
||
|
|
writeError(w, http.StatusNotFound, "teaching assets not configured")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
writeJSON(w, http.StatusOK, h.assets.Snapshot())
|
||
|
|
}
|