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>
401 lines
11 KiB
Go
401 lines
11 KiB
Go
package transformer
|
|
|
|
import (
|
|
"apskel-pos-be/internal/contract"
|
|
"apskel-pos-be/internal/models"
|
|
)
|
|
|
|
// Tier Transformers
|
|
func CreateTierRequestToModel(req *contract.CreateTierRequest) *models.CreateTierRequest {
|
|
return &models.CreateTierRequest{
|
|
Name: req.Name,
|
|
MinPoints: req.MinPoints,
|
|
Benefits: req.Benefits,
|
|
}
|
|
}
|
|
|
|
func UpdateTierRequestToModel(req *contract.UpdateTierRequest) *models.UpdateTierRequest {
|
|
return &models.UpdateTierRequest{
|
|
Name: req.Name,
|
|
MinPoints: req.MinPoints,
|
|
Benefits: req.Benefits,
|
|
}
|
|
}
|
|
|
|
func ListTiersRequestToModel(req *contract.ListTiersRequest) *models.ListTiersQuery {
|
|
return &models.ListTiersQuery{
|
|
Page: req.Page,
|
|
Limit: req.Limit,
|
|
Search: req.Search,
|
|
SortBy: req.SortBy,
|
|
SortOrder: req.SortOrder,
|
|
}
|
|
}
|
|
|
|
func TierModelToResponse(model *models.TierResponse) *contract.TierResponse {
|
|
return &contract.TierResponse{
|
|
ID: model.ID,
|
|
Name: model.Name,
|
|
MinPoints: model.MinPoints,
|
|
Benefits: model.Benefits,
|
|
CreatedAt: model.CreatedAt,
|
|
UpdatedAt: model.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
func PaginatedTiersResponseToContract(model *models.PaginatedResponse[models.TierResponse]) *contract.PaginatedTiersResponse {
|
|
responses := make([]contract.TierResponse, len(model.Data))
|
|
for i, item := range model.Data {
|
|
responses[i] = *TierModelToResponse(&item)
|
|
}
|
|
|
|
return &contract.PaginatedTiersResponse{
|
|
Data: responses,
|
|
TotalCount: int(model.Pagination.Total),
|
|
Page: model.Pagination.Page,
|
|
Limit: model.Pagination.Limit,
|
|
TotalPages: model.Pagination.TotalPages,
|
|
}
|
|
}
|
|
|
|
// Game Transformers
|
|
func CreateGameRequestToModel(req *contract.CreateGameRequest) *models.CreateGameRequest {
|
|
return &models.CreateGameRequest{
|
|
Name: req.Name,
|
|
Type: req.Type,
|
|
IsActive: req.IsActive,
|
|
Metadata: req.Metadata,
|
|
}
|
|
}
|
|
|
|
func UpdateGameRequestToModel(req *contract.UpdateGameRequest) *models.UpdateGameRequest {
|
|
return &models.UpdateGameRequest{
|
|
Name: req.Name,
|
|
Type: req.Type,
|
|
IsActive: req.IsActive,
|
|
Metadata: req.Metadata,
|
|
}
|
|
}
|
|
|
|
func ListGamesRequestToModel(req *contract.ListGamesRequest) *models.ListGamesQuery {
|
|
return &models.ListGamesQuery{
|
|
Page: req.Page,
|
|
Limit: req.Limit,
|
|
Search: req.Search,
|
|
Type: req.Type,
|
|
IsActive: req.IsActive,
|
|
SortBy: req.SortBy,
|
|
SortOrder: req.SortOrder,
|
|
}
|
|
}
|
|
|
|
func GameModelToResponse(model *models.GameResponse) *contract.GameResponse {
|
|
if model == nil {
|
|
return nil
|
|
}
|
|
|
|
return &contract.GameResponse{
|
|
ID: model.ID,
|
|
Name: model.Name,
|
|
Type: model.Type,
|
|
IsActive: model.IsActive,
|
|
Metadata: model.Metadata,
|
|
CreatedAt: model.CreatedAt,
|
|
UpdatedAt: model.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
func GameModelsToResponses(models []models.GameResponse) []contract.GameResponse {
|
|
responses := make([]contract.GameResponse, len(models))
|
|
for i, model := range models {
|
|
responses[i] = *GameModelToResponse(&model)
|
|
}
|
|
return responses
|
|
}
|
|
|
|
func PaginatedGamesResponseToContract(model *models.PaginatedResponse[models.GameResponse]) *contract.PaginatedGamesResponse {
|
|
responses := make([]contract.GameResponse, len(model.Data))
|
|
for i, item := range model.Data {
|
|
responses[i] = *GameModelToResponse(&item)
|
|
}
|
|
|
|
return &contract.PaginatedGamesResponse{
|
|
Data: responses,
|
|
TotalCount: int(model.Pagination.Total),
|
|
Page: model.Pagination.Page,
|
|
Limit: model.Pagination.Limit,
|
|
TotalPages: model.Pagination.TotalPages,
|
|
}
|
|
}
|
|
|
|
// Game Prize Transformers
|
|
func CreateGamePrizeRequestToModel(req *contract.CreateGamePrizeRequest) *models.CreateGamePrizeRequest {
|
|
return &models.CreateGamePrizeRequest{
|
|
GameID: req.GameID,
|
|
Name: req.Name,
|
|
Weight: req.Weight,
|
|
Stock: req.Stock,
|
|
MaxStock: req.MaxStock,
|
|
Threshold: req.Threshold,
|
|
FallbackPrizeID: req.FallbackPrizeID,
|
|
Metadata: req.Metadata,
|
|
}
|
|
}
|
|
|
|
func UpdateGamePrizeRequestToModel(req *contract.UpdateGamePrizeRequest) *models.UpdateGamePrizeRequest {
|
|
return &models.UpdateGamePrizeRequest{
|
|
Name: req.Name,
|
|
Weight: req.Weight,
|
|
Stock: req.Stock,
|
|
MaxStock: req.MaxStock,
|
|
Threshold: req.Threshold,
|
|
FallbackPrizeID: req.FallbackPrizeID,
|
|
Metadata: req.Metadata,
|
|
}
|
|
}
|
|
|
|
func ListGamePrizesRequestToModel(req *contract.ListGamePrizesRequest) *models.ListGamePrizesQuery {
|
|
return &models.ListGamePrizesQuery{
|
|
Page: req.Page,
|
|
Limit: req.Limit,
|
|
Search: req.Search,
|
|
GameID: req.GameID,
|
|
SortBy: req.SortBy,
|
|
SortOrder: req.SortOrder,
|
|
}
|
|
}
|
|
|
|
func GamePrizeModelToResponse(model *models.GamePrizeResponse) *contract.GamePrizeResponse {
|
|
if model == nil {
|
|
return nil
|
|
}
|
|
|
|
var game *contract.GameResponse
|
|
if model.Game != nil {
|
|
game = GameModelToResponse(model.Game)
|
|
}
|
|
|
|
var fallbackPrize *contract.GamePrizeResponse
|
|
if model.FallbackPrize != nil {
|
|
fallbackPrize = GamePrizeModelToResponse(model.FallbackPrize)
|
|
}
|
|
|
|
return &contract.GamePrizeResponse{
|
|
ID: model.ID,
|
|
GameID: model.GameID,
|
|
Name: model.Name,
|
|
Weight: model.Weight,
|
|
Stock: model.Stock,
|
|
MaxStock: model.MaxStock,
|
|
Threshold: model.Threshold,
|
|
FallbackPrizeID: model.FallbackPrizeID,
|
|
Metadata: model.Metadata,
|
|
Game: game,
|
|
FallbackPrize: fallbackPrize,
|
|
CreatedAt: model.CreatedAt,
|
|
UpdatedAt: model.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
func GamePrizeModelsToResponses(models []models.GamePrizeResponse) []contract.GamePrizeResponse {
|
|
responses := make([]contract.GamePrizeResponse, len(models))
|
|
for i, model := range models {
|
|
responses[i] = *GamePrizeModelToResponse(&model)
|
|
}
|
|
return responses
|
|
}
|
|
|
|
func PaginatedGamePrizesResponseToContract(model *models.PaginatedResponse[models.GamePrizeResponse]) *contract.PaginatedGamePrizesResponse {
|
|
responses := make([]contract.GamePrizeResponse, len(model.Data))
|
|
for i, item := range model.Data {
|
|
responses[i] = *GamePrizeModelToResponse(&item)
|
|
}
|
|
|
|
return &contract.PaginatedGamePrizesResponse{
|
|
Data: responses,
|
|
TotalCount: int(model.Pagination.Total),
|
|
Page: model.Pagination.Page,
|
|
Limit: model.Pagination.Limit,
|
|
TotalPages: model.Pagination.TotalPages,
|
|
}
|
|
}
|
|
|
|
// Game Play Transformers
|
|
func CreateGamePlayRequestToModel(req *contract.CreateGamePlayRequest) *models.CreateGamePlayRequest {
|
|
return &models.CreateGamePlayRequest{
|
|
GameID: req.GameID,
|
|
CustomerID: req.CustomerID,
|
|
CoinsUsed: req.CoinsUsed,
|
|
RandomSeed: req.RandomSeed,
|
|
}
|
|
}
|
|
|
|
func PlayGameRequestToModel(req *contract.PlayGameRequest) *models.PlayGameRequest {
|
|
return &models.PlayGameRequest{
|
|
GameID: req.GameID,
|
|
CustomerID: req.CustomerID,
|
|
}
|
|
}
|
|
|
|
func ListGamePlaysRequestToModel(req *contract.ListGamePlaysRequest) *models.ListGamePlaysQuery {
|
|
return &models.ListGamePlaysQuery{
|
|
Page: req.Page,
|
|
Limit: req.Limit,
|
|
Search: req.Search,
|
|
GameID: req.GameID,
|
|
CustomerID: req.CustomerID,
|
|
PrizeID: req.PrizeID,
|
|
SortBy: req.SortBy,
|
|
SortOrder: req.SortOrder,
|
|
}
|
|
}
|
|
|
|
func GamePlayModelToResponse(model *models.GamePlayResponse) *contract.GamePlayResponse {
|
|
if model == nil {
|
|
return nil
|
|
}
|
|
|
|
var game *contract.GameResponse
|
|
if model.Game != nil {
|
|
game = GameModelToResponse(model.Game)
|
|
}
|
|
|
|
var customer *contract.CustomerResponse
|
|
if model.Customer != nil {
|
|
customer = CustomerModelToResponse(model.Customer)
|
|
}
|
|
|
|
var prize *contract.GamePrizeResponse
|
|
if model.Prize != nil {
|
|
prize = GamePrizeModelToResponse(model.Prize)
|
|
}
|
|
|
|
return &contract.GamePlayResponse{
|
|
ID: model.ID,
|
|
GameID: model.GameID,
|
|
CustomerID: model.CustomerID,
|
|
PrizeID: model.PrizeID,
|
|
CoinsUsed: model.CoinsUsed,
|
|
RandomSeed: model.RandomSeed,
|
|
CreatedAt: model.CreatedAt,
|
|
Game: game,
|
|
Customer: customer,
|
|
Prize: prize,
|
|
}
|
|
}
|
|
|
|
func PlayGameModelToResponse(model *models.PlayGameResponse) *contract.PlayGameResponse {
|
|
if model == nil {
|
|
return nil
|
|
}
|
|
|
|
var gamePlay *contract.GamePlayResponse
|
|
if &model.GamePlay != nil {
|
|
gamePlay = GamePlayModelToResponse(&model.GamePlay)
|
|
}
|
|
|
|
var prizeWon *contract.GamePrizeResponse
|
|
if model.PrizeWon != nil {
|
|
prizeWon = GamePrizeModelToResponse(model.PrizeWon)
|
|
}
|
|
|
|
var gamePlayValue contract.GamePlayResponse
|
|
if gamePlay != nil {
|
|
gamePlayValue = *gamePlay
|
|
}
|
|
|
|
return &contract.PlayGameResponse{
|
|
GamePlay: gamePlayValue,
|
|
PrizeWon: prizeWon,
|
|
CoinsRemaining: model.CoinsRemaining,
|
|
}
|
|
}
|
|
|
|
func PaginatedGamePlaysResponseToContract(model *models.PaginatedResponse[models.GamePlayResponse]) *contract.PaginatedGamePlaysResponse {
|
|
responses := make([]contract.GamePlayResponse, len(model.Data))
|
|
for i, item := range model.Data {
|
|
responses[i] = *GamePlayModelToResponse(&item)
|
|
}
|
|
|
|
return &contract.PaginatedGamePlaysResponse{
|
|
Data: responses,
|
|
TotalCount: int(model.Pagination.Total),
|
|
Page: model.Pagination.Page,
|
|
Limit: model.Pagination.Limit,
|
|
TotalPages: model.Pagination.TotalPages,
|
|
}
|
|
}
|
|
|
|
// Omset Tracker Transformers
|
|
func CreateOmsetTrackerRequestToModel(req *contract.CreateOmsetTrackerRequest) *models.CreateOmsetTrackerRequest {
|
|
return &models.CreateOmsetTrackerRequest{
|
|
PeriodType: req.PeriodType,
|
|
PeriodStart: req.PeriodStart,
|
|
PeriodEnd: req.PeriodEnd,
|
|
Total: req.Total,
|
|
GameID: req.GameID,
|
|
}
|
|
}
|
|
|
|
func UpdateOmsetTrackerRequestToModel(req *contract.UpdateOmsetTrackerRequest) *models.UpdateOmsetTrackerRequest {
|
|
return &models.UpdateOmsetTrackerRequest{
|
|
PeriodType: req.PeriodType,
|
|
PeriodStart: req.PeriodStart,
|
|
PeriodEnd: req.PeriodEnd,
|
|
Total: req.Total,
|
|
GameID: req.GameID,
|
|
}
|
|
}
|
|
|
|
func ListOmsetTrackerRequestToModel(req *contract.ListOmsetTrackerRequest) *models.ListOmsetTrackerQuery {
|
|
return &models.ListOmsetTrackerQuery{
|
|
Page: req.Page,
|
|
Limit: req.Limit,
|
|
Search: req.Search,
|
|
PeriodType: req.PeriodType,
|
|
GameID: req.GameID,
|
|
From: req.From,
|
|
To: req.To,
|
|
SortBy: req.SortBy,
|
|
SortOrder: req.SortOrder,
|
|
}
|
|
}
|
|
|
|
func OmsetTrackerModelToResponse(model *models.OmsetTrackerResponse) *contract.OmsetTrackerResponse {
|
|
if model == nil {
|
|
return nil
|
|
}
|
|
|
|
var game *contract.GameResponse
|
|
if model.Game != nil {
|
|
game = GameModelToResponse(model.Game)
|
|
}
|
|
|
|
return &contract.OmsetTrackerResponse{
|
|
ID: model.ID,
|
|
PeriodType: model.PeriodType,
|
|
PeriodStart: model.PeriodStart,
|
|
PeriodEnd: model.PeriodEnd,
|
|
Total: model.Total,
|
|
GameID: model.GameID,
|
|
Game: game,
|
|
CreatedAt: model.CreatedAt,
|
|
UpdatedAt: model.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
func PaginatedOmsetTrackerResponseToContract(model *models.PaginatedResponse[models.OmsetTrackerResponse]) *contract.PaginatedOmsetTrackerResponse {
|
|
responses := make([]contract.OmsetTrackerResponse, len(model.Data))
|
|
for i, item := range model.Data {
|
|
responses[i] = *OmsetTrackerModelToResponse(&item)
|
|
}
|
|
|
|
return &contract.PaginatedOmsetTrackerResponse{
|
|
Data: responses,
|
|
TotalCount: int(model.Pagination.Total),
|
|
Page: model.Pagination.Page,
|
|
Limit: model.Pagination.Limit,
|
|
TotalPages: model.Pagination.TotalPages,
|
|
}
|
|
}
|