From f2a79683ac50c9186b2482f3af28c2eff7a7c712 Mon Sep 17 00:00:00 2001 From: ShivangiShah42 <177633426+ShivangiShah42@users.noreply.github.com> Date: Tue, 24 Dec 2024 14:30:34 +0000 Subject: [PATCH] DLS-11277 : Changed email to EmailAddress --- .../cbcrfrontend/controllers/SubmissionController.scala | 2 +- .../cbcrfrontend/controllers/SubscriptionController.scala | 4 ++-- app/uk/gov/hmrc/cbcrfrontend/model/ETMPGetResponse.scala | 2 +- app/uk/gov/hmrc/cbcrfrontend/model/SubmitterInfo.scala | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/uk/gov/hmrc/cbcrfrontend/controllers/SubmissionController.scala b/app/uk/gov/hmrc/cbcrfrontend/controllers/SubmissionController.scala index 829c315a..b8084ac6 100644 --- a/app/uk/gov/hmrc/cbcrfrontend/controllers/SubmissionController.scala +++ b/app/uk/gov/hmrc/cbcrfrontend/controllers/SubmissionController.scala @@ -361,7 +361,7 @@ class SubmissionController @Inject() ( form <- cache.readOption[SubmitterInfo].map { osi => (osi.map(_.fullName), osi.map(_.contactPhone), osi.map(_.email)) .mapN { (name, phone, email) => - submitterInfoForm.bind(Map("fullName" -> name, "contactPhone" -> phone, "email" -> email)) + submitterInfoForm.bind(Map("fullName" -> name, "contactPhone" -> phone, "email" -> email.value)) } .getOrElse(submitterInfoForm) } diff --git a/app/uk/gov/hmrc/cbcrfrontend/controllers/SubscriptionController.scala b/app/uk/gov/hmrc/cbcrfrontend/controllers/SubscriptionController.scala index 098be42f..eb67aa37 100644 --- a/app/uk/gov/hmrc/cbcrfrontend/controllers/SubscriptionController.scala +++ b/app/uk/gov/hmrc/cbcrfrontend/controllers/SubscriptionController.scala @@ -125,7 +125,7 @@ class SubscriptionController @Inject() ( private def makeSubEmail(subscriberContact: SubscriberContact, cbcId: CBCId): Email = Email( - List(subscriberContact.email), + List(subscriberContact.email.value), "cbcr_subscription", Map("f_name" -> subscriberContact.firstName, "s_name" -> subscriberContact.lastName, "cbcrId" -> cbcId.value) ) @@ -157,7 +157,7 @@ class SubscriptionController @Inject() ( Map( "firstName" -> subData.names.name1, "lastName" -> subData.names.name2, - "email" -> subData.contact.email, + "email" -> subData.contact.email.value, "phoneNumber" -> subData.contact.phoneNumber ) ) diff --git a/app/uk/gov/hmrc/cbcrfrontend/model/ETMPGetResponse.scala b/app/uk/gov/hmrc/cbcrfrontend/model/ETMPGetResponse.scala index 20769a6b..c8ac6bc3 100644 --- a/app/uk/gov/hmrc/cbcrfrontend/model/ETMPGetResponse.scala +++ b/app/uk/gov/hmrc/cbcrfrontend/model/ETMPGetResponse.scala @@ -52,7 +52,7 @@ object PhoneNumber { } } -case class ContactDetails(email: String, phoneNumber: String) +case class ContactDetails(email: EmailAddress, phoneNumber: String) object ContactDetails { implicit val emailFormat: Format[EmailAddress] = diff --git a/app/uk/gov/hmrc/cbcrfrontend/model/SubmitterInfo.scala b/app/uk/gov/hmrc/cbcrfrontend/model/SubmitterInfo.scala index 1980033b..3ddbcc44 100644 --- a/app/uk/gov/hmrc/cbcrfrontend/model/SubmitterInfo.scala +++ b/app/uk/gov/hmrc/cbcrfrontend/model/SubmitterInfo.scala @@ -18,12 +18,14 @@ package uk.gov.hmrc.cbcrfrontend.model import play.api.libs.json._ import uk.gov.hmrc.auth.core.AffinityGroup +import uk.gov.hmrc.cbcrfrontend.emailaddress.EmailAddress +import uk.gov.hmrc.cbcrfrontend.emailaddress.PlayJsonFormats._ case class SubmitterInfo( fullName: String, agencyBusinessName: Option[AgencyBusinessName], contactPhone: String, - email: String, + email: EmailAddress, affinityGroup: Option[AffinityGroup] ) @@ -35,7 +37,7 @@ object SubmitterInfo { fullName <- m.get("fullName").flatMap(_.asOpt[String]) abn <- m.get("agencyBusinessName").map(_.asOpt[String]) cp <- m.get("contactPhone").flatMap(_.asOpt[String]) - email <- m.get("email").flatMap(_.asOpt[String]) + email <- m.get("email").flatMap(_.asOpt[EmailAddress]) ag <- m.get("affinityGroup").map(_.asOpt[AffinityGroup]) } yield JsSuccess(SubmitterInfo(fullName, abn.map(AgencyBusinessName(_)), cp, email, ag)) result.getOrElse(JsError(s"Unable to serialise $json as a SubmitterInfo"))