feat: get all staff
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package staffhttp
|
||||
|
||||
import (
|
||||
authmiddleware "legalgo-BE-go/internal/api/http/middleware/auth"
|
||||
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||
"legalgo-BE-go/internal/utilities/response"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
func GetStaffs(
|
||||
router chi.Router,
|
||||
staffSvc staffsvc.Auth,
|
||||
) {
|
||||
router.With(authmiddleware.Authorize()).Get("/staff/get-all", 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
|
||||
}
|
||||
|
||||
staffs, err := staffSvc.GetStaffs()
|
||||
if err != nil {
|
||||
response.RespondJsonErrorWithCode(
|
||||
ctx,
|
||||
w,
|
||||
err,
|
||||
response.ErrBadRequest.Code,
|
||||
response.ErrBadRequest.HttpCode,
|
||||
err.Error(),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
response.RespondJsonSuccess(ctx, w, staffs)
|
||||
})
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package staffhttp
|
||||
|
||||
import (
|
||||
authmiddleware "legalgo-BE-go/internal/api/http/middleware/auth"
|
||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
||||
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||
"legalgo-BE-go/internal/utilities/response"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
"net/http"
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
responsedomain "legalgo-BE-go/internal/domain/reponse"
|
||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
||||
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||
"legalgo-BE-go/internal/utilities/response"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
|
||||
|
||||
@@ -9,5 +9,6 @@ var Module = fx.Module("auth-api",
|
||||
Update,
|
||||
GetProfile,
|
||||
GetUsers,
|
||||
GetStaffs,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package staffhttp
|
||||
|
||||
import (
|
||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
||||
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||
"legalgo-BE-go/internal/utilities/response"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
"net/http"
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
||||
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||
"legalgo-BE-go/internal/utilities/response"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package staffhttp
|
||||
|
||||
import (
|
||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
||||
staffsvc "legalgo-BE-go/internal/services/staff"
|
||||
"legalgo-BE-go/internal/utilities/response"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
"net/http"
|
||||
|
||||
Reference in New Issue
Block a user