feat (encounter): create and checkout + checking soapi done

This commit is contained in:
dpurbosakti
2025-09-09 13:41:06 +07:00
parent cc226b8034
commit e4358034d9
15 changed files with 225 additions and 71 deletions
@@ -9,16 +9,10 @@ import (
m "simrs-vx/internal/domain/main-entities/user"
s "simrs-vx/internal/use-case/main-use-case/authentication"
pa "simrs-vx/pkg/auth-helper"
)
type authKey string
const akInfo authKey = "authInfo"
type AuthKey struct{}
// var Position m.Position
func Login(w http.ResponseWriter, r *http.Request) {
var input m.LoginDto
if !(rw.ValidateStructByIOR(w, r.Body, &input)) {
@@ -35,12 +29,12 @@ func Login(w http.ResponseWriter, r *http.Request) {
}
func Logout(w http.ResponseWriter, r *http.Request) {
ctxVal := r.Context().Value(AuthKey{})
ctxVal := r.Context().Value(pa.AuthKey{})
if ctxVal == nil {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": "logout skiped. the request is done wihtout authorization."}, nil)
return
}
authInfo := ctxVal.(*s.AuthInfo)
authInfo := ctxVal.(*pa.AuthInfo)
s.RevokeToken(authInfo.Uuid)
rw.WriteJSON(w, http.StatusOK, d.IS{"message": "logged out"}, nil)
}
@@ -52,7 +46,7 @@ func GuardMW(next http.Handler) http.Handler {
rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil)
return
}
ctx := context.WithValue(r.Context(), AuthKey{}, accessDetail)
ctx := context.WithValue(r.Context(), pa.AuthKey{}, accessDetail)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
@@ -125,10 +125,10 @@ func SetRoutes() http.Handler {
"POST /": encounter.O.Create,
"PATCH /{id}": encounter.O.Update,
"DELETE /{id}": encounter.O.Delete,
"PATCH /{id}/checkOut": encounter.O.CheckOut,
"PATCH /{id}/checkout": encounter.O.CheckOut,
})
hc.RegCrud(r, "/v1/soapi", soapi.O)
hc.RegCrud(r, "/v1/soapi", auth.GuardMW, soapi.O)
hc.RegCrud(r, "/v1/adime", adime.O)
hc.RegCrud(r, "/v1/sbar", sbar.O)
hc.RegCrud(r, "/v1/person", person.O)
@@ -10,6 +10,10 @@ import (
e "simrs-vx/internal/domain/main-entities/soapi"
u "simrs-vx/internal/use-case/main-use-case/soapi"
pa "simrs-vx/pkg/auth-helper"
d "github.com/karincake/dodol"
)
type myBase struct{}
@@ -17,10 +21,15 @@ type myBase struct{}
var O myBase
func (obj myBase) 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
}
dto.AuthInfo = *authInfo
res, err := u.Create(dto)
rw.DataResponse(w, res, err)
}