fix: Code for category

This commit is contained in:
2026-06-27 19:35:53 +05:00
parent 46add88fd5
commit 148d1fb841
14 changed files with 127 additions and 64 deletions

View File

@@ -34,12 +34,13 @@ func (h *CategoryHandler) Register(r chi.Router) {
type categoryRequest struct {
ParentID *string `json:"parent_id" validate:"omitempty,uuid"`
Code string `json:"code" validate:"required,max=255,slug"`
Name string `json:"name" validate:"required,max=255"`
Description string `json:"description" validate:"max=2000"`
}
func (r categoryRequest) toInput() (service.CategoryInput, error) {
in := service.CategoryInput{Name: r.Name, Description: r.Description}
in := service.CategoryInput{Code: r.Code, Name: r.Name, Description: r.Description}
if r.ParentID != nil {
id, err := uuid.Parse(*r.ParentID)
if err != nil {

View File

@@ -131,12 +131,6 @@ func (h *DatasetHandler) upload(w http.ResponseWriter, r *http.Request) {
return
}
code := r.FormValue("code")
if code == "" {
httputil.WriteError(w, http.StatusUnprocessableEntity, "code is required")
return
}
meta, ok := optionalJSONFormValue(w, r, "meta")
if !ok {
return
@@ -162,7 +156,6 @@ func (h *DatasetHandler) upload(w http.ResponseWriter, r *http.Request) {
dataset, err := h.svc.Upload(r.Context(), service.UploadInput{
CategoryID: categoryID,
Code: code,
Name: r.FormValue("name"),
Description: optionalFormValue(r, "description"),
Unit: optionalFormValue(r, "unit"),
@@ -220,6 +213,10 @@ func (h *DatasetHandler) list(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
var categoryCode *string
if v := strings.TrimSpace(r.URL.Query().Get("category_code")); v != "" {
categoryCode = &v
}
page, ok := parsePositiveIntQuery(w, r, "page", 1)
if !ok {
return
@@ -229,7 +226,7 @@ func (h *DatasetHandler) list(w http.ResponseWriter, r *http.Request) {
return
}
res, err := h.svc.ListSummaries(r.Context(), categoryID, page, pageSize)
res, err := h.svc.ListSummaries(r.Context(), categoryID, categoryCode, page, pageSize)
if err != nil {
respondDomainError(w, err)
return