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
Expand Up @@ -36,9 +36,10 @@ import uk.gov.hmrc.ngrraldfrontend.views.html.AgreementView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.{DateTextFields, NGRCharacterCountComponent}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

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

@Singleton
class AgreementController @Inject()(view: AgreementView,
authenticate: AuthRetrievals,
dateTextFields: DateTextFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ import uk.gov.hmrc.ngrraldfrontend.views.html.AgreementVerbalView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.DateTextFields
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

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

@Singleton
class AgreementVerbalController @Inject()(view: AgreementVerbalView,
authenticate: AuthRetrievals,
hasLinkedProperties: PropertyLinkingAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
import uk.gov.hmrc.ngrraldfrontend.views.html.CheckRentFreePeriodView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

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

@Singleton
class CheckRentFreePeriodController @Inject()(checkRentFreePeriodView: CheckRentFreePeriodView,
authenticate : AuthRetrievals,
hasLinkedProperties: PropertyLinkingAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
import uk.gov.hmrc.ngrraldfrontend.views.html.HowMuchIsTotalAnnualRentView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

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

@Singleton
class HowMuchIsTotalAnnualRentController @Inject()(howMuchIsTotalAnnualRentView: HowMuchIsTotalAnnualRentView,
authenticate: AuthRetrievals,
hasLinkedProperties: PropertyLinkingAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ import uk.gov.hmrc.ngrraldfrontend.views.html.LandlordView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.NGRCharacterCountComponent
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

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

@Singleton
class LandlordController @Inject()(view: LandlordView,
authenticate: AuthRetrievals,
hasLinkedProperties: PropertyLinkingAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ import uk.gov.hmrc.ngrraldfrontend.views.html.ProvideDetailsOfFirstSecondRentPer
import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

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

@Singleton
class ProvideDetailsOfFirstSecondRentPeriodController @Inject()(view: ProvideDetailsOfFirstSecondRentPeriodView,
authenticate: AuthRetrievals,
inputText: InputText,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*
* 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, Messages}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.govukfrontend.views.Aliases.Text
import uk.gov.hmrc.govukfrontend.views.viewmodels.*
import uk.gov.hmrc.govukfrontend.views.viewmodels.table.{Table, TableRow}
import uk.gov.hmrc.http.NotFoundException
import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
import uk.gov.hmrc.ngrraldfrontend.models.RaldUserAnswers
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.components.NavBarPageContents.createDefaultNavBar
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentPeriodsForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentPeriodsForm.form
import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
import uk.gov.hmrc.ngrraldfrontend.views.html.RentPeriodView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

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

@Singleton
class RentPeriodsController @Inject()(view: RentPeriodView,
authenticate: AuthRetrievals,
hasLinkedProperties: PropertyLinkingAction,
raldRepo: RaldRepo,
mcc: MessagesControllerComponents
)(implicit appConfig: AppConfig, ec:ExecutionContext) extends FrontendController(mcc) with I18nSupport {

def firstTable(userAnswers: RaldUserAnswers)(implicit messages:Messages): Table =
Table(
rows = Seq(
Seq(
TableRow(
content = Text(messages("rentPeriods.first.startDate"))
),
TableRow(
content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map{ dates =>
dates.firstDateStart
}.getOrElse(""))
)
),
Seq(
TableRow(
content = Text(messages("rentPeriods.first.endDate"))
),
TableRow(
content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map{ dates =>
dates.firstDateEnd
}.getOrElse(""))
)
),
if(userAnswers.provideDetailsOfFirstSecondRentPeriod.nonEmpty){
Seq(
TableRow(
content = Text(messages("rentPeriods.first.rentValue"))
),
TableRow(
content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map { dates =>
dates.firstRentPeriodAmount.get
}.getOrElse(""))
)
)
}else(Seq()),
Seq(
TableRow(
content = Text(messages("rentPeriods.first.doYouPay"))
),
TableRow(
content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map{ dates =>
if(dates.firstRentPeriodRadio == true){
"Yes"
}else{"False"}
}.getOrElse(""))
)
)
),
head = None,
caption = Some(Messages("rentPeriods.first.subheading")),
captionClasses = "govuk-table__caption--m",
firstCellIsHeader = true
)

def secondTable(userAnswers: RaldUserAnswers)(implicit messages: Messages): Table = Table(
rows = Seq(
Seq(
TableRow(
content = Text(messages("rentPeriods.second.startDate"))
),
TableRow(
content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map{ dates =>
dates.secondDateStart
}.getOrElse(""))
)
),
Seq(
TableRow(
content = Text(messages("rentPeriods.second.endDate"))
),
TableRow(
content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map { dates =>
dates.secondDateEnd
}.getOrElse(""))
)
),
Seq(
TableRow(
content = Text(messages("rentPeriods.second.rentValue"))
),
TableRow(
content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map { dates =>
dates.firstRentPeriodAmount.get
}.getOrElse(""))
)
)
),
head = None,
caption = Some(Messages("rentPeriods.first.subheading")),
captionClasses = "govuk-table__caption--m",
firstCellIsHeader = true
)

def show: Action[AnyContent] = {
(authenticate andThen hasLinkedProperties).async { implicit request =>
raldRepo.findByCredId(CredId(request.credId.getOrElse(""))).flatMap {
case Some(answers: RaldUserAnswers) =>
Future.successful(Ok(view(
navigationBarContent = createDefaultNavBar,
selectedPropertyAddress = answers.selectedProperty.addressFull,
form,
firstTable = firstTable(answers),
secondTable = secondTable(answers),
ngrRadio = buildRadios(form, RentPeriodsForm.ngrRadio(form)))))
case None =>
throw new NotFoundException("Couldn't find user Answers")
}
}
}

def submit: Action[AnyContent] = {
(authenticate andThen hasLinkedProperties).async { implicit request =>
form
.bindFromRequest()
.fold(
formWithErrors =>
raldRepo.findByCredId(CredId(request.credId.getOrElse(""))).flatMap {
case Some(answers: RaldUserAnswers) =>
Future.successful(BadRequest(view(
navigationBarContent = createDefaultNavBar,
selectedPropertyAddress = answers.selectedProperty.addressFull,
formWithErrors,
firstTable = firstTable(answers),
secondTable = secondTable(answers),
buildRadios(formWithErrors, RentPeriodsForm.ngrRadio(formWithErrors)))))
case None => throw new NotFoundException("Couldn't find user Answers")
},
rentPeriodsForm =>
raldRepo.insertRentPeriod(
CredId(request.credId.getOrElse("")),
rentPeriodsForm.radioValue
)
Future.successful(Redirect(routes.WhatTypeOfAgreementController.show.url))
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ import uk.gov.hmrc.ngrraldfrontend.views.html.WhatIsYourRentBasedOnView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.NGRCharacterCountComponent
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

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

@Singleton
class WhatIsYourRentBasedOnController @Inject()(view: WhatIsYourRentBasedOnView,
authenticate: AuthRetrievals,
hasLinkedProperties: PropertyLinkingAction,
Expand Down
67 changes: 67 additions & 0 deletions app/uk/gov/hmrc/ngrraldfrontend/models/forms/RentPeriodsForm.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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
/*
* 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 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.govukfrontend.views.Aliases.{Legend, Text}
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings

final case class RentPeriodsForm(radioValue: String)

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

private lazy val radioUnselectedError = "rentPeriods.error.required"
private val rentPeriodsRadio = "rent-periods-radio"

def unapply(rentPeriodsForm: RentPeriodsForm): Option[String] = Some(rentPeriodsForm.radioValue)

def form: Form[RentPeriodsForm] = {
Form(
mapping(
rentPeriodsRadio -> text(radioUnselectedError)
)(RentPeriodsForm.apply)(RentPeriodsForm.unapply)
)
}

private val yes: NGRRadioButtons = NGRRadioButtons(radioContent = "rentPeriods.yes", radioValue = No)
private val no: NGRRadioButtons = NGRRadioButtons(radioContent = "rentPeriods.no", radioValue = Yes)

def ngrRadio(form: Form[RentPeriodsForm])(implicit messages: Messages): NGRRadio =
NGRRadio(ngrTitle = Some(Legend(content = Text(messages("rentPeriods.radio.heading")), classes = "govuk-fieldset__legend--m", isPageHeading = true)), radioGroupName = NGRRadioName("rent-periods-radio"), NGRRadioButtons = Seq(yes, no))

}

Loading