This commit is contained in:
vanilia
2025-11-11 15:35:19 +07:00
parent a382dfdb3e
commit 733fb481b3
6 changed files with 49 additions and 24 deletions
@@ -4,7 +4,6 @@ import (
"net/http"
eru "simrs-vx/internal/domain/references/upload"
"strconv"
"strings"
d "github.com/karincake/dodol"
rw "github.com/karincake/risoles"
@@ -57,12 +56,13 @@ func (obj myBase) Create(w http.ResponseWriter, r *http.Request) {
MimeType: header.Header.Get("Content-Type"),
}
errs := validateCreate(dto)
if len(errs) > 0 {
dataFail := validateCreate(dto)
if dataFail != "" {
rw.DataResponse(w, nil, d.FieldError{
Code: "data-validation-fail",
Message: strings.Join(errs, "\n"),
Message: dataFail,
})
return
}
res, err := u.Create(dto)
@@ -4,17 +4,16 @@ import (
e "simrs-vx/internal/domain/main-entities/file-attachment"
)
func validateCreate(dto e.CreateDto) []string {
var errs []string
func validateCreate(dto e.CreateDto) string {
switch {
case dto.EntityType_Code == "":
errs = append(errs, "entityType_code is required")
return "entityType_code is required"
case dto.Ref_Id == nil:
errs = append(errs, "ref_id is required")
return "ref_id is required"
case dto.Type_Code == "":
errs = append(errs, "type_code is required")
return "type_code is required"
}
return errs
return ""
}
@@ -269,7 +269,7 @@ func SetRoutes() http.Handler {
hc.RegCrud(r, "/v1/adm-employee-hist", admemployeehist.O)
hc.RegCrud(r, "/v1/therapy-protocol", therapyprotocol.O)
hc.RegCrud(r, "/v1/chemo-protocol", chemoprotocol.O)
hc.RegCrud(r, "POST /upload", fileattachment.O)
hc.RegCrud(r, "/v1/upload", fileattachment.O)
/******************** actor ********************/
hc.RegCrud(r, "/v1/person", person.O)