Skip to content

Commit 57956a5

Browse files
committed
WIP
1 parent 263e98d commit 57956a5

19 files changed

+519
-97
lines changed

app/controllers/land/AgriculturalOrDevelopmentalLandController.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class AgriculturalOrDevelopmentalLandController @Inject()(
7070
_ <- sessionRepository.set(updatedAnswers)
7171
} yield if (value) {
7272
Redirect(navigator.nextPage(AgriculturalOrDevelopmentalLandPage, mode, updatedAnswers))
73-
} else { // TODO: DTR-2495 - redirect to Land CYA - SPRINT 10
74-
Redirect(controllers.land.routes.LandBeforeYouStartController.onPageLoad())
73+
} else {
74+
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
7575
}
7676
)
7777
}

app/controllers/land/DoYouKnowTheAreaOfLandController.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ class DoYouKnowTheAreaOfLandController @Inject()(
7272
if (value) {
7373
Redirect(navigator.nextPage(DoYouKnowTheAreaOfLandPage, mode, updatedAnswers))
7474
} else {
75-
//TODO: Change to Land CYA - DTR-2495
76-
Redirect(controllers.routes.ReturnTaskListController.onPageLoad())
75+
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
7776
}
7877
}
7978
)

app/controllers/land/LandAddNlpgUprnController.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class LandAddNlpgUprnController @Inject()(
7070
case true =>
7171
Redirect(navigator.nextPage(LandAddNlpgUprnPage, mode, updatedAnswers))
7272
case false if mode == CheckMode =>
73-
Redirect(controllers.routes.ReturnTaskListController.onPageLoad()) // TODO - DTR-2495 - SPRINT-10 - change to land CYA
73+
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
7474
case _ =>
7575
Redirect(controllers.land.routes.LandSendingPlanByPostController.onPageLoad(mode))
7676
}

app/controllers/land/LandAddressController.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ class LandAddressController @Inject()(
9090
address <- addressLookupService.getAddressById(id)
9191
updated <- addressLookupService.saveAddressDetails(address, LandAddressPage)
9292
} yield if (updated) {
93-
//TODO - DTR-2495 - SPRINT-10 - change this when we have the check your answers page
94-
Redirect(controllers.routes.ReturnTaskListController.onPageLoad())
93+
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
9594
} else {
9695
Redirect(controllers.routes.JourneyRecoveryController.onPageLoad())
9796
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* Copyright 2026 HM Revenue & Customs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package controllers.land
18+
19+
import connectors.StampDutyLandTaxConnector
20+
import controllers.actions.*
21+
import models.land.{CreateLandRequest, LandSessionQuestions, LandTypeOfProperty, UpdateLandRequest}
22+
import models.{CreateReturnAgentRequest, Land, ReturnVersionUpdateRequest, UpdateReturnAgentRequest, UserAnswers}
23+
import pages.land.LandTypeOfPropertyPage
24+
import pages.purchaserAgent.PurchaserAgentOverviewPage
25+
import play.api.i18n.{I18nSupport, MessagesApi}
26+
import play.api.libs.json.{JsError, JsSuccess}
27+
import play.api.mvc.*
28+
import repositories.SessionRepository
29+
import uk.gov.hmrc.http.HeaderCarrier
30+
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
31+
import viewmodels.checkAnswers.land.*
32+
import viewmodels.govuk.all.SummaryListViewModel
33+
import views.html.land.LandCheckYourAnswersView
34+
35+
import javax.inject.Inject
36+
import scala.concurrent.{ExecutionContext, Future}
37+
38+
class LandCheckYourAnswersController @Inject()(
39+
override val messagesApi: MessagesApi,
40+
identify: IdentifierAction,
41+
getData: DataRetrievalAction,
42+
requireData: DataRequiredAction,
43+
sessionRepository: SessionRepository,
44+
backendConnector: StampDutyLandTaxConnector,
45+
val controllerComponents: MessagesControllerComponents,
46+
view: LandCheckYourAnswersView
47+
)(implicit ex: ExecutionContext) extends FrontendBaseController with I18nSupport {
48+
49+
50+
def onPageLoad: Action[AnyContent] = (identify andThen getData andThen requireData).async {
51+
implicit request =>
52+
for {
53+
result <- sessionRepository.get(request.userAnswers.id)
54+
} yield {
55+
56+
val isDataEmpty = result.exists(_.data.value.isEmpty)
57+
58+
if (isDataEmpty) {
59+
Redirect(controllers.land.routes.LandBeforeYouStartController.onPageLoad())
60+
} else {
61+
val summaryList = SummaryListViewModel(
62+
rows = Seq(
63+
Some(LandTypeOfPropertySummary.row(request.userAnswers)),
64+
Some(LandInterestTransferredOrCreatedSummary.row(request.userAnswers)),
65+
Some(LandAddressSummary.row(request.userAnswers)),
66+
Some(LocalAuthorityCodeSummary.row(request.userAnswers)),
67+
Some(LandRegisteredHmRegistrySummary.row(request.userAnswers)),
68+
LandTitleNumberSummary.row(request.userAnswers),
69+
Some(LandAddNlpgUprnSummary.row(request.userAnswers)),
70+
LandNlpgUprnSummary.row(request.userAnswers),
71+
Some(LandSendingPlanByPostSummary.row(request.userAnswers)),
72+
Some(LandMineralsOrMineralRightsSummary.row(request.userAnswers)),
73+
if (propertyTypeCheck(request.userAnswers)) AgriculturalOrDevelopmentalLandSummary.row(request.userAnswers) else None,
74+
if (propertyTypeCheck(request.userAnswers)) DoYouKnowTheAreaOfLandSummary.row(request.userAnswers) else None,
75+
if (propertyTypeCheck(request.userAnswers)) AreaOfLandSummary.row(request.userAnswers) else None
76+
).flatten
77+
)
78+
79+
Ok(view(summaryList))
80+
}
81+
}
82+
}
83+
84+
def onSubmit(): Action[AnyContent] = (identify andThen getData andThen requireData).async { implicit request =>
85+
86+
sessionRepository.get(request.userAnswers.id).flatMap {
87+
case Some(userAnswers) =>
88+
(userAnswers.data \ "LandCurrent").validate[LandSessionQuestions] match {
89+
case JsSuccess(sessionData, _) =>
90+
request.userAnswers.get(PurchaserAgentOverviewPage).map { returnAgentId =>
91+
updateLand(userAnswers)
92+
}.getOrElse(createLand(userAnswers))
93+
94+
case JsError(_) =>
95+
Future.successful(
96+
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
97+
)
98+
}
99+
100+
case None =>
101+
Future.successful(Redirect(controllers.routes.JourneyRecoveryController.onPageLoad()))
102+
}
103+
}
104+
105+
private def updateLand(userAnswers: UserAnswers)(implicit hc: HeaderCarrier, request: Request[_]): Future[Result] = {
106+
for {
107+
land <- Land.from(userAnswers)
108+
updateReturnVersionRequest <- ReturnVersionUpdateRequest.from(userAnswers)
109+
updateReturnVersionReturn <- backendConnector.updateReturnVersion(updateReturnVersionRequest)
110+
updateLandRequest <- UpdateLandRequest.from(userAnswers, land) if updateReturnVersionReturn.newVersion.isDefined
111+
updateLandReturn <- backendConnector.updateLand(updateLandRequest) if updateReturnVersionReturn.newVersion.isDefined
112+
} yield {
113+
if (updateLandReturn.updated) {
114+
Redirect(controllers.vendor.routes.VendorOverviewController.onPageLoad())
115+
.flashing("landUpdated" -> FullName.fullName(updateLandRequest.forename1, updateVendorRequest.forename2, updateVendorRequest.name))
116+
} else {
117+
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
118+
}
119+
}
120+
}
121+
122+
private def createLand(userAnswers: UserAnswers)(implicit hc: HeaderCarrier, request: Request[_]): Future[Result] = {
123+
for {
124+
land <- Land.from(userAnswers)
125+
createLandRequest <- CreateLandRequest.from(userAnswers, land)
126+
createLandReturn <- backendConnector.createLand(createLandRequest)
127+
} yield {
128+
if (createLandReturn.landId.nonEmpty) {
129+
Redirect(controllers.vendor.routes.VendorOverviewController.onPageLoad())
130+
.flashing("LandCreated" -> FullName.fullName(createVendorRequest.forename1, createVendorRequest.forename2, createVendorRequest.name))
131+
} else {
132+
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
133+
}
134+
}
135+
}
136+
137+
private def propertyTypeCheck(userAnswers: UserAnswers): Boolean = {
138+
userAnswers.get(LandTypeOfPropertyPage) match {
139+
case Some(LandTypeOfProperty.Mixed | LandTypeOfProperty.NonResidential) => true
140+
case _ => false
141+
}
142+
}
143+
}

app/controllers/land/LandMineralsOrMineralRightsController.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ class LandMineralsOrMineralRightsController @Inject()(
8383
case LandTypeOfProperty.Mixed | LandTypeOfProperty.NonResidential =>
8484
Redirect(navigator.nextPage(LandMineralsOrMineralRightsPage, mode, updatedAnswers))
8585
case _ =>
86-
// TODO DTR-2495: Redirect to CYA page
87-
Redirect(controllers.land.routes.LandMineralsOrMineralRightsController.onPageLoad(NormalMode))
86+
Redirect(controllers.land.routes.LandCheckYourAnswersController.onPageLoad())
8887
}
8988
}
9089
)

app/models/FullReturn.scala

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
package models
1818

19+
import models.land.LandSessionQuestions
1920
import models.vendor.VendorSessionQuestions
2021
import models.purchaser.PurchaserSessionQuestions
2122
import org.slf4j.Logger
2223
import play.api.libs.json.{Json, OFormat}
23-
import java.time.format.DateTimeFormatter
24-
2524

25+
import java.time.format.DateTimeFormatter
2626
import scala.concurrent.Future
2727

2828

@@ -290,6 +290,39 @@ case class Land(
290290

291291
object Land {
292292
implicit val format: OFormat[Land] = Json.format[Land]
293+
294+
def from(userAnswers: UserAnswers): Future[Land] = {
295+
val landSessionQuestions: LandSessionQuestions = userAnswers.data.as[LandSessionQuestions]
296+
297+
val existingLand = for {
298+
fullReturn <- userAnswers.fullReturn
299+
land <- fullReturn.land
300+
landId <- landSessionQuestions.landID
301+
existing <- land.find(_.landID.contains(landId))
302+
} yield existing
303+
304+
Future.successful(Land(
305+
landID = landSessionQuestions.landID,
306+
returnID = userAnswers.returnId,
307+
propertyType = landSessionQuestions.typeOfProperty,
308+
interestCreatedTransferred = landSessionQuestions.interestCreatedTransferred,
309+
houseNumber = landSessionQuestions.landAddress.houseNumber,
310+
address1 = Some(landSessionQuestions.landAddress.line1),
311+
address2 = landSessionQuestions.landAddress.line2,
312+
address3 = landSessionQuestions.landAddress.line3,
313+
address4 = landSessionQuestions.landAddress.line4,
314+
postcode = Some(landSessionQuestions.landAddress.postcode),
315+
landArea = landSessionQuestions.areaOfLand,
316+
localAuthorityNumber = Some(landSessionQuestions.localAuthorityCode),
317+
mineralRights = Some(landSessionQuestions.mineralRights),
318+
NLPGUPRN = landSessionQuestions.nlpgUprn,
319+
willSendPlanByPost = Some(landSessionQuestions.sendingPlanByPost),
320+
titleNumber = landSessionQuestions.titleNumber,
321+
landResourceRef = existingLand.flatMap(_.landResourceRef),
322+
nextLandID = existingLand.flatMap(_.nextLandID),
323+
DARPostcode = existingLand.flatMap(_.DARPostcode)
324+
))
325+
}
293326
}
294327

295328
case class Transaction(

0 commit comments

Comments
 (0)