50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
)
|
|
|
|
func (s *Service) CreateUser(ctx context.Context, User domain.CreateUserReq, createrUserId int64, branchId int64) (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)
|
|
}
|
|
|
|
return s.userStore.CreateUserWithoutOtp(ctx, User)
|
|
}
|
|
|
|
func (s *Service) DeleteUser(ctx context.Context, id int64) error {
|
|
// Delete User
|
|
return s.userStore.DeleteUser(ctx, id)
|
|
}
|
|
|
|
type Filter struct {
|
|
Role string
|
|
BranchId int64
|
|
Page int
|
|
PageSize int
|
|
}
|
|
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, error) {
|
|
// Get all Users
|
|
return s.userStore.GetAllUsers(ctx, filter)
|
|
}
|