From ca94e0bc7aa713d393a584ca46404c5af2a17510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Honor=C3=A9?= Date: Mon, 22 Jan 2024 17:51:20 +0000 Subject: [PATCH] refactoring --- .../Newspaper2024Migration/Amendment.scala | 21 ++----------------- .../Newspaper2024Migration/Estimation.scala | 18 ++-------------- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/lambda/src/main/scala/pricemigrationengine/migrations/Newspaper2024Migration/Amendment.scala b/lambda/src/main/scala/pricemigrationengine/migrations/Newspaper2024Migration/Amendment.scala index bc7b0dd3c..41f4fbc59 100644 --- a/lambda/src/main/scala/pricemigrationengine/migrations/Newspaper2024Migration/Amendment.scala +++ b/lambda/src/main/scala/pricemigrationengine/migrations/Newspaper2024Migration/Amendment.scala @@ -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( diff --git a/lambda/src/main/scala/pricemigrationengine/migrations/Newspaper2024Migration/Estimation.scala b/lambda/src/main/scala/pricemigrationengine/migrations/Newspaper2024Migration/Estimation.scala index e04bf30c4..ad3b29676 100644 --- a/lambda/src/main/scala/pricemigrationengine/migrations/Newspaper2024Migration/Estimation.scala +++ b/lambda/src/main/scala/pricemigrationengine/migrations/Newspaper2024Migration/Estimation.scala @@ -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,