Files
apskel-pos-backend/internal/mappers/spin_game_mapper.go
efrilmandClaude Opus 5.5 c988a79d3b refactor(loyalty): remove what is left of tokens
Tokens are EnakCoin and no app uses the token names any more, so their
compatibility layer goes:

- GET /customer/tokens and its handler, service, processor and response
  types.
- total_tokens and tokens_history on GET /customer/wallet; last_updated
  now comes from the most recent row of either currency.
- token_used and tokens_remaining on game and spin responses, and
  sort_by=token_used on the game play list.
- TOKENS as a campaign type and reward type, with the mapping to COINS:
  migration 000092 already renamed the stored values.

The customer_tokens table and its entity stay, as cmd/wallet-migrate still
reads them, and LEGACY_TOKENS stays as the reference of the MIGRATION rows
it wrote. The docs list the removed names and their replacements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 16:55:27 +07:00

81 lines
2.4 KiB
Go

package mappers
import (
"apskel-pos-be/internal/contract"
"apskel-pos-be/internal/models"
)
// SpinGameRequestContractToModel converts spin game request from contract to model
func SpinGameRequestContractToModel(req *contract.SpinGameRequest) *models.SpinGameRequest {
if req == nil {
return nil
}
return &models.SpinGameRequest{
SpinID: req.SpinID,
}
}
// SpinGameResponseModelToContract converts spin game response from model to contract
func SpinGameResponseModelToContract(resp *models.SpinGameResponse) *contract.SpinGameResponse {
if resp == nil {
return nil
}
return &contract.SpinGameResponse{
Status: resp.Status,
Message: resp.Message,
Data: SpinGameResponseDataModelToContract(resp.Data),
}
}
// SpinGameResponseDataModelToContract converts spin game response data from model to contract
func SpinGameResponseDataModelToContract(data *models.SpinGameResponseData) *contract.SpinGameResponseData {
if data == nil {
return nil
}
return &contract.SpinGameResponseData{
GamePlay: GamePlayResponseModelToContract(&data.GamePlay),
PrizeWon: CustomerGamePrizeResponseModelToContract(data.PrizeWon),
CoinsRemaining: data.CoinsRemaining,
}
}
// GamePlayResponseModelToContract converts game play response from model to contract
func GamePlayResponseModelToContract(resp *models.GamePlayResponse) contract.GamePlayResponse {
if resp == nil {
return contract.GamePlayResponse{}
}
return contract.GamePlayResponse{
ID: resp.ID,
GameID: resp.GameID,
CustomerID: resp.CustomerID,
PrizeID: resp.PrizeID,
CoinsUsed: resp.CoinsUsed,
RandomSeed: resp.RandomSeed,
CreatedAt: resp.CreatedAt,
Game: nil, // Optional field - can be populated separately if needed
Customer: nil, // Optional field - can be populated separately if needed
Prize: nil, // Optional field - can be populated separately if needed
}
}
// CustomerGamePrizeResponseModelToContract converts customer game prize response from model to contract
func CustomerGamePrizeResponseModelToContract(resp *models.CustomerGamePrizeResponse) *contract.CustomerGamePrizeResponse {
if resp == nil {
return nil
}
return &contract.CustomerGamePrizeResponse{
ID: resp.ID,
GameID: resp.GameID,
Name: resp.Name,
Image: resp.Image,
Metadata: resp.Metadata,
CreatedAt: resp.CreatedAt,
UpdatedAt: resp.UpdatedAt,
}
}