Merge branch 'dev' of https://github.com/dikstub-rssa/simrs-be into feat/sync-setting-vanili

This commit is contained in:
vanilia
2025-11-28 12:23:34 +07:00
48 changed files with 1418 additions and 419 deletions
@@ -64,7 +64,7 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
}
dto := e.ReadDetailDto{}
sf.UrlQueryParam(&dto, *r.URL)
dto.Id = uint16(id)
dto.Id = uint(id)
res, err := u.ReadDetail(dto)
rw.DataResponse(w, res, err)
}
@@ -84,7 +84,7 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
dto.Id = uint16(id)
dto.Id = uint(id)
dto.AuthInfo = *authInfo
res, err := u.Update(dto)
@@ -103,7 +103,7 @@ func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
}
dto := e.DeleteDto{}
dto.Id = uint16(id)
dto.Id = uint(id)
dto.AuthInfo = *authInfo
res, err := u.Delete(dto)
@@ -174,9 +174,15 @@ func (obj myBase) Process(w http.ResponseWriter, r *http.Request) {
return
}
authInfo, err := pa.GetAuthInfo(r)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
}
dto := e.UpdateStatusDto{
Id: uint16(id),
Id: uint(id),
StatusCode: erc.DSCProcess,
AuthInfo: *authInfo,
}
res, err := u.UpdateStatusCode(dto)
@@ -195,11 +201,11 @@ func (obj myBase) Cancel(w http.ResponseWriter, r *http.Request) {
}
dto := e.UpdateStatusDto{
Id: uint16(id),
Id: uint(id),
StatusCode: erc.DSCCancel,
AuthInfo: *authInfo,
}
dto.AuthInfo = *authInfo
res, err := u.UpdateStatusCode(dto)
rw.DataResponse(w, res, err)
}
@@ -211,7 +217,7 @@ func (obj myBase) Reject(w http.ResponseWriter, r *http.Request) {
}
dto := e.UpdateStatusDto{
Id: uint16(id),
Id: uint(id),
StatusCode: erc.DSCRejected,
}
@@ -226,7 +232,7 @@ func (obj myBase) Skip(w http.ResponseWriter, r *http.Request) {
}
dto := e.UpdateStatusDto{
Id: uint16(id),
Id: uint(id),
StatusCode: erc.DSCSkipped,
}
@@ -250,13 +256,19 @@ func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) {
return
}
authInfo, err := pa.GetAuthInfo(r)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
}
dto.AuthInfo = *authInfo
dto.Id = uint(id)
res, err := u.RequestSwitchUnit(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) ApproveSwitchUnit(w http.ResponseWriter, r *http.Request) {
dto := e.ApproveUnitDto{}
dto := e.ApproveCancelUnitDto{}
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
@@ -266,7 +278,37 @@ func (obj myBase) ApproveSwitchUnit(w http.ResponseWriter, r *http.Request) {
return
}
authInfo, err := pa.GetAuthInfo(r)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
}
dto.AuthInfo = *authInfo
dto.Id = uint(id)
res, err := u.ApproveSwitchUnit(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) CancelSwitchUnit(w http.ResponseWriter, r *http.Request) {
dto := e.ApproveCancelUnitDto{}
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
}
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
authInfo, err := pa.GetAuthInfo(r)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
}
dto.AuthInfo = *authInfo
dto.Id = uint(id)
res, err := u.CancelSwitchUnit(dto)
rw.DataResponse(w, res, err)
}
@@ -59,6 +59,22 @@ func validateRequestCheckIn(w http.ResponseWriter, i e.CheckinDto) (valid bool)
}
func validateRequestSwitchUnit(w http.ResponseWriter, i e.SwitchUnitDto) (valid bool) {
// validate poly-switch-code
if i.PolySwitchCode == nil {
rw.DataResponse(w, nil, d.FieldError{
Code: dataValidationFail,
Message: fmt.Sprintf("polySwitchCode required"),
})
return
}
if *i.PolySwitchCode != ere.PSCConsulPoly && *i.PolySwitchCode != ere.PSCConsulExecutive {
rw.DataResponse(w, nil, d.FieldError{
Code: dataValidationFail,
Message: "invalid PolySwitchCode",
})
}
if i.InternalReferences == nil {
rw.DataResponse(w, nil, d.FieldError{
Code: dataValidationFail,
@@ -39,7 +39,7 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
dto := eir.ReadDetailDto{}
sf.UrlQueryParam(&dto, *r.URL)
dto.Id = uint16(id)
dto.Id = uint(id)
res, err := uir.ReadDetail(dto)
rw.DataResponse(w, res, err)
}
@@ -54,7 +54,7 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
dto.Id = uint16(id)
dto.Id = uint(id)
res, err := uir.Update(dto)
rw.DataResponse(w, res, err)
}
@@ -66,7 +66,7 @@ func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
}
dto := eir.DeleteDto{}
dto.Id = uint16(id)
dto.Id = uint(id)
res, err := uir.Delete(dto)
rw.DataResponse(w, res, err)
}
@@ -175,6 +175,7 @@ func SetRoutes() http.Handler {
"PATCH /{id}/skip": encounter.O.Skip,
"PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchUnit,
"PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchUnit,
"PATCH /{id}/cancel-switch-unit": encounter.O.CancelSwitchUnit,
})
hk.GroupRoutes("/v1/mcu-order", r, auth.GuardMW, hk.MapHandlerFunc{
"GET /": mcuorder.O.GetList,