-
Notifications
You must be signed in to change notification settings - Fork 0
Ngr 1088 - provideDetailsOfFirstSecondRentPeriod #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b955926
[NGR-1088] WIP
JakeReid2020 414d219
[NGR-1088] WIP
JakeReid2020 0401099
[NGR-1088] Finishing provideDetailsOfFirstSecondRentPeriod tests, val…
JakeReid2020 e4c5145
[NGR-1088] Code cleanup
JakeReid2020 295f7b9
[NGR-1088] Fixing test
JakeReid2020 02100b6
[NGR-1088] Fixing View and messages
JakeReid2020 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
...ov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodController.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
/* | ||
* 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.data.Form | ||
import play.api.i18n.{I18nSupport, Messages} | ||
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} | ||
import play.twirl.api.Html | ||
import uk.gov.hmrc.govukfrontend.views.Aliases.* | ||
import uk.gov.hmrc.govukfrontend.views.viewmodels.dateinput.DateInput | ||
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.components.* | ||
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.ProvideDetailsOfFirstSecondRentPeriodForm | ||
import uk.gov.hmrc.ngrraldfrontend.models.forms.ProvideDetailsOfFirstSecondRentPeriodForm.form | ||
import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId | ||
import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo | ||
import uk.gov.hmrc.ngrraldfrontend.views.html.ProvideDetailsOfFirstSecondRentPeriodView | ||
import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText | ||
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController | ||
|
||
import javax.inject.Inject | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class ProvideDetailsOfFirstSecondRentPeriodController @Inject()(view: ProvideDetailsOfFirstSecondRentPeriodView, | ||
authenticate: AuthRetrievals, | ||
inputText: InputText, | ||
hasLinkedProperties: PropertyLinkingAction, | ||
raldRepo: RaldRepo, | ||
mcc: MessagesControllerComponents | ||
)(implicit appConfig: AppConfig, ec: ExecutionContext) extends FrontendController(mcc) with I18nSupport { | ||
|
||
def firstDateStartInput()(implicit messages: Messages) : DateInput = DateInput( | ||
id = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date", | ||
namePrefix = Some("provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date"), | ||
fieldset = Some(Fieldset( | ||
legend = Some(Legend( | ||
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.label")), | ||
classes = "govuk-fieldset__legend--s", | ||
isPageHeading = true | ||
)) | ||
)), | ||
hint = Some(Hint( | ||
id = Some("provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.hint"), | ||
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.hint")) | ||
)) | ||
) | ||
|
||
def firstDateEndInput()(implicit messages: Messages): DateInput = DateInput( | ||
id = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date", | ||
namePrefix = Some("provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date"), | ||
fieldset = Some(Fieldset( | ||
legend = Some(Legend( | ||
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.label")), | ||
classes = "govuk-fieldset__legend--s", | ||
isPageHeading = true | ||
)) | ||
)), | ||
hint = Some(Hint( | ||
id = Some("provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.hint"), | ||
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.hint")) | ||
)) | ||
) | ||
|
||
private def firstRentPeriodYesButton(form: Form[ProvideDetailsOfFirstSecondRentPeriodForm])(implicit messages: Messages): NGRRadioButtons = NGRRadioButtons( | ||
radioContent = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.yes", | ||
radioValue = yesPayedRent, | ||
conditionalHtml = Some(inputText( | ||
form = form, | ||
id = "RentPeriodAmount", | ||
name = "RentPeriodAmount", | ||
label = messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.conditional.hint.bold"), | ||
isVisible = true, | ||
hint = Some(Hint( | ||
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.conditional.hint")) | ||
)), | ||
classes = Some("govuk-input--width-10"), | ||
prefix = Some(PrefixOrSuffix(content = Text("£"))) | ||
)) | ||
) | ||
|
||
private def firstRentPeriodRadio(form: Form[ProvideDetailsOfFirstSecondRentPeriodForm])(implicit messages: Messages): NGRRadio = { | ||
val ngrRadioButtons: Seq[NGRRadioButtons] = Seq( | ||
firstRentPeriodYesButton(form), | ||
NGRRadioButtons(radioContent = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.no", radioValue = noRentPayed), | ||
) | ||
NGRRadio( | ||
NGRRadioName("provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio"), | ||
ngrTitle = Some(Legend(content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.label")), classes = "govuk-fieldset__legend--m", isPageHeading = true)), | ||
NGRRadioButtons = ngrRadioButtons | ||
) | ||
} | ||
|
||
def secondDateStartInput()(implicit messages: Messages): DateInput = DateInput( | ||
id = "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date", | ||
namePrefix = Some("provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date"), | ||
fieldset = Some(Fieldset( | ||
legend = Some(Legend( | ||
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.label")), | ||
classes = "govuk-fieldset__legend--s", | ||
isPageHeading = true | ||
)) | ||
)), | ||
hint = Some(Hint( | ||
id = Some("provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.hint"), | ||
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.hint")) | ||
)) | ||
) | ||
|
||
def secondDateEndInput()(implicit messages: Messages): DateInput = DateInput( | ||
id = "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date", | ||
namePrefix = Some("provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date"), | ||
fieldset = Some(Fieldset( | ||
legend = Some(Legend( | ||
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.label")), | ||
classes = "govuk-fieldset__legend--s", | ||
isPageHeading = true | ||
)) | ||
)), | ||
hint = Some(Hint( | ||
id = Some("provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.hint"), | ||
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.hint")) | ||
)) | ||
) | ||
|
||
def show: Action[AnyContent] = { | ||
(authenticate andThen hasLinkedProperties).async { implicit request => | ||
request.propertyLinking.map(property => | ||
Future.successful(Ok(view( | ||
navigationBarContent = createDefaultNavBar, | ||
selectedPropertyAddress = property.addressFull, | ||
form, | ||
firstDateStartInput(), | ||
firstDateEndInput(), | ||
buildRadios(form, firstRentPeriodRadio(form)), | ||
secondDateStartInput(), | ||
secondDateEndInput() | ||
))) | ||
).getOrElse(throw new NotFoundException("Couldn't find property in mongo")) | ||
} | ||
} | ||
|
||
def submit: Action[AnyContent] = { | ||
(authenticate andThen hasLinkedProperties).async { implicit request => | ||
form | ||
.bindFromRequest() | ||
.fold( | ||
formWithErrors => | ||
val correctedFormErrors = formWithErrors.errors.map { formError => | ||
(formError.key, formError.messages) match | ||
case ("", messages) => | ||
formError.copy(key = "RentPeriodAmount") | ||
case _ => | ||
formError | ||
} | ||
val formWithCorrectedErrors = formWithErrors.copy(errors = correctedFormErrors) | ||
|
||
request.propertyLinking.map(property => | ||
Future.successful(BadRequest(view( | ||
createDefaultNavBar, | ||
selectedPropertyAddress = property.addressFull, | ||
formWithCorrectedErrors, | ||
firstDateStartInput(), | ||
firstDateEndInput(), | ||
buildRadios(formWithErrors, firstRentPeriodRadio(formWithCorrectedErrors)), | ||
secondDateStartInput(), | ||
secondDateEndInput() | ||
)))).getOrElse(throw new NotFoundException("Couldn't find property in mongo")), | ||
provideDetailsOfFirstSecondRentPeriodForm => | ||
raldRepo.insertProvideDetailsOfFirstSecondRentPeriod( | ||
CredId(request.credId.getOrElse("")), | ||
provideDetailsOfFirstSecondRentPeriodForm.firstDateStartInput.makeString, | ||
provideDetailsOfFirstSecondRentPeriodForm.firstDateEndInput.makeString, | ||
provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodRadio, | ||
provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodAmount, | ||
provideDetailsOfFirstSecondRentPeriodForm.secondDateStartInput.makeString, | ||
provideDetailsOfFirstSecondRentPeriodForm.secondDateEndInput.makeString, | ||
provideDetailsOfFirstSecondRentPeriodForm.secondHowMuchIsRent, | ||
) | ||
Future.successful(Redirect(routes.WhatIsYourRentBasedOnController.show.url)) | ||
) | ||
} | ||
} | ||
} |
Empty file.
33 changes: 33 additions & 0 deletions
33
app/uk/gov/hmrc/ngrraldfrontend/models/ProvideDetailsOfFirstSecondRentPeriod.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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 | ||
|
||
import play.api.libs.json.{Json, OFormat} | ||
|
||
case class ProvideDetailsOfFirstSecondRentPeriod( | ||
firstDateStart: String, | ||
firstDateEnd: String, | ||
firstRentPeriodRadio: Boolean, | ||
firstRentPeriodAmount: Option[String], | ||
secondDateStart: String, | ||
secondDateEnd: String, | ||
secondHowMuchIsRent: String | ||
) | ||
|
||
object ProvideDetailsOfFirstSecondRentPeriod { | ||
implicit val format: OFormat[ProvideDetailsOfFirstSecondRentPeriod] = Json.format[ProvideDetailsOfFirstSecondRentPeriod] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add this to the messages file please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will also need to provide a message for this error as well provideDetailsOfFirstSecondRentPeriod.second.startDate.required.error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I click Yes in the first rent period to the Do you pay rent in this period, an error doesn't show . It shows all the other errors but nothing for the currency input