Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class AgriculturalOrDevelopmentalLandController @Inject()(
_ <- sessionRepository.set(updatedAnswers)
} yield if (value) {
Redirect(navigator.nextPage(AgriculturalOrDevelopmentalLandPage, mode, updatedAnswers))
} else { // TODO: DTR-2495 - redirect to Land CYA - SPRINT 10
Redirect(controllers.land.routes.LandBeforeYouStartController.onPageLoad())
} else {
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import forms.land.ConfirmLandOrPropertyAddressFormProvider
import models.Mode
import models.address.Address
import navigation.Navigator
import pages.land.{ConfirmLandOrPropertyAddressPage, LandAddressPage, LandIdPage}
import pages.land.{ConfirmLandOrPropertyAddressPage, LandAddressPage, LandOverviewPage}
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
Expand Down Expand Up @@ -96,7 +96,7 @@ class ConfirmLandOrPropertyAddressController @Inject()(
updatedAnswers <- Future.fromTry(request.userAnswers.set(ConfirmLandOrPropertyAddressPage, value))
_ <- sessionRepository.set(updatedAnswers)
} yield {
val updatedAnswersWithLandId = updatedAnswers.set(LandIdPage, landId).get
val updatedAnswersWithLandId = updatedAnswers.set(LandOverviewPage, landId).get
if (value.toString == "yes") {
val address = Address(line1 = add1, line2 = address2, line3 = address3, line4 = address4, postcode = postcode)
val updatedAnswersWithAddress = updatedAnswersWithLandId.set(LandAddressPage, address).get
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/land/DoYouKnowTheAreaOfLandController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ class DoYouKnowTheAreaOfLandController @Inject()(
if (value) {
Redirect(navigator.nextPage(DoYouKnowTheAreaOfLandPage, mode, updatedAnswers))
} else {
//TODO: Change to Land CYA - DTR-2495
Redirect(controllers.routes.ReturnTaskListController.onPageLoad())
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/land/LandAddNlpgUprnController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LandAddNlpgUprnController @Inject()(
case true =>
Redirect(navigator.nextPage(LandAddNlpgUprnPage, mode, updatedAnswers))
case false if mode == CheckMode =>
Redirect(controllers.routes.ReturnTaskListController.onPageLoad()) // TODO - DTR-2495 - SPRINT-10 - change to land CYA
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
case _ =>
Redirect(controllers.land.routes.LandSendingPlanByPostController.onPageLoad(mode))
}
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/land/LandAddressController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ class LandAddressController @Inject()(
address <- addressLookupService.getAddressById(id)
updated <- addressLookupService.saveAddressDetails(address, LandAddressPage)
} yield if (updated) {
//TODO - DTR-2495 - SPRINT-10 - change this when we have the check your answers page
Redirect(controllers.routes.ReturnTaskListController.onPageLoad())
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
} else {
Redirect(controllers.routes.JourneyRecoveryController.onPageLoad())
}
Expand Down
171 changes: 171 additions & 0 deletions app/controllers/land/LandCheckYourAnswersController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
* Copyright 2026 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.land

import connectors.StampDutyLandTaxConnector
import controllers.actions.*
import models.land.{CreateLandRequest, LandSessionQuestions, LandTypeOfProperty, UpdateLandRequest}
import models.{Land, ReturnVersionUpdateRequest, UserAnswers}
import pages.land.{AgriculturalOrDevelopmentalLandPage, DoYouKnowTheAreaOfLandPage, LandAddNlpgUprnPage, LandOverviewPage, LandRegisteredHmRegistryPage,
LandTypeOfPropertyPage}
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.libs.json.{JsError, JsSuccess}
import play.api.mvc.*
import repositories.SessionRepository
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import viewmodels.checkAnswers.land.*
import viewmodels.govuk.all.SummaryListViewModel
import views.html.land.LandCheckYourAnswersView

import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}

class LandCheckYourAnswersController @Inject()(
override val messagesApi: MessagesApi,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
sessionRepository: SessionRepository,
backendConnector: StampDutyLandTaxConnector,
val controllerComponents: MessagesControllerComponents,
view: LandCheckYourAnswersView
)(implicit ex: ExecutionContext) extends FrontendBaseController with I18nSupport {

def onPageLoad: Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>
for {
result <- sessionRepository.get(request.userAnswers.id)
} yield {

val isDataEmpty = result.exists(_.data.value.isEmpty)

if (isDataEmpty) {
Redirect(controllers.land.routes.LandBeforeYouStartController.onPageLoad())
} else {
val summaryList = SummaryListViewModel(
rows = Seq(
Some(LandTypeOfPropertySummary.row(request.userAnswers)),
Some(LandInterestTransferredOrCreatedSummary.row(request.userAnswers)),
Some(LandAddressSummary.row(request.userAnswers)),
Some(LocalAuthorityCodeSummary.row(request.userAnswers)),
Some(LandRegisteredHmRegistrySummary.row(request.userAnswers)),
if (titleCheck(request.userAnswers)) LandTitleNumberSummary.row(request.userAnswers) else None,
Some(LandAddNlpgUprnSummary.row(request.userAnswers)),
if (nlpgCheck(request.userAnswers)) LandNlpgUprnSummary.row(request.userAnswers) else None,
Some(LandSendingPlanByPostSummary.row(request.userAnswers)),
Some(LandMineralsOrMineralRightsSummary.row(request.userAnswers)),
if (propertyTypeCheck(request.userAnswers)) AgriculturalOrDevelopmentalLandSummary.row(request.userAnswers) else None,
if (propertyTypeCheck(request.userAnswers) && agriculturalCheck(request.userAnswers)) DoYouKnowTheAreaOfLandSummary.row(request.userAnswers) else None,
if (propertyTypeCheck(request.userAnswers) && knowAreaCheck(request.userAnswers) && agriculturalCheck(request.userAnswers)) {AreaOfLandSummary.row(request.userAnswers)} else None
).flatten
)

Ok(view(summaryList))
}
}
}

def onSubmit(): Action[AnyContent] = (identify andThen getData andThen requireData).async { implicit request =>

sessionRepository.get(request.userAnswers.id).flatMap {
case Some(userAnswers) =>
(userAnswers.data \ "landCurrent").validate[LandSessionQuestions] match {
case JsSuccess(sessionData, _) =>
request.userAnswers.get(LandOverviewPage).map { landId =>
updateLand(userAnswers)
}.getOrElse(createLand(userAnswers))

case JsError(_) =>
Future.successful(
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
)
}

case None =>
Future.successful(Redirect(controllers.routes.JourneyRecoveryController.onPageLoad()))
}
}

private def updateLand(userAnswers: UserAnswers)(implicit hc: HeaderCarrier, request: Request[_]): Future[Result] = {
for {
land <- Land.from(userAnswers)
updateReturnVersionRequest <- ReturnVersionUpdateRequest.from(userAnswers)
updateReturnVersionReturn <- backendConnector.updateReturnVersion(updateReturnVersionRequest)
updateLandRequest <- UpdateLandRequest.from(userAnswers, land) if updateReturnVersionReturn.newVersion.isDefined
updateLandReturn <- backendConnector.updateLand(updateLandRequest) if updateReturnVersionReturn.newVersion.isDefined
} yield {
if (updateLandReturn.updated) {
Redirect(controllers.land.routes.LandOverviewController.onPageLoad())
.flashing("landUpdated" -> updateLandRequest.addressLine1)
} else {
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
}
}
}

private def createLand(userAnswers: UserAnswers)(implicit hc: HeaderCarrier, request: Request[_]): Future[Result] = {
for {
land <- Land.from(userAnswers)
createLandRequest <- CreateLandRequest.from(userAnswers, land)
createLandReturn <- backendConnector.createLand(createLandRequest)
} yield {
if (createLandReturn.landId.nonEmpty) {
Redirect(controllers.land.routes.LandOverviewController.onPageLoad())
.flashing("landCreated" -> createLandRequest.addressLine1)
} else {
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
}
}
}

private def titleCheck(userAnswers: UserAnswers): Boolean = {
userAnswers.get(LandRegisteredHmRegistryPage) match {
case Some(true) => true
case _ => false
}
}

private def nlpgCheck(userAnswers: UserAnswers): Boolean = {
userAnswers.get(LandAddNlpgUprnPage) match {
case Some(true) => true
case _ => false
}
}

private def agriculturalCheck(userAnswers: UserAnswers): Boolean = {
userAnswers.get(AgriculturalOrDevelopmentalLandPage) match {
case Some(true) => true
case _ => false
}
}

private def knowAreaCheck(userAnswers: UserAnswers): Boolean = {
userAnswers.get(DoYouKnowTheAreaOfLandPage) match {
case Some(true) => true
case _ => false
}
}

private def propertyTypeCheck(userAnswers: UserAnswers): Boolean = {
userAnswers.get(LandTypeOfPropertyPage) match {
case Some(LandTypeOfProperty.Mixed | LandTypeOfProperty.NonResidential) => true
case _ => false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ class LandMineralsOrMineralRightsController @Inject()(
case LandTypeOfProperty.Mixed | LandTypeOfProperty.NonResidential =>
Redirect(navigator.nextPage(LandMineralsOrMineralRightsPage, mode, updatedAnswers))
case _ =>
// TODO DTR-2495: Redirect to CYA page
Redirect(controllers.land.routes.LandMineralsOrMineralRightsController.onPageLoad(NormalMode))
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
}
}
)
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/land/LandOverviewController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ class LandOverviewController @Inject()(
for {
updatedAnswers <- Future.fromTry(populateLandService.populateLandInSession(land, request.userAnswers))
_ <- sessionRepository.set(updatedAnswers)
// TODO: CYA Page
} yield Redirect(controllers.land.routes.LandBeforeYouStartController.onPageLoad())
} yield Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())

case None =>
Future.successful(Redirect(controllers.routes.JourneyRecoveryController.onPageLoad()))
Expand Down
37 changes: 35 additions & 2 deletions app/models/FullReturn.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package models

import models.land.LandSessionQuestions
import models.vendor.VendorSessionQuestions
import models.purchaser.PurchaserSessionQuestions
import org.slf4j.Logger
import play.api.libs.json.{Json, OFormat}
import java.time.format.DateTimeFormatter


import java.time.format.DateTimeFormatter
import scala.concurrent.Future


Expand Down Expand Up @@ -263,6 +263,39 @@ case class Land(

object Land {
implicit val format: OFormat[Land] = Json.format[Land]

def from(userAnswers: UserAnswers): Future[Land] = {
val landSessionQuestions: LandSessionQuestions = (userAnswers.data \ "landCurrent").as[LandSessionQuestions]

val existingLand = for {
fullReturn <- userAnswers.fullReturn
land <- fullReturn.land
landId <- landSessionQuestions.landId
existing <- land.find(_.landID.contains(landId))
} yield existing

Future.successful(Land(
landID = landSessionQuestions.landId,
returnID = userAnswers.returnId,
propertyType = landSessionQuestions.propertyType,
interestCreatedTransferred = landSessionQuestions.landInterestTransferredOrCreated,
houseNumber = landSessionQuestions.landAddress.houseNumber,
address1 = Some(landSessionQuestions.landAddress.line1),
address2 = landSessionQuestions.landAddress.line2,
address3 = landSessionQuestions.landAddress.line3,
address4 = landSessionQuestions.landAddress.line4,
postcode = Some(landSessionQuestions.landAddress.postcode),
landArea = landSessionQuestions.areaOfLand,
localAuthorityNumber = Some(landSessionQuestions.localAuthorityCode),
mineralRights = existingLand.map(_.mineralRights).getOrElse(Some("NO")),
NLPGUPRN = landSessionQuestions.landNlpgUprn,
willSendPlanByPost = existingLand.map(_.willSendPlanByPost).getOrElse(Some("NO")),
titleNumber = landSessionQuestions.titleNumber,
landResourceRef = existingLand.flatMap(_.landResourceRef),
nextLandID = existingLand.flatMap(_.nextLandID),
DARPostcode = existingLand.flatMap(_.DARPostcode)
))
}
}

case class Transaction(
Expand Down
Loading