feat: update staff data

This commit is contained in:
ericprd
2025-03-14 12:41:11 +08:00
parent 1297c71200
commit 11bc19360c
31 changed files with 130 additions and 115 deletions
+59
View File
@@ -0,0 +1,59 @@
package staffhttp
import (
authmiddleware "legalgo-BE-go/internal/api/http/middleware/auth"
staffsvc "legalgo-BE-go/internal/services/staffsvc"
"legalgo-BE-go/internal/utilities/response"
"legalgo-BE-go/internal/utilities/utils"
"net/http"
"github.com/go-chi/chi/v5"
)
func GetUsers(
router chi.Router,
authSvc staffsvc.Auth,
) {
router.With(authmiddleware.Authorize()).Get("/staff/users", func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
staffDetail, err := utils.GetTokenDetail(r)
if err != nil {
response.RespondJsonErrorWithCode(
ctx,
w,
err,
response.ErrBadRequest.Code,
response.ErrBadRequest.HttpCode,
"failed to get staff token",
)
return
}
if staffDetail.Role != "staff" {
response.RespondJsonErrorWithCode(
ctx,
w,
err,
response.ErrUnauthorized.Code,
response.ErrUnauthorized.HttpCode,
"unauthorized",
)
return
}
users, err := authSvc.GetUsers()
if err != nil {
response.RespondJsonErrorWithCode(
ctx,
w,
err,
response.ErrBadRequest.Code,
response.ErrBadRequest.HttpCode,
"failed to get users",
)
return
}
response.RespondJsonSuccess(ctx, w, users)
})
}