feat(web+api): 贡献表单按 archive_kind 动态生成字段
- categories 接口返回 archive_kind - 新增公开只读接口 /api/v1/kind-fields?kind=X 返回字段模板 - 投稿 payload 支持通用 attributes,审核通过写入 product.attributes (JSONB 合并) - food_detail 仅在含食品数据时才 upsert (药品/3C/通用不再产生空行) - 前端 Contribute 按所选品类 archive_kind 动态渲染字段 (食品营养 / 药品 18 字段 / 3C / 通用),除商品名外均选填 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -127,6 +127,7 @@ func (h *Handler) Router() http.Handler {
|
||||
})
|
||||
r.Get("/brands", h.ListBrands)
|
||||
r.Get("/categories", h.ListCategories)
|
||||
r.Get("/kind-fields", h.ListKindFields)
|
||||
r.Get("/sources/{id}", h.SourceByID)
|
||||
r.Get("/stats", h.Stats)
|
||||
})
|
||||
@@ -275,6 +276,21 @@ func (h *Handler) ListCategories(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"items": items})
|
||||
}
|
||||
|
||||
// ListKindFields returns the read-only spec field template for an archive kind,
|
||||
// used by the contribution form to render kind-specific inputs.
|
||||
func (h *Handler) ListKindFields(w http.ResponseWriter, r *http.Request) {
|
||||
kind := strings.TrimSpace(r.URL.Query().Get("kind"))
|
||||
if kind == "" {
|
||||
writeError(w, r, http.StatusBadRequest, "bad_request", "missing kind")
|
||||
return
|
||||
}
|
||||
items, err := h.store.ListKindFields(r.Context(), kind)
|
||||
if h.handleErr(w, r, err) {
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"items": items, "kind": kind})
|
||||
}
|
||||
|
||||
// SourceByID returns a single data source.
|
||||
func (h *Handler) SourceByID(w http.ResponseWriter, r *http.Request) {
|
||||
src, err := h.store.SourceByID(r.Context(), chi.URLParam(r, "id"))
|
||||
|
||||
Reference in New Issue
Block a user