Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shtukas committed Jan 22, 2024
1 parent 53a830e commit ca94e0b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,9 @@ object Amendment {
subscription: ZuoraSubscription,
effectiveDate: LocalDate,
): Either[AmendmentDataFailure, ZuoraSubscriptionUpdate] = {

def transform1[T](option: Option[T]): Either[AmendmentDataFailure, T] = {
option match {
case None => Left(AmendmentDataFailure("error"))
case Some(ratePlanCharge) => Right(ratePlanCharge)
}
}

def transform2[T](data: Either[String, T]): Either[AmendmentDataFailure, T] = {
data match {
case Left(string) => Left(AmendmentDataFailure(string))
case Right(t) => Right(t)
}
}

for {
data2024 <- transform2[SubscriptionData2024](
Estimation.subscriptionToSubscriptionData2024(subscription)
)
chargeDistribution <- transform1[ChargeDistribution2024](subscriptionToNewChargeDistribution2024(subscription))
data2024 <- Estimation.subscriptionToSubscriptionData2024(subscription).left.map(AmendmentDataFailure)
chargeDistribution <- subscriptionToNewChargeDistribution2024(subscription).toRight(AmendmentDataFailure("error"))
} yield ZuoraSubscriptionUpdate(
add = List(
AddZuoraRatePlan(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,10 @@ object Estimation {

// PriceData(currency: Currency, oldPrice: BigDecimal, newPrice: BigDecimal, billingPeriod: String)

def transform1[T](option: Option[T]): Either[AmendmentDataFailure, T] = {
option match {
case None => Left(AmendmentDataFailure("error"))
case Some(ratePlanCharge) => Right(ratePlanCharge)
}
}

def transform2[T](data: Either[String, T]): Either[AmendmentDataFailure, T] = {
data match {
case Left(string) => Left(AmendmentDataFailure(string))
case Right(t) => Right(t)
}
}

for {
data2024 <- transform2[SubscriptionData2024](subscriptionToSubscriptionData2024(subscription))
data2024 <- subscriptionToSubscriptionData2024(subscription).left.map(AmendmentDataFailure)
oldPrice = data2024.currentPrice
newPrice <- transform1[BigDecimal](subscriptionToNewPrice(subscription))
newPrice <- subscriptionToNewPrice(subscription).toRight(AmendmentDataFailure("error"))
} yield PriceData(
data2024.currency,
oldPrice,
Expand Down

0 comments on commit ca94e0b

Please sign in to comment.