Initial setup

This commit is contained in:
$(pass /github/name)
2024-06-26 13:08:39 +02:00
parent 164c07e3d1
commit fbb3bdfcb3
16 changed files with 279 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package services
import (
"GoMembership/internal/models"
"GoMembership/internal/repositories"
"golang.org/x/crypto/bcrypt"
)
type UserService interface {
RegisterUser(user *models.User) error
}
type userService struct {
repo repositories.UserRepository
}
func NewUserService(repo repositories.UserRepository) UserService {
return &userService{repo}
}
func (s *userService) RegisterUser(user *models.User) error {
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(user.Password), bcrypt.DefaultCost)
if err != nil {
return err
}
user.Password = string(hashedPassword)
return s.repo.CreateUser(user)
}