legalgo-BE-go/internal/accessor/user/get_user_profile.go

32 lines
590 B
Go
Raw Normal View History

package userrepository
import (
2025-03-14 12:41:11 +08:00
"fmt"
userdomain "legalgo-BE-go/internal/domain/user"
)
2025-03-14 13:00:12 +08:00
func (ur *accessor) GetUserProfile(id string) (*userdomain.UserProfile, error) {
var user *userdomain.User
2025-03-14 13:00:12 +08:00
if id == "" {
2025-03-14 12:41:11 +08:00
return nil, fmt.Errorf("email is empty")
}
2025-03-06 23:55:46 +08:00
if err := ur.db.
Preload("Subscribe").
Preload("Subscribe.SubscribePlan").
2025-03-14 13:00:12 +08:00
First(&user, "id = ?", id).
Error; err != nil {
return nil, err
}
userProfile := &userdomain.UserProfile{
ID: user.ID,
Email: user.Email,
Phone: user.Phone,
Subscribe: user.Subscribe,
}
return userProfile, nil
}