customer/internal/utils/transfer/tariff.go
Pasha 34a88a3a70
Some checks failed
Lint / Lint (push) Failing after 1m2s
rename go.mod
2024-11-18 21:44:09 +00:00

53 lines
1.4 KiB
Go

package transfer
import (
"gitea.pena/PenaSide/customer/internal/models"
"gitea.pena/PenaSide/customer/internal/proto/broker"
"gitea.pena/PenaSide/customer/internal/proto/discount"
)
func TariffsToProductInformations(tarrifs []models.Tariff) []*discount.ProductInformation {
productInformations := []*discount.ProductInformation{}
for _, tariff := range tarrifs {
for _, privilege := range tariff.Privileges {
productInformations = append(productInformations, PrivilegeToProductInformation(privilege))
}
if tariff.Price != 0 {
price := tariff.Price
productInformations[len(productInformations) - 1].Usage = &price
}
}
return productInformations
}
func PrivilegeToProductInformation(privilege models.Privilege) *discount.ProductInformation {
return &discount.ProductInformation{
ID: privilege.PrivilegeID,
Price: privilege.Price * privilege.Amount,
Group: &privilege.ServiceKey,
Term: &privilege.Amount,
}
}
func TariffMessageProtoToTariffModel(tariff *broker.TariffMessage) *models.Tariff {
if tariff == nil {
return &models.Tariff{}
}
return &models.Tariff{Privileges: PrivilegeArrayProtoToModel(tariff.Privileges)}
}
func TariffModelToProtoMessage(userID string, tariffModel *models.Tariff) *broker.TariffMessage {
if tariffModel == nil {
return &broker.TariffMessage{}
}
return &broker.TariffMessage{
UserID: userID,
Privileges: PrivilegeArrayModelToProto(tariffModel.Privileges),
}
}