Skip to content

Commit a9957a6

Browse files
DTR-2501 - Changes for remove land (#199)
* DTR-2501 initial changes for remove land * changed land reference id in controllerspec * addressed all review comments * addressed review comments and removed mocksessionRepository inject in controller spec
1 parent bc43776 commit a9957a6

File tree

10 files changed

+655
-6
lines changed

10 files changed

+655
-6
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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 forms.land.RemoveLandFormProvider
22+
import models.land.DeleteLandRequest
23+
import models.{Land, ReturnVersionUpdateRequest}
24+
import pages.land.RemoveLandPage
25+
import play.api.data.Form
26+
import play.api.i18n.{I18nSupport, MessagesApi}
27+
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
28+
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
29+
import views.html.land.RemoveLandView
30+
31+
import javax.inject.Inject
32+
import scala.concurrent.{ExecutionContext, Future}
33+
34+
class RemoveLandController @Inject()(
35+
override val messagesApi: MessagesApi,
36+
identify: IdentifierAction,
37+
getData: DataRetrievalAction,
38+
requireData: DataRequiredAction,
39+
formProvider: RemoveLandFormProvider,
40+
val controllerComponents: MessagesControllerComponents,
41+
backendConnector: StampDutyLandTaxConnector,
42+
view: RemoveLandView
43+
)(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport {
44+
45+
val form: Form[Boolean] = formProvider()
46+
47+
def onPageLoad(): Action[AnyContent] = (identify andThen getData andThen requireData) {
48+
implicit request =>
49+
50+
//TODO update to take removeLandId from user answers overview page DTR-2498.
51+
val removeLandId = "LND-REF-001"
52+
// request.userAnswers.get(LandOverviewRemovePage).map { removeLandId =>
53+
54+
val maybeReturnLandToRemove = request.userAnswers.fullReturn.flatMap(_.land.flatMap(_.find(_.landResourceRef.contains(removeLandId))))
55+
val addressLine1 = maybeReturnLandToRemove.flatMap(_.address1).getOrElse("")
56+
57+
maybeReturnLandToRemove match {
58+
case None =>
59+
Redirect(controllers.routes.JourneyRecoveryController.onPageLoad())
60+
61+
case Some(land) =>
62+
val preparedForm = request.userAnswers.get(RemoveLandPage) match {
63+
case None => form
64+
case Some(value) => form.fill(value)
65+
}
66+
Ok(view(preparedForm, addressLine1))
67+
}//TODO remove bellow comments post overview page DTR-2498 implementation.
68+
/*.getOrElse(
69+
Redirect(controllers.land.routes.LandOverviewController.onPageLoad())
70+
)*/
71+
}
72+
73+
def onSubmit(): Action[AnyContent] = (identify andThen getData andThen requireData).async {
74+
implicit request =>
75+
76+
//TODO update to take ID from user answers overview page DTR-2498
77+
val removeLandId = "LND-REF-001"
78+
// request.userAnswers.get(LandOverviewRemovePage).map { removeLandId =>
79+
val maybeLandToDelete: Option[Land] = for {
80+
fullReturn <- request.userAnswers.fullReturn
81+
allLands <- fullReturn.land
82+
returnLandToDelete <- allLands.find(_.landResourceRef.contains(removeLandId))
83+
} yield returnLandToDelete
84+
85+
maybeLandToDelete match {
86+
case None =>
87+
Future.successful(Redirect(controllers.routes.JourneyRecoveryController.onPageLoad()))
88+
89+
case Some(maybeLandToDelete) =>
90+
val addressLine1 = maybeLandToDelete.address1.getOrElse("")
91+
form.bindFromRequest().fold(
92+
formWithErrors =>
93+
Future.successful(BadRequest(view(formWithErrors, addressLine1))),
94+
95+
value =>
96+
if (value) {
97+
(for {
98+
updateReturnVersionRequest <- ReturnVersionUpdateRequest.from(request.userAnswers)
99+
returnVersion <- backendConnector.updateReturnVersion(updateReturnVersionRequest)
100+
deleteLandRequest <- DeleteLandRequest.from(request.userAnswers, removeLandId) if returnVersion.newVersion.isDefined
101+
deleteLandReturn <- backendConnector.deleteLand(deleteLandRequest) if returnVersion.newVersion.isDefined
102+
} yield {
103+
//Redirect(controllers.land.routes.LandOverviewController.onPageLoad()).flashing("landDeleted" -> addressLine1)
104+
Redirect(controllers.land.routes.RemoveLandController.onPageLoad()).flashing("landDeleted" -> addressLine1) //TODO update to land overview page DTR-2498
105+
}).recover {
106+
case _ =>
107+
// Redirect(controllers.land.routes.LandOverviewController.onPageLoad())
108+
Redirect(controllers.routes.ReturnTaskListController.onPageLoad()) //TODO update to land overview page DTR-2498
109+
110+
}
111+
} else {
112+
//Future.successful(Redirect(controllers.land.routes.LandOverviewController.onPageLoad()))
113+
Future.successful(Redirect(controllers.routes.ReturnTaskListController.onPageLoad())) //TODO update to land overview page DTR-2498
114+
}
115+
)
116+
}//TODO remove bellow comments post overview page DTR-2498 implementation.
117+
/*.getOrElse(
118+
Redirect(controllers.land.routes.LandOverviewController.onPageLoad())
119+
)*/
120+
}
121+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 forms.land
18+
19+
import forms.mappings.Mappings
20+
import play.api.data.Form
21+
22+
import javax.inject.Inject
23+
24+
class RemoveLandFormProvider @Inject() extends Mappings {
25+
26+
def apply(): Form[Boolean] =
27+
Form(
28+
"value" -> boolean("land.removeLand.error.required")
29+
)
30+
}

app/models/land/LandModels.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
package models.land
1818

19+
import models.UserAnswers
1920
import play.api.libs.json.{Json, OFormat}
21+
import scala.concurrent.Future
2022

2123
case class CreateLandRequest(
2224
stornId: String,
@@ -93,6 +95,24 @@ case class DeleteLandRequest(
9395

9496
object DeleteLandRequest {
9597
implicit val format: OFormat[DeleteLandRequest] = Json.format[DeleteLandRequest]
98+
def from(userAnswers: UserAnswers, landResourceRef: String): Future[DeleteLandRequest] = {
99+
userAnswers.fullReturn match {
100+
case Some(fullReturn) =>
101+
fullReturn.land.flatMap(_.find(_.landResourceRef.contains(landResourceRef))) match {
102+
case Some(_) =>
103+
Future.successful(DeleteLandRequest(
104+
storn = fullReturn.stornId,
105+
returnResourceRef = fullReturn.returnResourceRef,
106+
landResourceRef = landResourceRef
107+
))
108+
case None =>
109+
Future.failed(new NoSuchElementException("Land not found"))
110+
}
111+
112+
case None =>
113+
Future.failed(new NoSuchElementException("Full return not found"))
114+
}
115+
}
96116
}
97117

98118
case class DeleteLandReturn(
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 pages.land
18+
19+
import pages.QuestionPage
20+
import play.api.libs.json.JsPath
21+
22+
case object RemoveLandPage extends QuestionPage[Boolean] {
23+
24+
override def path: JsPath = JsPath \ toString
25+
26+
override def toString: String = "removeLand"
27+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
@import views.html.components._
18+
19+
@this(
20+
layout: templates.Layout,
21+
formHelper: FormWithCSRF,
22+
govukErrorSummary: GovukErrorSummary,
23+
govukRadios: GovukRadios,
24+
govukButton: GovukButton,
25+
caption: Caption
26+
)
27+
28+
@(form: Form[_], addressLine1 : String)(implicit request: Request[_], messages: Messages)
29+
30+
@layout(pageTitle = title(form, messages("land.removeLand.title"), section = Some(messages("site.land.caption")))) {
31+
32+
@formHelper(action = controllers.land.routes.RemoveLandController.onSubmit(), Symbol("autoComplete") -> "off") {
33+
34+
@if(form.errors.nonEmpty) {
35+
@govukErrorSummary(ErrorSummaryViewModel(form))
36+
}
37+
38+
@caption(messages("site.land.caption"))
39+
40+
@govukRadios(
41+
RadiosViewModel(
42+
field = form("value"),
43+
legend = LegendViewModel(messages("land.removeLand.heading", addressLine1)).asPageHeading(),
44+
items = Seq(
45+
RadioItem(
46+
value = Some("true"),
47+
content = Text(messages("site.yes"))
48+
),
49+
50+
RadioItem(
51+
value = Some("false"),
52+
content = Text(messages("site.no"))
53+
)
54+
)
55+
)
56+
)
57+
58+
@govukButton(
59+
ButtonViewModel(messages("site.save.continue"))
60+
)
61+
}
62+
}

conf/app.routes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,6 @@ GET /about-UK-residency/non-UK-resident-purchaser
378378
POST /about-UK-residency/non-UK-resident-purchaser controllers.ukResidency.NonUkResidentPurchaserController.onSubmit(mode: Mode = NormalMode)
379379
GET /about-UK-residency/non-UK-resident-purchaser/change controllers.ukResidency.NonUkResidentPurchaserController.onPageLoad(mode: Mode = CheckMode)
380380
POST /about-UK-residency/non-UK-resident-purchaser/change controllers.ukResidency.NonUkResidentPurchaserController.onSubmit(mode: Mode = CheckMode)
381+
382+
GET /about-the-land/remove-land-or-property controllers.land.RemoveLandController.onPageLoad()
383+
POST /about-the-land/remove-land-or-property controllers.land.RemoveLandController.onSubmit()

conf/messages.en

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,3 +1059,8 @@ ukResidency.crownEmploymentRelief.checkYourAnswersLabel
10591059
ukResidency.crownEmploymentRelief.missing = Select if any purchasers are claiming Crown employment relief
10601060
ukResidency.crownEmploymentRelief.error.required = Please select an option
10611061
ukResidency.crownEmploymentRelief.change.hidden = CrownEmploymentRelief
1062+
1063+
land.removeLand.title = Are you sure you want to remove the land or property?
1064+
land.removeLand.heading = Are you sure you want to remove {0}?
1065+
land.removeLand.error.required = Select yes if remove Land
1066+
land.removeLand.change.hidden = Are you sure you want to remove the land or property?

0 commit comments

Comments
 (0)