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,86 @@
/*
* 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.http.NotFoundException
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.DoYouPayExtraForParkingSpacesForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.DoYouPayExtraForParkingSpacesForm.form
import uk.gov.hmrc.ngrraldfrontend.models.{Landlord, Mode, NormalMode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
import uk.gov.hmrc.ngrraldfrontend.pages.DoYouPayExtraForParkingSpacesPage
import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.DoYouPayExtraForParkingSpacesView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

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

@Singleton
class DoYouPayExtraForParkingSpacesController @Inject()(doYouPayExtraForParkingSpacesView: DoYouPayExtraForParkingSpacesView,
authenticate : AuthRetrievals,
getData: DataRetrievalAction,
navigator: Navigator,
sessionRepository: SessionRepository,
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(DoYouPayExtraForParkingSpacesPage) match {
case None => form
case Some(value) => form.fill(DoYouPayExtraForParkingSpacesForm(if (value) "Yes" else "No"))
}
Future.successful(Ok(doYouPayExtraForParkingSpacesView(
form = preparedForm,
radios = buildRadios(preparedForm, DoYouPayExtraForParkingSpacesForm.ngrRadio(preparedForm)),
propertyAddress = request.property.addressFull,
mode = mode
)))
}
}

def submit(mode: Mode): Action[AnyContent] =
(authenticate andThen getData).async { implicit request =>
form.bindFromRequest().fold(
formWithErrors => {
Future.successful(BadRequest(doYouPayExtraForParkingSpacesView(
form = formWithErrors,
radios = buildRadios(formWithErrors, DoYouPayExtraForParkingSpacesForm.ngrRadio(formWithErrors)),
propertyAddress = request.property.addressFull,
mode = mode
)))
},
radioValue =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId))
.set(DoYouPayExtraForParkingSpacesPage,
radioValue.radioValue match
case "Yes" => true
case _ => false
)
)
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(navigator.nextPage(DoYouPayExtraForParkingSpacesPage, mode, updatedAnswers))
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import uk.gov.hmrc.ngrraldfrontend.models.{Mode, NGRDate, NormalMode, ProvideDet
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.ProvideDetailsOfFirstSecondRentPeriodForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.ProvideDetailsOfFirstSecondRentPeriodForm.form
import uk.gov.hmrc.ngrraldfrontend.models.forms.ProvideDetailsOfFirstSecondRentPeriodForm._
import uk.gov.hmrc.ngrraldfrontend.utils.DateKeyFinder
import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
import uk.gov.hmrc.ngrraldfrontend.pages.ProvideDetailsOfFirstSecondRentPeriodPage
Expand Down Expand Up @@ -148,15 +148,7 @@ class ProvideDetailsOfFirstSecondRentPeriodController @Inject()(view: ProvideDet
(authenticate andThen getData).async { implicit request =>
val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(ProvideDetailsOfFirstSecondRentPeriodPage) match {
case None => form
case Some(value) => form.fill(ProvideDetailsOfFirstSecondRentPeriodForm(NGRDate.fromString(value.firstDateStart),NGRDate.fromString(value.firstDateEnd),value.firstRentPeriodRadio match {
case true => "yesPayedRent"
case false => "noRentPayed"
}, value.firstRentPeriodAmount match {
case Some(value) => Some(value)
case None => None
},
NGRDate.fromString(value.secondDateStart),NGRDate.fromString(value.secondDateEnd),BigDecimal(value.secondHowMuchIsRent)))

case Some(value) => answerToForm(value)
}
Future.successful(Ok(view(
selectedPropertyAddress = request.property.addressFull,
Expand Down Expand Up @@ -204,22 +196,8 @@ class ProvideDetailsOfFirstSecondRentPeriodController @Inject()(view: ProvideDet
mode
))),
provideDetailsOfFirstSecondRentPeriodForm =>
val provideDetailsOfFirstSecondRentPeriod: ProvideDetailsOfFirstSecondRentPeriod = ProvideDetailsOfFirstSecondRentPeriod(
provideDetailsOfFirstSecondRentPeriodForm.firstDateStartInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.firstDateEndInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodRadio match {
case "yesPayedRent" => true
case _ => false
},
provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodAmount match {
case Some(value) => Some(value)
case None => None
},
provideDetailsOfFirstSecondRentPeriodForm.secondDateStartInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.secondDateEndInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.secondHowMuchIsRent.toString())
for {
updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(ProvideDetailsOfFirstSecondRentPeriodPage, provideDetailsOfFirstSecondRentPeriod))
updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(ProvideDetailsOfFirstSecondRentPeriodPage, formToAnswers(provideDetailsOfFirstSecondRentPeriodForm)))
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(navigator.nextPage(ProvideDetailsOfFirstSecondRentPeriodPage, NormalMode, updatedAnswers))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import uk.gov.hmrc.govukfrontend.views.viewmodels.table.{Table, TableRow}
import uk.gov.hmrc.http.NotFoundException
import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
import uk.gov.hmrc.ngrraldfrontend.models.{Mode, ProvideDetailsOfFirstSecondRentPeriod}
import uk.gov.hmrc.ngrraldfrontend.models.{Mode, NGRDate, ProvideDetailsOfFirstSecondRentPeriod}
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentPeriodsForm
Expand Down Expand Up @@ -58,7 +58,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
content = Text(messages("rentPeriods.first.startDate"))
),
TableRow(
content = Text(rentPeriods.firstDateStart),
content = Text(NGRDate.formatDate(rentPeriods.firstDateStart)),
attributes = Map(
"id" -> "first-period-start-date-id"
)
Expand All @@ -69,7 +69,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
content = Text(messages("rentPeriods.first.endDate"))
),
TableRow(
content = Text(rentPeriods.firstDateEnd),
content = Text(NGRDate.formatDate(rentPeriods.firstDateEnd)),
attributes = Map(
"id" -> "first-period-end-date-id"
)
Expand Down Expand Up @@ -119,7 +119,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
content = Text(messages("rentPeriods.second.startDate"))
),
TableRow(
content = Text(rentPeriods.secondDateStart),
content = Text(NGRDate.formatDate(rentPeriods.secondDateStart)),
attributes = Map(
"id" -> "second-period-start-date-id"
)
Expand All @@ -130,7 +130,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
content = Text(messages("rentPeriods.second.endDate"))
),
TableRow(
content = Text(rentPeriods.secondDateEnd),
content = Text(NGRDate.formatDate(rentPeriods.secondDateEnd)),
attributes = Map(
"id" -> "second-period-end-date-id"
)
Expand All @@ -141,7 +141,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
content = Text(messages("rentPeriods.second.rentValue"))
),
TableRow(
content = Text(rentPeriods.secondHowMuchIsRent),
content = Text(formatRentValue(rentPeriods.secondHowMuchIsRent.toDouble)),
attributes = Map(
"id" -> "second-period-rent-value-id"
)
Expand Down
4 changes: 2 additions & 2 deletions app/uk/gov/hmrc/ngrraldfrontend/models/NGRMonthYear.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ object NGRMonthYear {
}

def fromString(dateString: String): NGRMonthYear = {
val parts = dateString.split("-").map(_.toInt)
NGRMonthYear(parts(1).toString, parts(0).toString)
val parts = dateString.split("-")
NGRMonthYear(parts(1), parts(0))
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.Messages
import play.api.libs.json.{Json, OFormat}
import uk.gov.hmrc.ngrraldfrontend.models.components.{NGRRadio, NGRRadioName}
import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings

case class DoYouPayExtraForParkingSpacesForm(radioValue: String)

object DoYouPayExtraForParkingSpacesForm extends Mappings {

implicit val format: OFormat[DoYouPayExtraForParkingSpacesForm] = Json.format[DoYouPayExtraForParkingSpacesForm]

private lazy val radioUnselectedError = "doYouPayExtraForParkingSpaces.required.error"
val payExtraRadio = "payExtra"

def unapply(doYouPayExtraForParkingSpacesForm: DoYouPayExtraForParkingSpacesForm): Option[String] = Some(doYouPayExtraForParkingSpacesForm.radioValue)

def form: Form[DoYouPayExtraForParkingSpacesForm] = {
Form(
mapping(
payExtraRadio -> radioText(radioUnselectedError)
)(DoYouPayExtraForParkingSpacesForm.apply)(DoYouPayExtraForParkingSpacesForm.unapply)
)
}

def ngrRadio(form: Form[DoYouPayExtraForParkingSpacesForm])(implicit messages: Messages): NGRRadio =
NGRRadio(NGRRadioName(payExtraRadio), NGRRadioButtons = Seq(NGRRadio.yesButton, NGRRadio.noButton))

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,39 @@ object ProvideDetailsOfFirstSecondRentPeriodForm extends CommonFormValidators wi
provideDetailsOfFirstSecondRentPeriodForm.secondDateEndInput,
provideDetailsOfFirstSecondRentPeriodForm.secondHowMuchIsRent
)


def answerToForm(value: ProvideDetailsOfFirstSecondRentPeriod): Form[ProvideDetailsOfFirstSecondRentPeriodForm] =
form.fill(
ProvideDetailsOfFirstSecondRentPeriodForm(
NGRDate.fromString(value.firstDateStart),
NGRDate.fromString(value.firstDateEnd),
value.firstRentPeriodRadio match {
case true => "yesPayedRent"
case false => "noRentPayed"
},
value.firstRentPeriodAmount,
NGRDate.fromString(value.secondDateStart),
NGRDate.fromString(value.secondDateEnd),
BigDecimal(value.secondHowMuchIsRent))
)

def formToAnswers(provideDetailsOfFirstSecondRentPeriodForm: ProvideDetailsOfFirstSecondRentPeriodForm): ProvideDetailsOfFirstSecondRentPeriod =
ProvideDetailsOfFirstSecondRentPeriod(
provideDetailsOfFirstSecondRentPeriodForm.firstDateStartInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.firstDateEndInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodRadio match {
case "yesPayedRent" => true
case _ => false
},
provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodAmount match {
case Some(value) if provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodRadio.equals("yesPayedRent") => Some(value)
case _ => None
},
provideDetailsOfFirstSecondRentPeriodForm.secondDateStartInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.secondDateEndInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.secondHowMuchIsRent.toString()
)

private def firstRentPeriodAmountValidation[A]: Constraint[A] =
Constraint((input: A) =>
val provideDetailsOfFirstSecondRentPeriodForm = input.asInstanceOf[ProvideDetailsOfFirstSecondRentPeriodForm]
Expand Down
15 changes: 12 additions & 3 deletions app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,26 @@ class Navigator @Inject()() {
answers.get(DoesYourRentIncludeParkingPage) match {
case Some(value) => value match {
case "Yes" => uk.gov.hmrc.ngrraldfrontend.controllers.routes.HowManyParkingSpacesOrGaragesIncludedInRentController.show(NormalMode)
case _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode)
case _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.DoYouPayExtraForParkingSpacesController.show(NormalMode)
}
case None => throw new NotFoundException("Failed to find answers")
}
case HowManyParkingSpacesOrGaragesIncludedInRentPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode)
case HowManyParkingSpacesOrGaragesIncludedInRentPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.DoYouPayExtraForParkingSpacesController.show(NormalMode)
case InterimSetByTheCourtPage => answers =>
answers.get(ProvideDetailsOfFirstSecondRentPeriodPage) match {
case Some(_) => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeController.show(NormalMode)
case None => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode)
case None => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode)
}
case RentFreePeriodPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeStartController.show(NormalMode)
//TODO need to connect to next pages when they are done
case DoYouPayExtraForParkingSpacesPage => answers =>
answers.get(DoYouPayExtraForParkingSpacesPage) match {
case Some(value) => value match {
case true => uk.gov.hmrc.ngrraldfrontend.controllers.routes.DoYouPayExtraForParkingSpacesController.show(NormalMode)
case _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.DoYouPayExtraForParkingSpacesController.show(NormalMode)
}
case None => throw new NotFoundException("Failed to find answers")
}
}

//TODO change to check your answers page
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 DoYouPayExtraForParkingSpacesPage extends QuestionPage[Boolean]{

override def path: JsPath = JsPath \ toString

override def toString: String = "doYouPayExtraForParkingSpacesNotIncludedInRent"

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


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

@(form:Form[DoYouPayExtraForParkingSpacesForm], radios: Radios, propertyAddress: String,mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)

@layout(pageTitle = Some(messages("doYouPayExtraForParkingSpaces.title")), showBackLink = true, fullWidth = false) {
@formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.DoYouPayExtraForParkingSpacesController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
<span class="govuk-caption-m">@propertyAddress</span>
<h1 class="govuk-heading-l">@messages("doYouPayExtraForParkingSpaces.title")</h1>
@govukRadios(radios)
@saveAndContinueButton(msg = messages("service.continue"), isStartButton = false)
}
}
Loading