Reapply "feat(loyalty): EnakPoint & EnakCoin" (#32)

This reverts commit 4e24f9bbb0.
This commit is contained in:
efrilm
2026-09-30 15:31:44 +07:00
parent 4e24f9bbb0
commit 582dc75543
195 changed files with 20058 additions and 2177 deletions
+9 -27
View File
@@ -6,7 +6,6 @@ import (
"apskel-pos-be/internal/models"
"apskel-pos-be/internal/processor"
"apskel-pos-be/internal/repository"
"github.com/google/uuid"
)
@@ -17,13 +16,11 @@ type SpinGameService interface {
type spinGameService struct {
gamePlayProcessor *processor.GamePlayProcessor
txManager *repository.TxManager
}
func NewSpinGameService(gamePlayProcessor *processor.GamePlayProcessor, txManager *repository.TxManager) SpinGameService {
func NewSpinGameService(gamePlayProcessor *processor.GamePlayProcessor) SpinGameService {
return &spinGameService{
gamePlayProcessor: gamePlayProcessor,
txManager: txManager,
}
}
@@ -45,28 +42,13 @@ func (s *spinGameService) PlaySpinGame(ctx context.Context, customerID string, r
return nil, fmt.Errorf("invalid customer ID format: %w", err)
}
// 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
// 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,
})
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to play spin game: %w", err)
}
// Convert prize to customer-facing format
@@ -88,9 +70,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,
TokensRemaining: playResponse.TokensRemaining,
GamePlay: playResponse.GamePlay,
PrizeWon: customerPrize,
CoinsRemaining: playResponse.CoinsRemaining,
},
}