Skip to content
Merged
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
@@ -0,0 +1,80 @@
/*
* Copyright 2025 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 uk.gov.hmrc.ngrraldfrontend.controllers

import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.{buildRadios, simpleNgrRadio}
import uk.gov.hmrc.ngrraldfrontend.models.forms.RepairsAndFittingOutForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.RepairsAndFittingOutForm.form
import uk.gov.hmrc.ngrraldfrontend.models.{Mode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
import uk.gov.hmrc.ngrraldfrontend.pages.RepairsAndFittingOutPage
import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.RepairsAndFittingOutView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

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

class RepairsAndFittingOutController @Inject()(repairsAndFittingView: RepairsAndFittingOutView,
authenticate: AuthRetrievals,
getData: DataRetrievalAction,
sessionRepository: SessionRepository,
navigator: Navigator,
mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport {


def show(mode: Mode): Action[AnyContent] = {
(authenticate andThen getData).async { implicit request =>
val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(RepairsAndFittingOutPage) match {
case None => form
case Some(value) => form.fill(RepairsAndFittingOutForm(value.toString))
}
Future.successful(Ok(repairsAndFittingView(
selectedPropertyAddress = request.property.addressFull,
form = preparedForm,
ngrRadio = buildRadios(preparedForm, RepairsAndFittingOutForm.repairsAndFittingOutRadio),
mode = mode
)))
}
}

def submit(mode: Mode): Action[AnyContent] =
(authenticate andThen getData).async { implicit request =>
form.bindFromRequest().fold(
formWithErrors => {
Future.successful(BadRequest(repairsAndFittingView(
form = formWithErrors,
ngrRadio = buildRadios(formWithErrors, RepairsAndFittingOutForm.repairsAndFittingOutRadio),
selectedPropertyAddress = request.property.addressFull,
mode = mode
)))
},
radioValue =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId))
.set(RepairsAndFittingOutPage, radioValue.radioValue.toBoolean))
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(navigator.nextPage(RepairsAndFittingOutPage, mode, updatedAnswers))

)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2025 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 uk.gov.hmrc.ngrraldfrontend.models.forms

import play.api.data.Form
import play.api.data.Forms.mapping
import play.api.i18n.*
import play.api.libs.json.{Json, OFormat}
import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.{ngrRadio, noButton, yesButton}

final case class RepairsAndFittingOutForm(radioValue: String)

object RepairsAndFittingOutForm extends CommonFormValidators with Mappings {
implicit val format: OFormat[RepairsAndFittingOutForm] = Json.format[RepairsAndFittingOutForm]

private lazy val radioUnselectedError = "repairsAndFittingOut.empty.error"
val radio = "repairsAndFittingOut-radio-value"

val messagesApi: MessagesApi = new DefaultMessagesApi()
val lang: Lang = Lang.defaultLang
val messages: Messages = MessagesImpl(lang, messagesApi)

def unapply(repairsAndFittingOutForm: RepairsAndFittingOutForm): Option[(String)] =
Some(repairsAndFittingOutForm.radioValue)

def repairsAndFittingOutRadio(implicit messages: Messages): NGRRadio =
ngrRadio(
radioName = radio,
radioButtons = Seq(
yesButton(),
noButton()
),
ngrTitle = "repairsAndFittingOut.header"
)

def form: Form[RepairsAndFittingOutForm] = {
Form(
mapping(
radio -> radioText(radioUnselectedError),
)(RepairsAndFittingOutForm.apply)(RepairsAndFittingOutForm.unapply)
)
}


}
1 change: 1 addition & 0 deletions app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class Navigator @Inject()() {
case ConfirmBreakClausePage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.LandlordController.show(NormalMode) //TODO This needs to be amended when the journey is completed
//TODO Next page not made yet
case RentReviewPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode)
case RepairsAndFittingOutPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.LandlordController.show(NormalMode) //TODO This needs to be amended when the journey is completed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous page is already done. Can you please link it? It looks like only new agreement journey will come to this page.

case HowMuchWasTheLumpSumPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode) //TODO This needs to be amended when the journey is completed
case ParkingSpacesOrGaragesNotIncludedInYourRentPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RepairsAndInsuranceController.show(NormalMode)
case RepairsAndInsurancePage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.ConfirmBreakClauseController.show(NormalMode) //TODO Needs journey mapping
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2025 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 uk.gov.hmrc.ngrraldfrontend.pages

import play.api.libs.json.JsPath

case object RepairsAndFittingOutPage extends QuestionPage[Boolean] {

override def toString: String = "repairsAndFittingOutPage"

override def path: JsPath = JsPath \ toString

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@*
* Copyright 2025 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.
*@

@*
* Copyright 2025 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 uk.gov.hmrc.ngrraldfrontend.config.AppConfig

@import uk.gov.hmrc.govukfrontend.views.html.components._
@import uk.gov.hmrc.govukfrontend.views.Aliases._
@import uk.gov.hmrc.ngrraldfrontend.views.html.components._
@import uk.gov.hmrc.ngrraldfrontend.viewmodels.govuk.all._
@import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
@import uk.gov.hmrc.ngrraldfrontend.models.components.NavigationBarContent
@import uk.gov.hmrc.ngrraldfrontend.models.forms.RepairsAndFittingOutForm

@this(
layout: Layout,
formHelper: FormWithCSRF,
govukErrorSummary: GovukErrorSummary,
govukRadios : GovukRadios,
saveAndContinueButton: saveAndContinueButton
)

@(selectedPropertyAddress: String, form: Form[RepairsAndFittingOutForm], ngrRadio: Radios, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)

@layout(pageTitle = Some(messages("repairsAndFittingOut.title")), showBackLink = true, fullWidth = false) {
@formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.RepairsAndFittingOutController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
<span class="govuk-caption-m">@selectedPropertyAddress</span>
<h1 class="govuk-heading-l">@messages("repairsAndFittingOut.title")</h1>
<p class="govuk-body">@messages("repairsAndFittingOut.p1")</p>
@govukRadios(ngrRadio)
@saveAndContinueButton(msg = messages("service.continue"), isStartButton = false)
}
}
8 changes: 6 additions & 2 deletions conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ POST /does-rent-include-parking-spaces-or-garages uk.gov.hmrc.n
GET /does-rent-include-parking-spaces-or-garages/change uk.gov.hmrc.ngrraldfrontend.controllers.DoesYourRentIncludeParkingController.show(mode: Mode = CheckMode)
POST /does-rent-include-parking-spaces-or-garages/change uk.gov.hmrc.ngrraldfrontend.controllers.DoesYourRentIncludeParkingController.submit(mode: Mode = CheckMode)


#How many parking spaces or garages included in rent
GET /how-many-parking-spaces-or-garages-included-in-rent uk.gov.hmrc.ngrraldfrontend.controllers.HowManyParkingSpacesOrGaragesIncludedInRentController.show(mode: Mode = NormalMode)
POST /how-many-parking-spaces-or-garages-included-in-rent uk.gov.hmrc.ngrraldfrontend.controllers.HowManyParkingSpacesOrGaragesIncludedInRentController.submit(mode: Mode = NormalMode)
Expand Down Expand Up @@ -174,7 +173,12 @@ GET /rent-review/change uk.gov.hmrc.ngrraldfron
POST /rent-review/change uk.gov.hmrc.ngrraldfrontend.controllers.RentReviewController.submit(mode: Mode = CheckMode)

#Rent review
GET /repairs-and-fitting-out uk.gov.hmrc.ngrraldfrontend.controllers.RepairsAndFittingOutController.show(mode: Mode = NormalMode)
POST /repairs-and-fitting-out uk.gov.hmrc.ngrraldfrontend.controllers.RepairsAndFittingOutController.submit(mode: Mode = NormalMode)
GET /repairs-and-fitting-out/change uk.gov.hmrc.ngrraldfrontend.controllers.RepairsAndFittingOutController.show(mode: Mode = CheckMode)
POST /repairs-and-fitting-out/change uk.gov.hmrc.ngrraldfrontend.controllers.RepairsAndFittingOutController.submit(mode: Mode = CheckMode)

GET /how-much-was-the-lump-sum uk.gov.hmrc.ngrraldfrontend.controllers.HowMuchWasTheLumpSumController.show(mode: Mode = NormalMode)
POST /how-much-was-the-lump-sum uk.gov.hmrc.ngrraldfrontend.controllers.HowMuchWasTheLumpSumController.submit(mode: Mode = NormalMode)
GET /how-much-was-the-lump-sum/change uk.gov.hmrc.ngrraldfrontend.controllers.HowMuchWasTheLumpSumController.show(mode: Mode = CheckMode)
POST /how-much-was-the-lump-sum/change uk.gov.hmrc.ngrraldfrontend.controllers.HowMuchWasTheLumpSumController.submit(mode: Mode = CheckMode)
POST /how-much-was-the-lump-sum/change uk.gov.hmrc.ngrraldfrontend.controllers.HowMuchWasTheLumpSumController.submit(mode: Mode = CheckMode)
6 changes: 6 additions & 0 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ rentReview.rentReviewMonthsYears.months.maximum.11.error = The number of months
rentReview.rentReviewMonthsYears.years.invalid.error = The number of years for how often your rent is reviewed must be a number, like 2
rentReview.rentReviewMonthsYears.years.maximum.1000.error = How often your rent is reviewed must be 1,000 years or less

#Repairs and fitting out
repairsAndFittingOut.title = Repairs and fitting out
repairsAndFittingOut.header = Have you done any repairs or fitting out in the property?
repairsAndFittingOut.p1 = Repairs are when you fix things like poor electrical wiring, leaking windows or a broken toilet. Fitting out is when you install things like air conditioning, a kitchen or carpeting.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you've ran the application and see the radio button question(Have you done any repairs or fitting out in the property?). But I don't see the radio question text being here.

repairsAndFittingOut.empty.error = Select yes if you have done any repairs of fitting out in the property

#How much was the lump sum
howMuchWasTheLumpSum.title = How much was the lump sum?
howMuchWasTheLumpSum.empty.error = Enter the lump sum, in pounds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ class ConfirmBreakClauseControllerSpec extends ControllerSpecSupport {
val content = contentAsString(result)
content must include(pageTitle)
}
"return OK and the correct view with prepopulated data" in {
val result = controllerProperty(confirmBreakClauseAnswers).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
val document = Jsoup.parse(content)
document.select("input[type=radio][name=confirmBreakClause-radio-value][value=true]").hasAttr("checked") mustBe true
document.select("input[type=radio][name=confirmBreakClause-radio-value][value=false]").hasAttr("checked") mustBe false
}
"Return NotFoundException when property is not found in the mongo" in {
when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
Expand Down
Loading