2025-02-27 18:59:58 +08:00
|
|
|
package authhttp
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
authsvc "legalgo-BE-go/internal/services/auth"
|
|
|
|
|
"legalgo-BE-go/internal/utilities/response"
|
2025-02-28 12:18:47 +08:00
|
|
|
"legalgo-BE-go/internal/utilities/utils"
|
2025-02-27 18:59:58 +08:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func GetStaffProfile(
|
|
|
|
|
router chi.Router,
|
|
|
|
|
authSvc authsvc.AuthIntf,
|
|
|
|
|
) {
|
2025-02-28 12:18:47 +08:00
|
|
|
router.Get("/staff/profile", func(w http.ResponseWriter, r *http.Request) {
|
2025-02-27 18:59:58 +08:00
|
|
|
ctx := r.Context()
|
2025-03-02 04:36:17 +08:00
|
|
|
destructedToken, err := utils.GetTokenDetail(r)
|
2025-02-28 12:18:47 +08:00
|
|
|
if err != nil {
|
|
|
|
|
response.ResponseWithErrorCode(
|
|
|
|
|
ctx,
|
|
|
|
|
w,
|
|
|
|
|
err,
|
|
|
|
|
response.ErrBadRequest.Code,
|
|
|
|
|
response.ErrBadRequest.HttpCode,
|
|
|
|
|
err.Error(),
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
staffProfile, err := authSvc.GetStaffProfile(destructedToken.Email)
|
2025-02-27 18:59:58 +08:00
|
|
|
if err != nil {
|
|
|
|
|
response.ResponseWithErrorCode(
|
|
|
|
|
ctx,
|
|
|
|
|
w,
|
|
|
|
|
err,
|
|
|
|
|
response.ErrBadRequest.Code,
|
|
|
|
|
response.ErrBadRequest.HttpCode,
|
|
|
|
|
err.Error(),
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.RespondJsonSuccess(ctx, w, staffProfile)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetUserProfile(
|
|
|
|
|
router chi.Router,
|
|
|
|
|
authSvc authsvc.AuthIntf,
|
|
|
|
|
) {
|
2025-02-28 12:18:47 +08:00
|
|
|
router.Get("/user/profile", func(w http.ResponseWriter, r *http.Request) {
|
2025-02-27 18:59:58 +08:00
|
|
|
ctx := r.Context()
|
2025-03-02 04:36:17 +08:00
|
|
|
destructedToken, err := utils.GetTokenDetail(r)
|
2025-02-28 12:18:47 +08:00
|
|
|
if err != nil {
|
|
|
|
|
response.ResponseWithErrorCode(
|
|
|
|
|
ctx,
|
|
|
|
|
w,
|
|
|
|
|
err,
|
|
|
|
|
response.ErrBadRequest.Code,
|
|
|
|
|
response.ErrBadRequest.HttpCode,
|
|
|
|
|
err.Error(),
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userProfile, err := authSvc.GetUserProfile(destructedToken.Email)
|
2025-02-27 18:59:58 +08:00
|
|
|
if err != nil {
|
|
|
|
|
response.ResponseWithErrorCode(
|
|
|
|
|
ctx,
|
|
|
|
|
w,
|
|
|
|
|
err,
|
|
|
|
|
response.ErrBadRequest.Code,
|
|
|
|
|
response.ErrBadRequest.HttpCode,
|
|
|
|
|
err.Error(),
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.RespondJsonSuccess(ctx, w, userProfile)
|
|
|
|
|
})
|
|
|
|
|
}
|