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
import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouGetMoneyFromLandlordForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouGetMoneyFromLandlordForm.form
import uk.gov.hmrc.ngrraldfrontend.models.{Mode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
import uk.gov.hmrc.ngrraldfrontend.pages.DidYouGetMoneyFromLandlordPage
import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.DidYouGetMoneyFromLandlordView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

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

class DidYouGetMoneyFromLandlordController @Inject()(didYouGetMoneyFromLandlordView: DidYouGetMoneyFromLandlordView,
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(DidYouGetMoneyFromLandlordPage) match {
case None => form
case Some(value) => form.fill(DidYouGetMoneyFromLandlordForm(value.toString))

}
Future.successful(Ok(didYouGetMoneyFromLandlordView(
selectedPropertyAddress = request.property.addressFull,
form = preparedForm,
ngrRadio = buildRadios(preparedForm, DidYouGetMoneyFromLandlordForm.moneyLandlordRadio),
mode = mode
)))
}
}

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

)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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, optional}
import play.api.data.validation.{Constraint, Invalid, Valid}
import play.api.i18n.*
import play.api.libs.json.{Json, OFormat}
import uk.gov.hmrc.govukfrontend.views.Aliases.Text
import uk.gov.hmrc.govukfrontend.views.viewmodels.fieldset.Legend
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.{ngrRadio, noButton, yesButton}
import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings

final case class DidYouGetMoneyFromLandlordForm(radio: String)

object DidYouGetMoneyFromLandlordForm extends Mappings{
implicit val format: OFormat[DidYouGetMoneyFromLandlordForm] = Json.format[DidYouGetMoneyFromLandlordForm]

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

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

def unapply(didYouGetMoneyFromLandlordForm: DidYouGetMoneyFromLandlordForm): Option[String] = Some(didYouGetMoneyFromLandlordForm.radio)

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

def moneyLandlordRadio(implicit messages: Messages): NGRRadio =
ngrRadio(
radioName = moneyFromLandlordRadio,
radioButtons = Seq(
yesButton(),
noButton()
),
ngrTitle = "didYouGetMoneyFromLandlord.title",
ngrTitleClass = "govuk-fieldset__legend--l"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object LandlordForm extends CommonFormValidators with Mappings{
private lazy val landlordNameEmptyError = "landlord.name.empty.error"
private lazy val landlordNameTooLongError = "landlord.name.empty.tooLong.error"
private lazy val radioUnselectedError = "landlord.radio.empty.error"
private lazy val landlordRelationshipEmptyError = "landlord.relationship.empty.error"
private lazy val landlordRelationshipEmptyError = "landlord.relationship.emptyText.error"
private lazy val landlordRelationshipTooLongError = "landlord.radio.tooLong.error"

private val landlord = "landlord-name-value"
Expand Down
3 changes: 3 additions & 0 deletions app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class Navigator @Inject()() {
case None => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode)
}
case RentFreePeriodPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeStartController.show(NormalMode)
case ConfirmBreakClausePage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.LandlordController.show(NormalMode) //TODO This needs to be amended when the journey is completed
case DidYouGetMoneyFromLandlordPage => _ => 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.

Please link your previous page


case DoYouPayExtraForParkingSpacesPage => answers =>
answers.get(DoYouPayExtraForParkingSpacesPage) match {
case Some(value) => value match {
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 DidYouGetMoneyFromLandlordPage extends QuestionPage[Boolean] {

override def toString: String = "confirmBreakClause"

override def path: JsPath = JsPath \ toString

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

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

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

@layout(pageTitle = Some(messages("didYouGetMoneyFromLandlord.title")), showBackLink = true, fullWidth = false) {
@formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.DidYouGetMoneyFromLandlordController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
<span class="govuk-caption-m">@selectedPropertyAddress</span>
@govukRadios(ngrRadio)
@saveAndContinueButton(msg = messages("service.continue"), isStartButton = false)
}
}
6 changes: 6 additions & 0 deletions conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ POST /landlord uk.gov.hmrc.ngrraldfront
GET /landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.LandlordController.show(mode: Mode = CheckMode)
POST /landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.LandlordController.submit(mode: Mode = CheckMode)

#Did you get money from landlord
GET /did-you-get-money-from-landlord uk.gov.hmrc.ngrraldfrontend.controllers.DidYouGetMoneyFromLandlordController.show(mode: Mode = NormalMode)
POST /did-you-get-money-from-landlord uk.gov.hmrc.ngrraldfrontend.controllers.DidYouGetMoneyFromLandlordController.submit(mode: Mode = NormalMode)
GET /did-you-get-money-from-landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.DidYouGetMoneyFromLandlordController.show(mode: Mode = CheckMode)
POST /did-you-get-money-from-landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.DidYouGetMoneyFromLandlordController.submit(mode: Mode = CheckMode)

#What is your rent based on
GET /what-is-your-rent-based-on uk.gov.hmrc.ngrraldfrontend.controllers.WhatIsYourRentBasedOnController.show(mode: Mode = NormalMode)
POST /what-is-your-rent-based-on uk.gov.hmrc.ngrraldfrontend.controllers.WhatIsYourRentBasedOnController.submit(mode: Mode = NormalMode)
Expand Down
8 changes: 6 additions & 2 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ landlord.p2 = Do you have a relationship with the landlord other than as a tenan
landlord.name.empty.error = Enter the landlord''s full name
landlord.name.empty.tooLong.error = Landlord''s full name must be 50 characters or less
landlord.radio.empty.error = Select yes if you have any relationship with landlord
landlord.relationship.empty.error = Tell us what your relationship with the landlord is
landlord.relationship.emptyText.error = Tell us what your relationship with the landlord is
landlord.radio.tooLong.error = Maximum character allowed is 250
landlord.radio.yes = Can you tell us what your relationship with the landlord is?
landlord.radio.yes.hint = For example, the landlord is a family member, business partner, shared director or company pension fund
Expand Down Expand Up @@ -393,6 +393,10 @@ repairsAndInsurance.internalRepairs.radio.required.error = Select who pays for i
repairsAndInsurance.externalRepairs.radio.required.error = Select who pays for external repairs
repairsAndInsurance.buildingInsurance.radio.required.error = Select who pays for buildings insurance

#DidYouGetMoneyFromLandlord
didYouGetMoneyFromLandlord.title = Did you get any money from the landlord or previous tenant to take on the lease?
didYouGetMoneyFromLandlord.empty.error = Select yes if you got any money from the landlord or previous tenant to take on the lease

#Rent review
rentReview.months = Months
rentReview.years = Years
Expand Down Expand Up @@ -438,4 +442,4 @@ parkingSpacesOrGaragesNotIncludedInYourRent.agreementDate.month.required.error =
parkingSpacesOrGaragesNotIncludedInYourRent.agreementDate.monthAndYear.required.error = Date this payment was agreed for parking and garages must include a month and year
parkingSpacesOrGaragesNotIncludedInYourRent.agreementDate.year.required.error = Date this payment was agreed for parking and garages must include a year
parkingSpacesOrGaragesNotIncludedInYourRent.agreementDate.invalid.error = Date this payment was agreed for parking and garages must be a real date
parkingSpacesOrGaragesNotIncludedInYourRent.agreementDate.before.1900.error = Year payment was agreed for parking and garages must be 1900 or after
parkingSpacesOrGaragesNotIncludedInYourRent.agreementDate.before.1900.error = Year payment was agreed for parking and garages must be 1900 or after
Loading