customer/internal/utils/transfer/tariff.go
2023-09-14 10:07:28 +00:00

44 lines
1.2 KiB
Go

package transfer
import (
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/proto/broker"
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/proto/discount"
)
func TariffsToProductInformations(tarrifs []models.Tariff) []*discount.ProductInformation {
productInformations := make([]*discount.ProductInformation, len(tarrifs))
for index, tariff := range tarrifs {
productInformations[index] = TariffToProductInformation(tariff)
}
return productInformations
}
func TariffToProductInformation(tarrif models.Tariff) *discount.ProductInformation {
return &discount.ProductInformation{
ID: tarrif.ID,
Price: tarrif.Price,
}
}
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),
}
}