74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
package bet
|
|
|
|
import (
|
|
"context"
|
|
"crypto/rand"
|
|
"math/big"
|
|
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
)
|
|
|
|
type Service struct {
|
|
betStore BetStore
|
|
}
|
|
|
|
func NewService(betStore BetStore) *Service {
|
|
return &Service{
|
|
betStore: betStore,
|
|
}
|
|
}
|
|
|
|
func (s *Service) GenerateCashoutID() (string, error) {
|
|
const chars = "abcdefghijklmnopqrstuvwxyz0123456789"
|
|
const length int = 13
|
|
charLen := big.NewInt(int64(len(chars)))
|
|
result := make([]byte, length)
|
|
for i := 0; i < length; i++ {
|
|
index, err := rand.Int(rand.Reader, charLen)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
result[i] = chars[index.Int64()]
|
|
}
|
|
return string(result), nil
|
|
}
|
|
|
|
func (s *Service) CreateBet(ctx context.Context, bet domain.CreateBet) (domain.Bet, error) {
|
|
|
|
return s.betStore.CreateBet(ctx, bet)
|
|
}
|
|
|
|
func (s *Service) CreateBetOutcome(ctx context.Context, outcomes []domain.CreateBetOutcome) (int64, error) {
|
|
return s.betStore.CreateBetOutcome(ctx, outcomes)
|
|
}
|
|
|
|
func (s *Service) GetBetByID(ctx context.Context, id int64) (domain.GetBet, error) {
|
|
return s.betStore.GetBetByID(ctx, id)
|
|
}
|
|
func (s *Service) GetBetByCashoutID(ctx context.Context, id string) (domain.GetBet, error) {
|
|
return s.betStore.GetBetByCashoutID(ctx, id)
|
|
}
|
|
func (s *Service) GetAllBets(ctx context.Context) ([]domain.GetBet, error) {
|
|
return s.betStore.GetAllBets(ctx)
|
|
}
|
|
|
|
func (s *Service) GetBetByBranchID(ctx context.Context, branchID int64) ([]domain.GetBet, error) {
|
|
return s.betStore.GetBetByBranchID(ctx, branchID)
|
|
}
|
|
|
|
func (s *Service) UpdateCashOut(ctx context.Context, id int64, cashedOut bool) error {
|
|
return s.betStore.UpdateCashOut(ctx, id, cashedOut)
|
|
}
|
|
|
|
func (s *Service) UpdateStatus(ctx context.Context, id int64, status domain.OutcomeStatus) error {
|
|
return s.betStore.UpdateStatus(ctx, id, status)
|
|
}
|
|
|
|
func (s *Service) UpdateBetOutcomeStatus(ctx context.Context, id int64, status domain.OutcomeStatus) error {
|
|
return s.betStore.UpdateBetOutcomeStatus(ctx, id, status)
|
|
}
|
|
|
|
func (s *Service) DeleteBet(ctx context.Context, id int64) error {
|
|
return s.betStore.DeleteBet(ctx, id)
|
|
}
|