fix: improvement access data
This commit is contained in:
parent
11bc19360c
commit
ee8e8e140d
@ -5,17 +5,17 @@ import (
|
||||
userdomain "legalgo-BE-go/internal/domain/user"
|
||||
)
|
||||
|
||||
func (ur *accessor) GetUserProfile(email string) (*userdomain.UserProfile, error) {
|
||||
func (ur *accessor) GetUserProfile(id string) (*userdomain.UserProfile, error) {
|
||||
var user *userdomain.User
|
||||
|
||||
if email == "" {
|
||||
if id == "" {
|
||||
return nil, fmt.Errorf("email is empty")
|
||||
}
|
||||
|
||||
if err := ur.db.
|
||||
Preload("Subscribe").
|
||||
Preload("Subscribe.SubscribePlan").
|
||||
First(&user, "email = ?", email).
|
||||
First(&user, "id = ?", id).
|
||||
Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -59,20 +59,7 @@ func Create(
|
||||
return
|
||||
}
|
||||
|
||||
staffProfile, err := staffRepo.GetStaffByEmail(destructedToken.Email)
|
||||
if err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
ctx,
|
||||
w,
|
||||
err,
|
||||
response.ErrBadRequest.Code,
|
||||
response.ErrBadRequest.HttpCode,
|
||||
err.Error(),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if err := newsSvc.Create(spec, staffProfile.ID); err != nil {
|
||||
if err := newsSvc.Create(spec, destructedToken.ID); err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
ctx,
|
||||
w,
|
||||
|
||||
@ -48,19 +48,6 @@ func Update(
|
||||
return
|
||||
}
|
||||
|
||||
staff, err := authSvc.GetProfile(destructedToken.Email)
|
||||
if err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
ctx,
|
||||
w,
|
||||
err,
|
||||
response.ErrBadRequest.Code,
|
||||
response.ErrBadRequest.HttpCode,
|
||||
err.Error(),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
var spec newsdomain.NewsUpdate
|
||||
if err := utils.UnmarshalBody(r, &spec); err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
@ -76,7 +63,7 @@ func Update(
|
||||
|
||||
spec.ID = newsID
|
||||
|
||||
if err := newsSvc.Update(staff.ID, spec); err != nil {
|
||||
if err := newsSvc.Update(destructedToken.ID, spec); err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
ctx,
|
||||
w,
|
||||
|
||||
@ -28,7 +28,7 @@ func GetProfile(
|
||||
return
|
||||
}
|
||||
|
||||
staffProfile, err := authSvc.GetProfile(destructedToken.Email)
|
||||
staffProfile, err := authSvc.GetProfile(destructedToken.ID)
|
||||
if err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
ctx,
|
||||
|
||||
@ -60,7 +60,7 @@ func Update(
|
||||
return
|
||||
}
|
||||
|
||||
user, err := userRepo.GetUserProfile(detail.Email)
|
||||
user, err := userRepo.GetUserProfile(detail.ID)
|
||||
|
||||
body.ID = user.Subscribe.ID
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ func GetProfile(
|
||||
return
|
||||
}
|
||||
|
||||
userProfile, err := userSvc.GetUserProfile(destructedToken.Email)
|
||||
userProfile, err := userSvc.GetUserProfile(destructedToken.ID)
|
||||
if err != nil {
|
||||
response.ResponseWithErrorCode(
|
||||
ctx,
|
||||
|
||||
@ -4,8 +4,8 @@ import (
|
||||
staffdomain "legalgo-BE-go/internal/domain/staff"
|
||||
)
|
||||
|
||||
func (as *impl) GetProfile(email string) (*staffdomain.StaffProfile, error) {
|
||||
staff, err := as.staffRepo.GetStaffByEmail(email)
|
||||
func (as *impl) GetProfile(id string) (*staffdomain.StaffProfile, error) {
|
||||
staff, err := as.staffRepo.GetStaffByID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user