customer/internal/utils/transfer/tariff.go

48 lines
1.4 KiB
Go
Raw Normal View History

2023-05-30 11:33:57 +00:00
package transfer
import (
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
2023-07-06 18:50:46 +00:00
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/proto/broker"
2023-05-30 11:33:57 +00:00
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/proto/discount"
)
func TariffsToProductInformations(tarrifs []models.Tariff) []*discount.ProductInformation {
2023-09-19 21:43:08 +00:00
productInformations := []*discount.ProductInformation{}
2023-05-30 11:33:57 +00:00
2023-09-19 21:43:08 +00:00
for _, tariff := range tarrifs {
for _, privilege := range tariff.Privileges {
productInformations = append(productInformations, PrivilegeToProductInformation(privilege))
2023-09-19 21:43:08 +00:00
}
2023-05-30 11:33:57 +00:00
}
return productInformations
}
2023-09-19 21:43:08 +00:00
func PrivilegeToProductInformation(privilege models.Privilege) *discount.ProductInformation {
2023-05-30 11:33:57 +00:00
return &discount.ProductInformation{
2023-09-28 20:53:01 +00:00
ID: privilege.PrivilegeID,
2023-09-20 20:04:15 +00:00
Price: privilege.Price * privilege.Amount,
Group: &privilege.ServiceKey,
2023-10-02 21:27:56 +00:00
Term: &privilege.Amount,
2023-07-06 18:50:46 +00:00
}
}
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),
2023-05-30 11:33:57 +00:00
}
}