add bb_api rest api for begushiybashkir

This commit is contained in:
2025-10-07 05:23:40 +05:00
parent de0c992db9
commit 23d68e53ab
16 changed files with 552 additions and 1 deletions
@@ -0,0 +1,52 @@
package service
import (
"errors"
"go-rest-api/internal/models"
"go-rest-api/internal/repository"
)
type AuthService interface {
Register(user *models.User) error
Login(email, password string) (*models.User, error)
}
type authService struct {
userRepo repository.UserRepository
}
func NewAuthService(userRepo repository.UserRepository) AuthService {
return &authService{userRepo: userRepo}
}
func (s *authService) Register(user *models.User) error {
// Проверка существования пользователя
existingUser, _ := s.userRepo.FindByEmail(user.Email)
if existingUser != nil {
return errors.New("user already exists")
}
// Здесь должна быть хеширование пароля
// user.Password = hashPassword(user.Password)
return s.userRepo.Create(user)
}
func (s *authService) Login(email, password string) (*models.User, error) {
user, err := s.userRepo.FindByEmail(email)
if err != nil {
return nil, errors.New("invalid credentials")
}
// Здесь должна быть проверка хеша пароля
// if !checkPasswordHash(password, user.Password) {
// return nil, errors.New("invalid credentials")
// }
// Временно просто проверяем напрямую (для демо)
if user.Password != password {
return nil, errors.New("invalid credentials")
}
return user, nil
}