feat: update staff data
This commit is contained in:
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
authmiddleware "legalgo-BE-go/internal/api/http/middleware/auth"
|
||||
newsdomain "legalgo-BE-go/internal/domain/news"
|
||||
authsvc "legalgo-BE-go/internal/services/auth"
|
||||
newssvc "legalgo-BE-go/internal/services/news"
|
||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
||||
"legalgo-BE-go/internal/utilities/response"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
"net/http"
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
func Update(
|
||||
router chi.Router,
|
||||
newsSvc newssvc.News,
|
||||
authSvc authsvc.Auth,
|
||||
authSvc staffsvc.Auth,
|
||||
) {
|
||||
router.With(authmiddleware.Authorize()).
|
||||
Put("/news/{news_id}/update", func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -48,7 +48,7 @@ func Update(
|
||||
return
|
||||
}
|
||||
|
||||
staff, err := authSvc.GetStaffProfile(destructedToken.Email)
|
||||
staff, err := authSvc.GetProfile(destructedToken.Email)
|
||||
if err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
ctx,
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
categoryhttp "legalgo-BE-go/internal/api/http/category"
|
||||
newshttp "legalgo-BE-go/internal/api/http/news"
|
||||
osshttp "legalgo-BE-go/internal/api/http/oss"
|
||||
staffhttp "legalgo-BE-go/internal/api/http/staffhttp"
|
||||
staffhttp "legalgo-BE-go/internal/api/http/staff"
|
||||
subscribehttp "legalgo-BE-go/internal/api/http/subscribe"
|
||||
subscribeplanhttp "legalgo-BE-go/internal/api/http/subscribe_plan"
|
||||
taghttp "legalgo-BE-go/internal/api/http/tag"
|
||||
|
||||
@@ -2,7 +2,7 @@ package staffhttp
|
||||
|
||||
import (
|
||||
authmiddleware "legalgo-BE-go/internal/api/http/middleware/auth"
|
||||
authsvc "legalgo-BE-go/internal/services/auth"
|
||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
||||
"legalgo-BE-go/internal/utilities/response"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
"net/http"
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func GetUsers(
|
||||
router chi.Router,
|
||||
authSvc authsvc.Auth,
|
||||
authSvc staffsvc.Auth,
|
||||
) {
|
||||
router.With(authmiddleware.Authorize()).Get("/staff/users", func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
responsedomain "legalgo-BE-go/internal/domain/reponse"
|
||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||
authsvc "legalgo-BE-go/internal/services/auth"
|
||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
||||
"legalgo-BE-go/internal/utilities/response"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
|
||||
func Login(
|
||||
router chi.Router,
|
||||
authSvc authsvc.Auth,
|
||||
authSvc staffsvc.Auth,
|
||||
validate *validator.Validate,
|
||||
rdb *redis.Client,
|
||||
) {
|
||||
@@ -49,7 +49,7 @@ func Login(
|
||||
return
|
||||
}
|
||||
|
||||
token, err := authSvc.LoginAsStaff(spec)
|
||||
token, err := authSvc.Login(spec)
|
||||
if err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
ctx,
|
||||
@@ -1,7 +1,7 @@
|
||||
package staffhttp
|
||||
|
||||
import (
|
||||
authsvc "legalgo-BE-go/internal/services/auth"
|
||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
||||
"legalgo-BE-go/internal/utilities/response"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
"net/http"
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
func GetProfile(
|
||||
router chi.Router,
|
||||
authSvc authsvc.Auth,
|
||||
authSvc staffsvc.Auth,
|
||||
) {
|
||||
router.Get("/staff/profile", func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
@@ -28,7 +28,7 @@ func GetProfile(
|
||||
return
|
||||
}
|
||||
|
||||
staffProfile, err := authSvc.GetStaffProfile(destructedToken.Email)
|
||||
staffProfile, err := authSvc.GetProfile(destructedToken.Email)
|
||||
if err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
ctx,
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
responsedomain "legalgo-BE-go/internal/domain/reponse"
|
||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||
authsvc "legalgo-BE-go/internal/services/auth"
|
||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
||||
"legalgo-BE-go/internal/utilities/response"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
func Register(
|
||||
router chi.Router,
|
||||
validate *validator.Validate,
|
||||
authSvc authsvc.Auth,
|
||||
authSvc staffsvc.Auth,
|
||||
rdb *redis.Client,
|
||||
) {
|
||||
router.Post("/staff/register", func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -49,7 +49,7 @@ func Register(
|
||||
return
|
||||
}
|
||||
|
||||
token, err := authSvc.RegisterStaff(spec)
|
||||
token, err := authSvc.Register(spec)
|
||||
if err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
ctx,
|
||||
@@ -1,9 +1,8 @@
|
||||
package staffhttp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||
authsvc "legalgo-BE-go/internal/services/auth"
|
||||
staffsvc "legalgo-BE-go/internal/services/staffsvc"
|
||||
"legalgo-BE-go/internal/utilities/response"
|
||||
"legalgo-BE-go/internal/utilities/utils"
|
||||
"net/http"
|
||||
@@ -13,25 +12,25 @@ import (
|
||||
|
||||
func Update(
|
||||
router chi.Router,
|
||||
authSvc authsvc.Auth,
|
||||
authSvc staffsvc.Auth,
|
||||
) {
|
||||
router.Patch("/staff/{id}/update", func(w http.ResponseWriter, r *http.Request) {
|
||||
router.Put("/staff/update", func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
id := chi.URLParam(r, "id")
|
||||
if id == "" {
|
||||
destructedToken, err := utils.GetTokenDetail(r)
|
||||
if err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
ctx,
|
||||
w,
|
||||
errors.New("provided id is empty"),
|
||||
err,
|
||||
response.ErrBadRequest.Code,
|
||||
response.ErrBadRequest.HttpCode,
|
||||
"required params is not provided",
|
||||
err.Error(),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
var spec staffdomain.StaffRegister
|
||||
var spec staffdomain.StaffUpdate
|
||||
|
||||
if err := utils.UnmarshalBody(r, &spec); err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
@@ -45,14 +44,7 @@ func Update(
|
||||
return
|
||||
}
|
||||
|
||||
staff := staffdomain.Staff{
|
||||
ID: id,
|
||||
Email: spec.Email,
|
||||
Password: spec.Password,
|
||||
Name: spec.Name,
|
||||
}
|
||||
|
||||
if err := authSvc.UpdateStaff(staff); err != nil {
|
||||
if err := authSvc.Update(destructedToken.ID, spec); err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
ctx,
|
||||
w,
|
||||
Reference in New Issue
Block a user