-
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.
VEIOSS-379 Build View Submitted Returns Pages for Multiple IOSS Accou…
…nts (#87) * VEIOSS-379 Build View Submitted Returns Pages for Multiple IOSS Accounts * Complete return-registration-selection page * Add /view-returns-multiple-reg * Fix test * Remove stub * Clean * Skip selection when only one previous registration * Fix test * Add id to href links * Clean * Clean * Add index * Clean * Add submitted-returns-history id * Add ReturnRegistrationSelectionControllerSpec * Add ViewReturnsMultipleRegControllerSpec * Add SelectedPreviousRegistrationRepositorySpec * Add ReturnRegistrationSelectionFormProviderSpec * Rename previousRegistration.submittedReturnsHistory viewReturnsMultipleReg * Add previousIossNumber to makePayment * Add onPageLoadForIossNumber and makePaymentForIossNumber * Remove println in test * Factor onPageLoad and onPageLoadForIossNumber tests * Add onPageLoadForIossNumber tests * Add test * Add PaymentController tests * Clean
- Loading branch information
Showing
31 changed files
with
2,623 additions
and
688 deletions.
There are no files selected for viewing
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
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
81 changes: 81 additions & 0 deletions
81
app/controllers/previousReturns/ReturnRegistrationSelectionController.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,81 @@ | ||
/* | ||
* 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.previousReturns | ||
|
||
import controllers.actions._ | ||
import forms.ReturnRegistrationSelectionFormProvider | ||
import logging.Logging | ||
import pages.Waypoints | ||
import play.api.data.Form | ||
import play.api.i18n.{I18nSupport, MessagesApi} | ||
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} | ||
import repositories.SelectedPreviousRegistrationRepository | ||
import services.PreviousRegistrationService | ||
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController | ||
import viewmodels.previousReturns.{PreviousRegistration, SelectedPreviousRegistration} | ||
import views.html.previousReturns.ReturnRegistrationSelectionView | ||
|
||
import javax.inject.Inject | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class ReturnRegistrationSelectionController @Inject()( | ||
override val messagesApi: MessagesApi, | ||
cc: AuthenticatedControllerComponents, | ||
formProvider: ReturnRegistrationSelectionFormProvider, | ||
view: ReturnRegistrationSelectionView, | ||
previousRegistrationService: PreviousRegistrationService, | ||
selectedPreviousRegistrationRepository: SelectedPreviousRegistrationRepository | ||
)(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport with Logging { | ||
|
||
protected val controllerComponents: MessagesControllerComponents = cc | ||
|
||
def onPageLoad(waypoints: Waypoints): Action[AnyContent] = cc.authAndGetOptionalData().async { | ||
implicit request => | ||
for { | ||
previousRegistrations <- previousRegistrationService.getPreviousRegistrations() | ||
selectedPreviousRegistration <- selectedPreviousRegistrationRepository.get(request.userId) | ||
} yield { | ||
val form: Form[PreviousRegistration] = formProvider(previousRegistrations) | ||
|
||
val preparedForm = selectedPreviousRegistration match { | ||
case None => form | ||
case Some(value) => form.fill(value.previousRegistration) | ||
} | ||
|
||
previousRegistrations match { | ||
case Nil => Redirect(controllers.routes.JourneyRecoveryController.onPageLoad()) | ||
case _ :: Nil => Redirect(controllers.previousReturns.routes.ViewReturnsMultipleRegController.onPageLoad()) | ||
case _ => Ok(view(waypoints, preparedForm, previousRegistrations)) | ||
} | ||
} | ||
} | ||
|
||
def onSubmit(waypoints: Waypoints): Action[AnyContent] = cc.authAndGetOptionalData().async { | ||
implicit request => | ||
previousRegistrationService.getPreviousRegistrations().flatMap { previousRegistrations => | ||
val form: Form[PreviousRegistration] = formProvider(previousRegistrations) | ||
|
||
form.bindFromRequest().fold( | ||
formWithErrors => Future.successful(BadRequest(view(waypoints, formWithErrors, previousRegistrations))), | ||
value => | ||
selectedPreviousRegistrationRepository.set(SelectedPreviousRegistration(request.userId, value)).map { _ => | ||
Redirect(controllers.previousReturns.routes.ViewReturnsMultipleRegController.onPageLoad()) | ||
} | ||
) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.