Revert "feat(loyalty): EnakPoint & EnakCoin" (#32)
This reverts merge commit645da30, returning main tof0ff59f. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
645da3048e
commit
4e24f9bbb0
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"apskel-pos-be/internal/models"
|
||||
"apskel-pos-be/internal/processor"
|
||||
"apskel-pos-be/internal/repository"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -16,11 +17,13 @@ type SpinGameService interface {
|
||||
|
||||
type spinGameService struct {
|
||||
gamePlayProcessor *processor.GamePlayProcessor
|
||||
txManager *repository.TxManager
|
||||
}
|
||||
|
||||
func NewSpinGameService(gamePlayProcessor *processor.GamePlayProcessor) SpinGameService {
|
||||
func NewSpinGameService(gamePlayProcessor *processor.GamePlayProcessor, txManager *repository.TxManager) SpinGameService {
|
||||
return &spinGameService{
|
||||
gamePlayProcessor: gamePlayProcessor,
|
||||
txManager: txManager,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,13 +45,28 @@ func (s *spinGameService) PlaySpinGame(ctx context.Context, customerID string, r
|
||||
return nil, fmt.Errorf("invalid customer ID format: %w", err)
|
||||
}
|
||||
|
||||
// PlayGame runs its own transaction and charges the game's coin_cost in EnakCoin.
|
||||
playResponse, err := s.gamePlayProcessor.PlayGame(ctx, &models.PlayGameRequest{
|
||||
GameID: spinID,
|
||||
CustomerID: customerUUID,
|
||||
// Use transaction to ensure consistency
|
||||
var playResponse *models.PlayGameResponse
|
||||
err = s.txManager.WithTransaction(ctx, func(txCtx context.Context) error {
|
||||
// Create play game request
|
||||
playGameReq := &models.PlayGameRequest{
|
||||
GameID: spinID,
|
||||
CustomerID: customerUUID,
|
||||
TokenUsed: 1, // Default to 1 token per spin
|
||||
}
|
||||
|
||||
// Play the game within transaction
|
||||
var playErr error
|
||||
playResponse, playErr = s.gamePlayProcessor.PlayGame(txCtx, playGameReq)
|
||||
if playErr != nil {
|
||||
return fmt.Errorf("failed to play spin game: %w", playErr)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to play spin game: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Convert prize to customer-facing format
|
||||
@@ -70,9 +88,9 @@ func (s *spinGameService) PlaySpinGame(ctx context.Context, customerID string, r
|
||||
Status: "SUCCESS",
|
||||
Message: "Spin game completed successfully.",
|
||||
Data: &models.SpinGameResponseData{
|
||||
GamePlay: playResponse.GamePlay,
|
||||
PrizeWon: customerPrize,
|
||||
CoinsRemaining: playResponse.CoinsRemaining,
|
||||
GamePlay: playResponse.GamePlay,
|
||||
PrizeWon: customerPrize,
|
||||
TokensRemaining: playResponse.TokensRemaining,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user