Add Tiers and Game Prize
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package mappers
|
||||
|
||||
import (
|
||||
"apskel-pos-be/internal/entities"
|
||||
"apskel-pos-be/internal/models"
|
||||
)
|
||||
|
||||
// ToGamePrizeResponse converts a game prize entity to a game prize response
|
||||
func ToGamePrizeResponse(gamePrize *entities.GamePrize) *models.GamePrizeResponse {
|
||||
if gamePrize == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &models.GamePrizeResponse{
|
||||
ID: gamePrize.ID,
|
||||
GameID: gamePrize.GameID,
|
||||
Name: gamePrize.Name,
|
||||
Weight: gamePrize.Weight,
|
||||
Stock: gamePrize.Stock,
|
||||
MaxStock: gamePrize.MaxStock,
|
||||
Threshold: gamePrize.Threshold,
|
||||
FallbackPrizeID: gamePrize.FallbackPrizeID,
|
||||
Metadata: gamePrize.Metadata,
|
||||
Game: ToGameResponse(&gamePrize.Game),
|
||||
FallbackPrize: ToGamePrizeResponse(gamePrize.FallbackPrize),
|
||||
CreatedAt: gamePrize.CreatedAt,
|
||||
UpdatedAt: gamePrize.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// ToGamePrizeResponses converts a slice of game prize entities to game prize responses
|
||||
func ToGamePrizeResponses(gamePrizes []entities.GamePrize) []models.GamePrizeResponse {
|
||||
responses := make([]models.GamePrizeResponse, len(gamePrizes))
|
||||
for i, gp := range gamePrizes {
|
||||
responses[i] = *ToGamePrizeResponse(&gp)
|
||||
}
|
||||
return responses
|
||||
}
|
||||
|
||||
// ToGamePrizeEntity converts a create game prize request to a game prize entity
|
||||
func ToGamePrizeEntity(req *models.CreateGamePrizeRequest) *entities.GamePrize {
|
||||
return &entities.GamePrize{
|
||||
GameID: req.GameID,
|
||||
Name: req.Name,
|
||||
Weight: req.Weight,
|
||||
Stock: req.Stock,
|
||||
MaxStock: req.MaxStock,
|
||||
Threshold: req.Threshold,
|
||||
FallbackPrizeID: req.FallbackPrizeID,
|
||||
Metadata: req.Metadata,
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateGamePrizeEntity updates a game prize entity with update request data
|
||||
func UpdateGamePrizeEntity(gamePrize *entities.GamePrize, req *models.UpdateGamePrizeRequest) {
|
||||
if req.Name != nil {
|
||||
gamePrize.Name = *req.Name
|
||||
}
|
||||
if req.Weight != nil {
|
||||
gamePrize.Weight = *req.Weight
|
||||
}
|
||||
if req.Stock != nil {
|
||||
gamePrize.Stock = *req.Stock
|
||||
}
|
||||
if req.MaxStock != nil {
|
||||
gamePrize.MaxStock = req.MaxStock
|
||||
}
|
||||
if req.Threshold != nil {
|
||||
gamePrize.Threshold = req.Threshold
|
||||
}
|
||||
if req.FallbackPrizeID != nil {
|
||||
gamePrize.FallbackPrizeID = req.FallbackPrizeID
|
||||
}
|
||||
if req.Metadata != nil {
|
||||
gamePrize.Metadata = req.Metadata
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user