Skip to content

Commit

Permalink
Merge pull request #93 from hmrc/DAC6-3209
Browse files Browse the repository at this point in the history
DAC6-3209 | Implement CYA Validation
  • Loading branch information
matthewharris1 authored Sep 3, 2024
2 parents e61bfee + ee2c964 commit 0c1c300
Show file tree
Hide file tree
Showing 12 changed files with 975 additions and 144 deletions.
41 changes: 41 additions & 0 deletions app/controllers/SomeInformationMissingController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package controllers

import controllers.actions._
import javax.inject.Inject
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.SomeInformationMissingView

class SomeInformationMissingController @Inject() (
override val messagesApi: MessagesApi,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
val controllerComponents: MessagesControllerComponents,
view: SomeInformationMissingView
) extends FrontendBaseController
with I18nSupport {

def onPageLoad: Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>
Ok(view())
}

}
1 change: 1 addition & 0 deletions app/models/Name.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ case class Name(firstName: String, lastName: String) {
}

object Name {

implicit val format: OFormat[Name] = Json.format[Name]
}
106 changes: 106 additions & 0 deletions app/utils/CheckYourAnswersValidator.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package utils

import models.UserAnswers
import pages._
import pages.addFinancialInstitution._
import play.api.libs.json.Reads

sealed trait AddFIValidator {
self: CheckYourAnswersValidator =>

private def firstContactPhoneMissingAnswers: Seq[Page] = (userAnswers.get(FirstContactHavePhonePage) match {
case Some(true) => checkPage(FirstContactPhoneNumberPage)
case Some(false) => None
case _ => Some(FirstContactPhoneNumberPage)
}).toSeq

private def secContactPhoneMissingAnswers: Seq[Page] = (userAnswers.get(SecondContactCanWePhonePage) match {
case Some(true) => checkPage(SecondContactPhoneNumberPage)
case Some(false) => None
case _ => Some(SecondContactPhoneNumberPage)
}).toSeq

private def checkFirstContactMissingAnswers: Seq[Page] = Seq(
checkPage(FirstContactNamePage),
checkPage(FirstContactEmailPage)
).flatten ++ firstContactPhoneMissingAnswers

private def checkSecContactDetailsMissingAnswers: Seq[Page] =
userAnswers.get(SecondContactExistsPage) match {
case Some(true) =>
Seq(
checkPage(SecondContactNamePage),
checkPage(SecondContactEmailPage)
).flatten ++ secContactPhoneMissingAnswers
case Some(false) => Seq.empty
case _ => Seq(SecondContactExistsPage)
}

private[utils] def checkContactDetailsMissingAnswers = checkFirstContactMissingAnswers ++ checkSecContactDetailsMissingAnswers

private[utils] def checkAddressMissingAnswers: Seq[Page] = (userAnswers.get(WhereIsFIBasedPage) match {
case Some(true) =>
checkPage(PostcodePage)
.orElse(
any(
checkPage(SelectAddressPage),
checkPage(UkAddressPage)
).map(
_ => PostcodePage
)
)
case Some(false) => checkPage(NonUkAddressPage)
case _ => Some(WhereIsFIBasedPage)
}).toSeq

private def fiUTRMissingAnswers: Seq[Page] = (userAnswers.get(HaveUniqueTaxpayerReferencePage) match {
case Some(true) => checkPage(WhatIsUniqueTaxpayerReferencePage)
case Some(false) => None
case _ => Some(HaveUniqueTaxpayerReferencePage)
}).toSeq

private def fiGIINMissingAnswers: Seq[Page] = (userAnswers.get(HaveGIINPage) match {
case Some(true) => checkPage(WhatIsGIINPage)
case Some(false) => None
case _ => Some(HaveGIINPage)
}).toSeq

private[utils] def checkNameUTRGIINMissingAnswers: Seq[Page] = Seq(
checkPage(NameOfFinancialInstitutionPage)
).flatten ++ fiUTRMissingAnswers ++ fiGIINMissingAnswers

}

class CheckYourAnswersValidator(val userAnswers: UserAnswers) extends AddFIValidator {

private[utils] def checkPage[A](page: QuestionPage[A])(implicit rds: Reads[A]): Option[Page] =
userAnswers.get(page) match {
case None => Some(page)
case _ => None
}

private[utils] def any(checkPages: Option[Page]*): Option[Page] = checkPages.find(_.isEmpty).getOrElse(checkPages.last)

def validate: Seq[Page] = checkNameUTRGIINMissingAnswers ++ checkAddressMissingAnswers ++ checkContactDetailsMissingAnswers

}

object CheckYourAnswersValidator {
def apply(userAnswers: UserAnswers): CheckYourAnswersValidator = new CheckYourAnswersValidator(userAnswers)
}
29 changes: 29 additions & 0 deletions app/views/SomeInformationMissingView.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@*
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*@

@this(
layout: templates.Layout,
govukButton: GovukButton
)

@()(implicit request: Request[_], messages: Messages)

@layout(pageTitle = titleNoForm(messages("someInformationMissing.title"))) {

<h1 class="govuk-heading-xl">@messages("someInformationMissing.heading")</h1>

<p class="govuk-body">@messages("someInformationMissing.p1")</p>
}
Loading

0 comments on commit 0c1c300

Please sign in to comment.