fix: Code for category
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user