43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
type Service struct {
|
|
userStore UserStore
|
|
}
|
|
|
|
func NewService(userStore UserStore, RefreshExpiry int) *Service {
|
|
return &Service{
|
|
userStore: userStore,
|
|
}
|
|
}
|
|
|
|
func (s *Service) CreateUser(ctx context.Context, firstName, lastName, email, phoneNumber, password, role string, verified bool) (domain.User, error) {
|
|
return s.userStore.CreateUser(ctx, firstName, lastName, email, phoneNumber, password, role, verified)
|
|
}
|
|
func (s *Service) GetUserByID(ctx context.Context, id int64) (domain.User, error) {
|
|
return s.userStore.GetUserByID(ctx, id)
|
|
}
|
|
func (s *Service) GetAllUsers(ctx context.Context) ([]domain.User, error) {
|
|
return s.userStore.GetAllUsers(ctx)
|
|
}
|
|
func (s *Service) UpdateUser(ctx context.Context, id int64, firstName, lastName, email, phoneNumber, password, role string, verified bool) error {
|
|
return s.userStore.UpdateUser(ctx, id, firstName, lastName, email, phoneNumber, password, role, verified)
|
|
}
|
|
func (s *Service) DeleteUser(ctx context.Context, id int64) error {
|
|
return s.userStore.DeleteUser(ctx, id)
|
|
}
|
|
func hashPassword(plaintextPassword string) ([]byte, error) {
|
|
hash, err := bcrypt.GenerateFromPassword([]byte(plaintextPassword), 12)
|
|
if err != nil {
|
|
return []byte{}, err
|
|
}
|
|
|
|
return hash, nil
|
|
}
|