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))
})
}