55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"inbox/internal/base/httpx"
|
|
"inbox/internal/domain/skill"
|
|
)
|
|
|
|
func (h *Handler) listSkills(w http.ResponseWriter, r *http.Request) {
|
|
items, err := h.Skills.List(r.Context())
|
|
if err != nil {
|
|
writeStoreError(w, err)
|
|
return
|
|
}
|
|
httpx.WriteJSON(w, http.StatusOK, map[string]any{"skills": items})
|
|
}
|
|
|
|
func (h *Handler) putSkill(w http.ResponseWriter, r *http.Request) {
|
|
type request struct {
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
SourceType string `json:"source_type"`
|
|
ContentMarkdown string `json:"content_markdown"`
|
|
Status string `json:"status"`
|
|
UpdatedBy string `json:"updated_by"`
|
|
}
|
|
var req request
|
|
if err := httpx.DecodeJSON(r, &req); err != nil {
|
|
httpx.WriteError(w, http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
item, err := h.Skills.Upsert(r.Context(), skill.Definition{
|
|
SkillKey: r.PathValue("skillKey"),
|
|
Name: req.Name,
|
|
Description: req.Description,
|
|
SourceType: req.SourceType,
|
|
ContentMarkdown: req.ContentMarkdown,
|
|
Status: req.Status,
|
|
}, req.UpdatedBy)
|
|
if err != nil {
|
|
writeStoreError(w, err)
|
|
return
|
|
}
|
|
httpx.WriteJSON(w, http.StatusOK, item)
|
|
}
|
|
|
|
func (h *Handler) deleteSkill(w http.ResponseWriter, r *http.Request) {
|
|
if err := h.Skills.Delete(r.Context(), r.PathValue("skillKey")); err != nil {
|
|
writeStoreError(w, err)
|
|
return
|
|
}
|
|
w.WriteHeader(http.StatusNoContent)
|
|
}
|