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

This reverts commit 4e24f9bbb0.
This commit is contained in:
efrilm
2026-09-30 15:31:11 +07:00
parent 5e28b05770
commit c6062c4bb9
195 changed files with 20058 additions and 2177 deletions
+4 -4
View File
@@ -71,7 +71,7 @@ func ToCampaignEntity(request *contract.CreateCampaignRequest) *entities.Campaig
return &entities.Campaign{
Name: request.Name,
Description: request.Description,
Type: entities.CampaignType(request.Type),
Type: entities.NormalizeCampaignType(request.Type),
StartDate: request.StartDate,
EndDate: request.EndDate,
IsActive: request.IsActive,
@@ -91,7 +91,7 @@ func ToCampaignEntityFromUpdate(request *contract.UpdateCampaignRequest) *entiti
ID: request.ID,
Name: request.Name,
Description: request.Description,
Type: entities.CampaignType(request.Type),
Type: entities.NormalizeCampaignType(request.Type),
StartDate: request.StartDate,
EndDate: request.EndDate,
IsActive: request.IsActive,
@@ -118,7 +118,7 @@ func ToCampaignRuleEntity(request *contract.CampaignRuleStruct, campaignID uuid.
CampaignID: campaignID,
RuleType: entities.RuleType(request.RuleType),
ConditionValue: request.ConditionValue,
RewardType: entities.CampaignRewardType(request.RewardType),
RewardType: entities.NormalizeCampaignRewardType(request.RewardType),
RewardValue: request.RewardValue,
RewardSubtype: rewardSubtype,
RewardRefID: request.RewardRefID,
@@ -142,7 +142,7 @@ func ToCampaignRuleEntityFromUpdate(request *contract.CampaignRuleStruct, campai
CampaignID: campaignID,
RuleType: entities.RuleType(request.RuleType),
ConditionValue: request.ConditionValue,
RewardType: entities.CampaignRewardType(request.RewardType),
RewardType: entities.NormalizeCampaignRewardType(request.RewardType),
RewardValue: request.RewardValue,
RewardSubtype: rewardSubtype,
RewardRefID: request.RewardRefID,
@@ -1,46 +0,0 @@
package mappers
import (
"apskel-pos-be/internal/entities"
"apskel-pos-be/internal/models"
)
// ToCustomerPointsResponse converts a customer points entity to a customer points response
func ToCustomerPointsResponse(customerPoints *entities.CustomerPoints) *models.CustomerPointsResponse {
if customerPoints == nil {
return nil
}
return &models.CustomerPointsResponse{
ID: customerPoints.ID,
CustomerID: customerPoints.CustomerID,
Balance: customerPoints.Balance,
Customer: ToCustomerResponse(&customerPoints.Customer),
CreatedAt: customerPoints.CreatedAt,
UpdatedAt: customerPoints.UpdatedAt,
}
}
// ToCustomerPointsResponses converts a slice of customer points entities to customer points responses
func ToCustomerPointsResponses(customerPoints []entities.CustomerPoints) []models.CustomerPointsResponse {
responses := make([]models.CustomerPointsResponse, len(customerPoints))
for i, cp := range customerPoints {
responses[i] = *ToCustomerPointsResponse(&cp)
}
return responses
}
// ToCustomerPointsEntity converts a create customer points request to a customer points entity
func ToCustomerPointsEntity(req *models.CreateCustomerPointsRequest) *entities.CustomerPoints {
return &entities.CustomerPoints{
CustomerID: req.CustomerID,
Balance: req.Balance,
}
}
// UpdateCustomerPointsEntity updates a customer points entity with update request data
func UpdateCustomerPointsEntity(customerPoints *entities.CustomerPoints, req *models.UpdateCustomerPointsRequest) {
if req.Balance >= 0 {
customerPoints.Balance = req.Balance
}
}
@@ -1,48 +0,0 @@
package mappers
import (
"apskel-pos-be/internal/entities"
"apskel-pos-be/internal/models"
)
// ToCustomerTokensResponse converts a customer tokens entity to a customer tokens response
func ToCustomerTokensResponse(customerTokens *entities.CustomerTokens) *models.CustomerTokensResponse {
if customerTokens == nil {
return nil
}
return &models.CustomerTokensResponse{
ID: customerTokens.ID,
CustomerID: customerTokens.CustomerID,
TokenType: string(customerTokens.TokenType),
Balance: customerTokens.Balance,
Customer: ToCustomerResponse(&customerTokens.Customer),
CreatedAt: customerTokens.CreatedAt,
UpdatedAt: customerTokens.UpdatedAt,
}
}
// ToCustomerTokensResponses converts a slice of customer tokens entities to customer tokens responses
func ToCustomerTokensResponses(customerTokens []entities.CustomerTokens) []models.CustomerTokensResponse {
responses := make([]models.CustomerTokensResponse, len(customerTokens))
for i, ct := range customerTokens {
responses[i] = *ToCustomerTokensResponse(&ct)
}
return responses
}
// ToCustomerTokensEntity converts a create customer tokens request to a customer tokens entity
func ToCustomerTokensEntity(req *models.CreateCustomerTokensRequest) *entities.CustomerTokens {
return &entities.CustomerTokens{
CustomerID: req.CustomerID,
TokenType: entities.TokenType(req.TokenType),
Balance: req.Balance,
}
}
// UpdateCustomerTokensEntity updates a customer tokens entity with update request data
func UpdateCustomerTokensEntity(customerTokens *entities.CustomerTokens, req *models.UpdateCustomerTokensRequest) {
if req.Balance >= 0 {
customerTokens.Balance = req.Balance
}
}
+2 -2
View File
@@ -16,7 +16,7 @@ func ToGamePlayResponse(gamePlay *entities.GamePlay) *models.GamePlayResponse {
GameID: gamePlay.GameID,
CustomerID: gamePlay.CustomerID,
PrizeID: gamePlay.PrizeID,
TokenUsed: gamePlay.TokenUsed,
CoinsUsed: gamePlay.CoinsUsed,
RandomSeed: gamePlay.RandomSeed,
CreatedAt: gamePlay.CreatedAt,
Game: ToGameResponse(&gamePlay.Game),
@@ -48,7 +48,7 @@ func ToGamePlayEntity(req *models.CreateGamePlayRequest) *entities.GamePlay {
return &entities.GamePlay{
GameID: req.GameID,
CustomerID: req.CustomerID,
TokenUsed: req.TokenUsed,
CoinsUsed: req.CoinsUsed,
RandomSeed: req.RandomSeed,
}
}
+2
View File
@@ -189,6 +189,8 @@ func PaymentEntityToResponse(payment *entities.Payment) *models.PaymentResponse
SplitType: (*string)(payment.SplitType),
SplitDescription: payment.SplitDescription,
RefundAmount: payment.RefundAmount,
PointsUsed: payment.PointsUsed,
PointValue: payment.PointValue,
RefundReason: payment.RefundReason,
RefundedAt: payment.RefundedAt,
RefundedBy: payment.RefundedBy,
@@ -134,6 +134,7 @@ func ListPaymentMethodsContractToModel(req *contract.ListPaymentMethodsRequest)
return &models.ListPaymentMethodsRequest{
OrganizationID: req.OrganizationID,
OutletID: req.OutletID,
Type: paymentMethodType,
IsActive: req.IsActive,
Search: req.Search,
+4 -2
View File
@@ -38,7 +38,8 @@ func SpinGameResponseDataModelToContract(data *models.SpinGameResponseData) *con
return &contract.SpinGameResponseData{
GamePlay: GamePlayResponseModelToContract(&data.GamePlay),
PrizeWon: CustomerGamePrizeResponseModelToContract(data.PrizeWon),
TokensRemaining: data.TokensRemaining,
CoinsRemaining: data.CoinsRemaining,
TokensRemaining: data.CoinsRemaining,
}
}
@@ -53,7 +54,8 @@ func GamePlayResponseModelToContract(resp *models.GamePlayResponse) contract.Gam
GameID: resp.GameID,
CustomerID: resp.CustomerID,
PrizeID: resp.PrizeID,
TokenUsed: resp.TokenUsed,
CoinsUsed: resp.CoinsUsed,
TokenUsed: resp.CoinsUsed,
RandomSeed: resp.RandomSeed,
CreatedAt: resp.CreatedAt,
Game: nil, // Optional field - can be populated separately if needed