47 lines
1.6 KiB
Go
47 lines
1.6 KiB
Go
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
|
|
}
|
|
}
|