modified: internal/service/user_service.go
fix bag with checking existens of user
This commit is contained in:
@@ -19,7 +19,8 @@ func NewUserService(userRepo *repository.UserRepository) *UserService {
|
|||||||
func (s *UserService) CreateUser(req *model.CreateUserRequest) (*model.UserResponse, error) {
|
func (s *UserService) CreateUser(req *model.CreateUserRequest) (*model.UserResponse, error) {
|
||||||
// Проверяем существует ли пользователь с таким email
|
// Проверяем существует ли пользователь с таким email
|
||||||
existingUser, err := s.userRepo.FindByEmail(req.Email)
|
existingUser, err := s.userRepo.FindByEmail(req.Email)
|
||||||
if err.Error() != "record not found" && existingUser.Email == "" {
|
// Проверяем как на nil, так на пустой ID
|
||||||
|
if existingUser != nil && existingUser.ID != 0 {
|
||||||
return nil, errors.New("user with this email already exists")
|
return nil, errors.New("user with this email already exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user