feat (user): add block and active

This commit is contained in:
dpurbosakti
2025-08-25 09:57:55 +07:00
parent 4d10a8f99f
commit d10b92c7b1
3 changed files with 131 additions and 5 deletions
@@ -54,7 +54,15 @@ func SetRoutes() http.Handler {
// r.HandleFunc("POST /v1/authentication/logout", auth.Logout)
hk.Route("POST /v1/authentication/logout", r, auth.GuardMW, auth.Logout)
hc.RegCrud(r, "/v1/user", user.O)
hk.GroupRoutes("/v1/user", r, hk.MapHandlerFunc{
"GET /": user.O.GetList,
"GET /{id}": user.O.GetDetail,
"POST /": user.O.Create,
"PATCH /{id}": user.O.Update,
"DELETE /{id}": user.O.Delete,
"PATCH /{id}/block": user.O.Block,
"PATCH /{id}/active": user.O.Active,
})
/******************** sources ********************/
hc.RegCrud(r, "/v1/division", division.O)
@@ -69,3 +69,27 @@ func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
res, err := u.Delete(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Block(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
}
dto := e.ReadDetailDto{}
dto.Id = uint(id)
res, err := u.Block(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Active(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
}
dto := e.ReadDetailDto{}
dto.Id = uint(id)
res, err := u.Active(dto)
rw.DataResponse(w, res, err)
}