feat (kfr): base crud + validation&verification done, no rules set yet
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
package kfr
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
rw "github.com/karincake/risoles"
|
||||
sf "github.com/karincake/semprit"
|
||||
|
||||
// ua "github.com/karincake/tumpeng/auth/svc"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/kfr"
|
||||
u "simrs-vx/internal/use-case/main-use-case/kfr"
|
||||
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
|
||||
pa "simrs-vx/internal/lib/auth"
|
||||
)
|
||||
|
||||
func Create(w http.ResponseWriter, r *http.Request) {
|
||||
authInfo, err := pa.GetAuthInfo(r)
|
||||
if err != nil {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
|
||||
}
|
||||
dto := e.CreateDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
|
||||
if !dto.IsCorrectType() {
|
||||
rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "invalid kfr type"}, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !dto.IsCorrectFollowUpType() {
|
||||
rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "invalid kfr followUpType"}, nil)
|
||||
return
|
||||
}
|
||||
|
||||
dto.AuthInfo = *authInfo
|
||||
res, err := u.Create(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func GetList(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ReadListDto{}
|
||||
sf.UrlQueryParam(&dto, *r.URL)
|
||||
res, err := u.ReadList(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func GetDetail(w http.ResponseWriter, r *http.Request) {
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
dto := e.ReadDetailDto{}
|
||||
sf.UrlQueryParam(&dto, *r.URL)
|
||||
dto.Id = uint(id)
|
||||
res, err := u.ReadDetail(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func Update(w http.ResponseWriter, r *http.Request) {
|
||||
authInfo, err := pa.GetAuthInfo(r)
|
||||
if err != nil {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
|
||||
}
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.UpdateDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
|
||||
if !dto.IsCorrectType() {
|
||||
rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "invalid kfr type"}, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !dto.IsCorrectFollowUpType() {
|
||||
rw.WriteJSON(w, http.StatusBadRequest, d.IS{"message": "invalid kfr followUpType"}, nil)
|
||||
return
|
||||
}
|
||||
|
||||
dto.Id = uint(id)
|
||||
dto.AuthInfo = *authInfo
|
||||
res, err := u.Update(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func Delete(w http.ResponseWriter, r *http.Request) {
|
||||
authInfo, err := pa.GetAuthInfo(r)
|
||||
if err != nil {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
|
||||
}
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.DeleteDto{}
|
||||
dto.Id = uint(id)
|
||||
dto.AuthInfo = *authInfo
|
||||
res, err := u.Delete(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func Verify(w http.ResponseWriter, r *http.Request) {
|
||||
authInfo, err := pa.GetAuthInfo(r)
|
||||
if err != nil {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
|
||||
}
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.UpdateDto{}
|
||||
dto.Id = uint(id)
|
||||
dto.Status_Code = erc.DVCVerified
|
||||
dto.AuthInfo = *authInfo
|
||||
res, err := u.UpdateStatusCode(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func Validate(w http.ResponseWriter, r *http.Request) {
|
||||
authInfo, err := pa.GetAuthInfo(r)
|
||||
if err != nil {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
|
||||
}
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.UpdateDto{}
|
||||
dto.Id = uint(id)
|
||||
dto.Status_Code = erc.DVCValidated
|
||||
dto.AuthInfo = *authInfo
|
||||
res, err := u.UpdateStatusCode(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
generalconsent "simrs-vx/internal/interface/main-handler/general-consent"
|
||||
generatefile "simrs-vx/internal/interface/main-handler/generate-file"
|
||||
internalreference "simrs-vx/internal/interface/main-handler/internal-reference"
|
||||
kfr "simrs-vx/internal/interface/main-handler/kfr"
|
||||
materialorder "simrs-vx/internal/interface/main-handler/material-order"
|
||||
materialorderitem "simrs-vx/internal/interface/main-handler/material-order-item"
|
||||
mcuorder "simrs-vx/internal/interface/main-handler/mcu-order"
|
||||
@@ -347,6 +348,15 @@ func SetRoutes() http.Handler {
|
||||
"GET /": screening.O.GetList,
|
||||
"GET /{id}": screening.O.GetDetail,
|
||||
})
|
||||
hk.GroupRoutes("/v1/kfr", r, auth.GuardMW, hk.MapHandlerFunc{
|
||||
"POST /": kfr.Create,
|
||||
"GET /": kfr.GetList,
|
||||
"GET /{id}": kfr.GetDetail,
|
||||
"PATCH /{id}": kfr.Update,
|
||||
"DELETE /{id}": kfr.Delete,
|
||||
"PATCH /{id}/verify": kfr.Verify,
|
||||
"PATCH /{id}/validate": kfr.Validate,
|
||||
})
|
||||
/******************** actor ********************/
|
||||
hc.RegCrud(r, "/v1/person", person.O)
|
||||
hc.RegCrud(r, "/v1/person-address", personaddress.O)
|
||||
|
||||
Reference in New Issue
Block a user