77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
)
|
|
|
|
func (s *Service) CreateUser(ctx context.Context, User domain.CreateUserReq, is_company bool) (domain.User, error) {
|
|
// Create User
|
|
// creator, err := s.userStore.GetUserByID(ctx, createrUserId)
|
|
// if err != nil {
|
|
// return domain.User{}, err
|
|
// }
|
|
// if creator.Role != domain.RoleAdmin {
|
|
// User.BranchID = creator.BranchID
|
|
// User.Role = string(domain.RoleCashier)
|
|
// } else {
|
|
// User.BranchID = branchId
|
|
// User.Role = string(domain.RoleBranchManager)
|
|
// }
|
|
hashedPassword, err := hashPassword(User.Password)
|
|
if err != nil {
|
|
return domain.User{}, err
|
|
}
|
|
|
|
return s.userStore.CreateUserWithoutOtp(ctx, domain.User{
|
|
FirstName: User.FirstName,
|
|
LastName: User.LastName,
|
|
Email: User.Email,
|
|
PhoneNumber: User.PhoneNumber,
|
|
Password: hashedPassword,
|
|
Role: domain.Role(User.Role),
|
|
EmailVerified: true,
|
|
PhoneVerified: true,
|
|
Suspended: User.Suspended,
|
|
CompanyID: User.CompanyID,
|
|
}, is_company)
|
|
}
|
|
|
|
func (s *Service) DeleteUser(ctx context.Context, id int64) error {
|
|
// Delete User
|
|
return s.userStore.DeleteUser(ctx, id)
|
|
}
|
|
|
|
type Filter struct {
|
|
Role string
|
|
CompanyID domain.ValidInt64
|
|
Page domain.ValidInt
|
|
PageSize domain.ValidInt
|
|
}
|
|
type ValidRole struct {
|
|
Value domain.Role
|
|
Valid bool
|
|
}
|
|
type ValidBranchId struct {
|
|
Value int64
|
|
Valid bool
|
|
}
|
|
|
|
func (s *Service) GetAllUsers(ctx context.Context, filter Filter) ([]domain.User, int64, error) {
|
|
// Get all Users
|
|
return s.userStore.GetAllUsers(ctx, filter)
|
|
}
|
|
func (s *Service) GetUserById(ctx context.Context, id int64) (domain.User, error) {
|
|
|
|
return s.userStore.GetUserByID(ctx, id)
|
|
}
|
|
|
|
func (s *Service) GetCashiersByBranch(ctx context.Context, branchID int64) ([]domain.User, error) {
|
|
return s.userStore.GetCashiersByBranch(ctx, branchID)
|
|
}
|
|
|
|
func (s *Service) GetAllCashiers(ctx context.Context) ([]domain.User, error) {
|
|
return s.userStore.GetAllCashiers(ctx)
|
|
}
|