76 lines
1.5 KiB
Go
76 lines
1.5 KiB
Go
package authhttp
|
|
|
|
import (
|
|
"errors"
|
|
authdomain "legalgo-BE-go/internal/domain/auth"
|
|
authsvc "legalgo-BE-go/internal/services/auth"
|
|
"legalgo-BE-go/internal/utilities/response"
|
|
"legalgo-BE-go/internal/utilities/utils"
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
func UpdateStaff(
|
|
router chi.Router,
|
|
authSvc authsvc.AuthIntf,
|
|
) {
|
|
router.Patch("/staff/{id}/update", func(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
id := chi.URLParam(r, "id")
|
|
if id == "" {
|
|
response.ResponseWithErrorCode(
|
|
ctx,
|
|
w,
|
|
errors.New("provided id is empty"),
|
|
response.ErrBadRequest.Code,
|
|
response.ErrBadRequest.HttpCode,
|
|
"required params is not provided",
|
|
)
|
|
return
|
|
}
|
|
|
|
var spec authdomain.RegisterStaffReq
|
|
|
|
if err := utils.UnmarshalBody(r, &spec); err != nil {
|
|
response.ResponseWithErrorCode(
|
|
ctx,
|
|
w,
|
|
err,
|
|
response.ErrBadRequest.Code,
|
|
response.ErrBadRequest.HttpCode,
|
|
"failed to unmarshal request",
|
|
)
|
|
return
|
|
}
|
|
|
|
staff := authdomain.Staff{
|
|
ID: id,
|
|
Email: spec.Email,
|
|
Password: spec.Password,
|
|
Name: spec.Name,
|
|
}
|
|
|
|
if err := authSvc.UpdateStaff(staff); err != nil {
|
|
response.ResponseWithErrorCode(
|
|
ctx,
|
|
w,
|
|
err,
|
|
response.ErrBadRequest.Code,
|
|
response.ErrBadRequest.HttpCode,
|
|
err.Error(),
|
|
)
|
|
return
|
|
}
|
|
|
|
responsePayload := struct {
|
|
Message string
|
|
}{
|
|
Message: "update staff success",
|
|
}
|
|
|
|
response.RespondJsonSuccess(ctx, w, responsePayload)
|
|
})
|
|
}
|