fix: get profile user/staff using token rather than id
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package userrepository
|
||||
|
||||
import (
|
||||
"errors"
|
||||
authdomain "legalgo-BE-go/internal/domain/auth"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (ur *UserRepository) GetUserProfile(email string) (*authdomain.UserProfile, error) {
|
||||
var users []authdomain.UserProfile
|
||||
|
||||
if email == "" {
|
||||
return nil, errors.New("email is empty")
|
||||
}
|
||||
|
||||
if err := ur.DB.Table("users u").
|
||||
Select("u.email, u.id, s.status as subscribe_status, sp.code as subscribe_plan_code, sp.name as subscribe_plan_name").
|
||||
Joins("join subscribes s on s.id = u.subscribe_id").
|
||||
Joins("join subscribe_plans sp on s.subscribe_plan_id = sp.id").
|
||||
Scan(&users).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errors.New("user not found")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &users[0], nil
|
||||
}
|
||||
@@ -12,6 +12,7 @@ type UserRepository struct {
|
||||
type UserIntf interface {
|
||||
GetUserByEmail(string) (*authdomain.User, error)
|
||||
GetUserByID(string) (*authdomain.UserProfile, error)
|
||||
GetUserProfile(string) (*authdomain.UserProfile, error)
|
||||
CreateUser(*authdomain.User) (*authdomain.User, error)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user