-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from hmrc/DAC6-3293
DAC6-3293 | First Draft PR - Controller, view, model etc
- Loading branch information
Showing
12 changed files
with
548 additions
and
19 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
...ntrollers/changeFinancialInstitution/ChangeRegisteredFinancialInstitutionController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* 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.changeFinancialInstitution | ||
|
||
import com.google.inject.Inject | ||
import controllers.actions._ | ||
import models.UserAnswers | ||
import models.requests.DataRequest | ||
import pages.changeFinancialInstitution.ChangeFiDetailsInProgressId | ||
import play.api.Logging | ||
import play.api.i18n.{I18nSupport, MessagesApi} | ||
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents, Result} | ||
import services.{FinancialInstitutionUpdateService, FinancialInstitutionsService} | ||
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController | ||
import utils.ContactHelper | ||
import viewmodels.changeFinancialInstitution.ChangeRegisteredFinancialInstitutionViewModel.getChangeRegisteredFinancialInstitutionSummaries | ||
import viewmodels.govuk.summarylist._ | ||
import views.html.ThereIsAProblemView | ||
import views.html.changeFinancialInstitution.ChangeRegisteredFinancialInstitutionView | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class ChangeRegisteredFinancialInstitutionController @Inject() ( | ||
override val messagesApi: MessagesApi, | ||
identify: IdentifierAction, | ||
getData: DataRetrievalAction, | ||
requireData: DataRequiredAction, | ||
financialInstitutionsService: FinancialInstitutionsService, | ||
financialInstitutionUpdateService: FinancialInstitutionUpdateService, | ||
val controllerComponents: MessagesControllerComponents, | ||
view: ChangeRegisteredFinancialInstitutionView, | ||
errorView: ThereIsAProblemView | ||
)(implicit ec: ExecutionContext) | ||
extends FrontendBaseController | ||
with ContactHelper | ||
with I18nSupport | ||
with Logging { | ||
|
||
def onPageLoad(fiid: String): Action[AnyContent] = (identify andThen getData andThen requireData).async { | ||
implicit request => | ||
val userAnswers = request.userAnswers | ||
financialInstitutionsService | ||
.getFinancialInstitution(request.fatcaId, fiid) | ||
.flatMap { | ||
case Some(fiDetails) => | ||
userAnswers.get(ChangeFiDetailsInProgressId) match { | ||
case Some(id) if id.equalsIgnoreCase(fiid) => | ||
val hasChanges = financialInstitutionUpdateService.registeredFiDetailsHasChanged(userAnswers, fiDetails) | ||
Future.successful(createPage(fiid, userAnswers, hasChanges)) | ||
case _ => | ||
financialInstitutionUpdateService | ||
.populateAndSaveRegisteredFiDetails(userAnswers, fiDetails) | ||
.map(createPage(fiid, _, hasChanges = false)) | ||
.recoverWith { | ||
exception => | ||
logger.error(s"Failed to populate and save FI details to user answers for subscription Id: [${request.fatcaId}] and FI Id [$fiid]", | ||
exception | ||
) | ||
Future.successful(InternalServerError(errorView())) | ||
} | ||
} | ||
case _ => | ||
logger.error(s"Failed to retrieve FI details from backend for subscription Id: [${request.fatcaId}] and FI Id [$fiid]") | ||
Future.successful(InternalServerError(errorView())) | ||
} | ||
.recoverWith { | ||
exception => | ||
logger.error(s"Failed to get FI details for subscription Id: [${request.fatcaId}] and FI Id [$fiid]", exception) | ||
Future.successful(InternalServerError(errorView())) | ||
} | ||
} | ||
|
||
def confirmAndAdd(): Action[AnyContent] = (identify andThen getData andThen requireData).async { | ||
implicit request => | ||
financialInstitutionUpdateService | ||
.clearUserAnswers(request.userAnswers) | ||
.map( | ||
_ => // TODO: User answers to be submitted and redirected to /details-updated as part of DAC6-3186 | ||
Redirect(controllers.routes.JourneyRecoveryController.onPageLoad()) | ||
) | ||
.recoverWith { | ||
exception => | ||
logger.error(s"Failed to clear user answers for subscription Id: [${request.fatcaId}]", exception) | ||
Future.successful(InternalServerError(errorView())) | ||
} | ||
} | ||
|
||
private def createPage(fiId: String, updatedUserAnswers: UserAnswers, hasChanges: Boolean)(implicit request: DataRequest[AnyContent]): Result = { | ||
val fiName = getFinancialInstitutionName(updatedUserAnswers) | ||
val financialInstitutionSummary = SummaryListViewModel(getChangeRegisteredFinancialInstitutionSummaries(fiId, updatedUserAnswers)) | ||
Ok(view(hasChanges, fiName, financialInstitutionSummary)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...viewmodels/changeFinancialInstitution/ChangeRegisteredFinancialInstitutionViewModel.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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 viewmodels.changeFinancialInstitution | ||
|
||
import models.{ChangeAnswers, UserAnswers} | ||
import play.api.i18n.Messages | ||
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow | ||
import viewmodels.common._ | ||
|
||
object ChangeRegisteredFinancialInstitutionViewModel { | ||
|
||
def getChangeRegisteredFinancialInstitutionSummaries(fiId: String, userAnswers: UserAnswers)(implicit messages: Messages): Seq[SummaryListRow] = | ||
Seq( | ||
Option(FinancialInstitutionIdSummary.row(fiId)), | ||
IsThisYourBusinessNameSummary.row(userAnswers, ChangeAnswers), | ||
getGIINRows(userAnswers, ChangeAnswers), | ||
getAddressRow(userAnswers, ChangeAnswers) | ||
).flatten | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
app/views/changeFinancialInstitution/ChangeRegisteredFinancialInstitutionView.scala.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
@* | ||
* 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. | ||
*@ | ||
|
||
@import components._ | ||
|
||
@this( | ||
layout: templates.Layout, | ||
govukSummaryList: GovukSummaryList, | ||
heading: Heading, | ||
para: Paragraph, | ||
formHelper: FormWithCSRF, | ||
govukButton: GovukButton, | ||
link: components.Link, | ||
) | ||
|
||
@(hasChanges: Boolean, fiName: String, financialInstitutionList: SummaryList)(implicit request: Request[_], messages: Messages) | ||
|
||
@layout(pageTitle = titleNoForm(if (hasChanges) messages("changeYourRegisteredAnswers.title") else messages("changeYourRegisteredAnswers.title"))) { | ||
|
||
@heading(if (hasChanges) messages("changedYourRegisteredAnswers.heading", fiName) else messages("changeYourRegisteredAnswers.heading", fiName)) | ||
|
||
@govukSummaryList(financialInstitutionList) | ||
<p class="govuk-!-margin-bottom-9"></p> | ||
|
||
@if(hasChanges){ | ||
@heading(messages("changeYourAnswers.changed.subheading"), "m") | ||
@para(Html(messages("changeYourAnswers.changed.p2"))) | ||
|
||
@formHelper(action = controllers.changeFinancialInstitution.routes.ChangeRegisteredFinancialInstitutionController.confirmAndAdd()) { | ||
@govukButton( | ||
ButtonViewModel(messages("changeYourAnswers.submit.button")).withAttribute("id" -> "submit").preventingDoubleClick()) | ||
} | ||
} | ||
|
||
<p class="govuk-body govuk-!-margin-bottom-2">@link(controllers.routes.YourFinancialInstitutionsController.onPageLoad().url, "changeYourAnswers.p1")</p> | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.