Skip to content

Commit

Permalink
BST-111679 Update task list for letting history
Browse files Browse the repository at this point in the history
  • Loading branch information
pangiole committed Dec 17, 2024
1 parent 9d63717 commit 12ba88b
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 36 deletions.
24 changes: 16 additions & 8 deletions app/controllers/lettingHistory/OccupierListController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import navigation.LettingHistoryNavigator
import navigation.identifiers.{OccupierListPageId, OccupierRemovePageId}
import play.api.data.Form
import play.api.i18n.I18nSupport
import play.api.libs.json.Writes
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents, Result}
import repositories.SessionRepo
import uk.gov.hmrc.http.HeaderCarrier
import views.html.genericRemoveConfirmation as RemoveConfirmationView
import views.html.lettingHistory.occupierList as OccupierListView

Expand Down Expand Up @@ -91,17 +93,23 @@ class OccupierListController @Inject() (
theListView(theFormWithErrors, previousRentalPeriod, completedLettings(request.sessionData), backLinkUrl)
)
),
hadMoreOccupiers =>
successful(
navigator.redirect(
currentPage = OccupierListPageId,
updatedSession = request.sessionData,
navigationData = Map("hadMoreOccupiers" -> hadMoreOccupiers.toBoolean)
)
)
answer =>
val answerBool = answer.toBoolean
given Session = request.sessionData
for
savedSession <- eventuallySaveOrUpdateSessionWith(hadMoreOccupier = answerBool)
navigationData = Map("hadMoreOccupiers" -> answerBool)
yield navigator.redirect(currentPage = OccupierListPageId, savedSession, navigationData)
)
}

private def eventuallySaveOrUpdateSessionWith(
hadMoreOccupier: Boolean
)(using session: Session, ws: Writes[Session], hc: HeaderCarrier, ec: ExecutionContext) =
if !hadMoreOccupier && completedLettings(session).isEmpty
then repository.saveOrUpdateSession(withCompletedLettings(false))
else successful(session)

private def renderTheConfirmationViewWith(theForm: Form[AnswersYesNo], occupierDetail: OccupierDetail, index: Int)(
using request: SessionRequest[AnyContent]
) =
Expand Down
22 changes: 15 additions & 7 deletions app/controllers/lettingHistory/ResidentListController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import navigation.LettingHistoryNavigator
import navigation.identifiers.{ResidentListPageId, ResidentRemovePageId}
import play.api.data.Form
import play.api.i18n.I18nSupport
import play.api.libs.json.Writes
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents, Result}
import repositories.SessionRepo
import uk.gov.hmrc.http.HeaderCarrier
import views.html.genericRemoveConfirmation as RemoveConfirmationView
import views.html.lettingHistory.residentList as ResidentListView

Expand Down Expand Up @@ -91,16 +93,22 @@ class ResidentListController @Inject() (
)
),
answer =>
successful(
navigator.redirect(
currentPage = ResidentListPageId,
updatedSession = request.sessionData,
navigationData = Map("hasMoreResidents" -> answer.toBoolean)
)
)
val answerBool = answer.toBoolean
given Session = request.sessionData
for
savedSession <- eventuallySaveOrUpdateSessionWith(hasMoreResidents = answerBool)
navigationData = Map("hasMoreResidents" -> answerBool)
yield navigator.redirect(currentPage = ResidentListPageId, savedSession, navigationData)
)
}

private def eventuallySaveOrUpdateSessionWith(
hasMoreResidents: Boolean
)(using session: Session, ws: Writes[Session], hc: HeaderCarrier, ec: ExecutionContext) =
if !hasMoreResidents && permanentResidents(session).isEmpty
then repository.saveOrUpdateSession(withPermanentResidents(false))
else successful(session)

private def withResidentDetailAt(
index: Int
)(func: ResidentDetail => Future[Result])(using request: SessionRequest[AnyContent]): Future[Result] =
Expand Down
9 changes: 6 additions & 3 deletions app/models/submissions/lettingHistory/LettingHistory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,14 @@ object LettingHistory:
.map { (_, foundIndex) =>
// patch the resident detail if found as existing
lettingHistory
.copy(hasPermanentResidents = Some(true))
.copy(permanentResidents = lettingHistory.permanentResidents.patch(foundIndex, List(residentDetail), 1))
}
.getOrElse {
// not found ... then append it
lettingHistory.copy(permanentResidents = lettingHistory.permanentResidents.:+(residentDetail))
lettingHistory
.copy(hasPermanentResidents = Some(true))
.copy(permanentResidents = lettingHistory.permanentResidents.:+(residentDetail))
}
}
)
Expand Down Expand Up @@ -157,14 +160,14 @@ object LettingHistory:
.copy(name = name, address = address)

val patchedCompletedLettings = lettingHistory.completedLettings.patch(foundIndex, List(patchedOccupier), 1)
val copiedLettingHistory = lettingHistory.copy(completedLettings = patchedCompletedLettings)
val copiedLettingHistory = lettingHistory.copy(hasCompletedLettings = Some(true)).copy(completedLettings = patchedCompletedLettings)
(foundIndex, copiedLettingHistory)
}
.getOrElse {
// not found ... then append it to the list of completed lettings
val lastIndex = lettingHistory.completedLettings.size
val extendedCompletedLettings = lettingHistory.completedLettings.:+(occupierDetail)
val copiedLettingHistory = lettingHistory.copy(completedLettings = extendedCompletedLettings)
val copiedLettingHistory = lettingHistory.copy(hasCompletedLettings = Some(true)).copy(completedLettings = extendedCompletedLettings)
(lastIndex, copiedLettingHistory)
}
}
Expand Down
28 changes: 17 additions & 11 deletions app/models/submissions/lettingHistory/SensitiveLettingHistory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ import uk.gov.hmrc.crypto.Sensitive

case class SensitiveLettingHistory(
hasPermanentResidents: Option[Boolean],
permanentResidents: List[SensitiveResidentDetail],
permanentResidents: Option[List[SensitiveResidentDetail]],
mayHaveMorePermanentResidents: Option[Boolean],
hasCompletedLettings: Option[Boolean],
completedLettings: List[SensitiveOccupierDetail],
completedLettings: Option[List[SensitiveOccupierDetail]],
mayHaveMoreCompletedLettings: Option[Boolean],
intendedLettings: Option[IntendedLettings]
) extends Sensitive[LettingHistory]:

override def decryptedValue: LettingHistory =
LettingHistory(
hasPermanentResidents,
permanentResidents.map(_.decryptedValue),
permanentResidents.fold(Nil)(_.map(_.decryptedValue)),
mayHaveMorePermanentResidents,
hasCompletedLettings,
completedLettings.map(_.decryptedValue),
completedLettings.fold(Nil)(_.map(_.decryptedValue)),
mayHaveMoreCompletedLettings,
intendedLettings
)
Expand All @@ -47,11 +47,17 @@ object SensitiveLettingHistory:
// encryption method
def apply(lettingHistory: LettingHistory): SensitiveLettingHistory =
SensitiveLettingHistory(
lettingHistory.hasPermanentResidents,
lettingHistory.permanentResidents.map(SensitiveResidentDetail(_)),
lettingHistory.mayHaveMorePermanentResidents,
lettingHistory.hasCompletedLettings,
lettingHistory.completedLettings.map(SensitiveOccupierDetail(_)),
lettingHistory.mayHaveMoreCompletedLettings,
lettingHistory.intendedLettings
hasPermanentResidents = lettingHistory.hasPermanentResidents,
permanentResidents =
if lettingHistory.hasPermanentResidents.isEmpty
then None
else Some(lettingHistory.permanentResidents.map(SensitiveResidentDetail(_))),
mayHaveMorePermanentResidents = lettingHistory.mayHaveMorePermanentResidents,
hasCompletedLettings = lettingHistory.hasCompletedLettings,
completedLettings =
if lettingHistory.hasCompletedLettings.isEmpty
then None
else Some(lettingHistory.completedLettings.map(SensitiveOccupierDetail(_))),
mayHaveMoreCompletedLettings = lettingHistory.mayHaveMoreCompletedLettings,
intendedLettings = lettingHistory.intendedLettings
)
53 changes: 53 additions & 0 deletions app/views/lettingHistory/LettingHistoryTaskListHelper.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2024 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 views.lettingHistory

import actions.SessionRequest
import models.Session
import models.submissions.lettingHistory.LettingHistory.{intendedLettings, *}
import play.api.mvc.AnyContent

object LettingHistoryTaskListHelper:

def isTaskComplete(taskId: String)(using request: SessionRequest[?]) =
taskId match
case "residential-tenants" =>
(for
hasPermanentResidents <- hasPermanentResidents(request.sessionData)
doesNotHavePermanentResidents = !hasPermanentResidents
permanentResidentList = permanentResidents(request.sessionData)
yield
if doesNotHavePermanentResidents then "yes"
else if permanentResidentList.nonEmpty then "yes"
else "no"

).getOrElse("no")

case "temporary-occupiers" =>
(for
hasCompletedLettings <- hasCompletedLettings(request.sessionData)
doesNotHaveCompletedLettings = !hasCompletedLettings
completedLettingsList = completedLettings(request.sessionData)
yield
if doesNotHaveCompletedLettings then "yes"
else if completedLettingsList.nonEmpty then "yes"
else "no"

).getOrElse("no")

case _ =>
"no"
43 changes: 36 additions & 7 deletions app/views/taskList.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
@import uk.gov.hmrc.govukfrontend.views.viewmodels.warningtext.WarningText
@import uk.gov.hmrc.govukfrontend.views.viewmodels.content.Text
@import uk.gov.hmrc.govukfrontend.views.html.components.FormWithCSRF
@import views.lettingHistory.LettingHistoryTaskListHelper
@import models.submissions.lettingHistory.LettingHistory


@this(layout: Layout,
Expand Down Expand Up @@ -68,13 +70,14 @@
@section6Completed = @{ session.additionalInformation.flatMap(_.checkYourAnswersAdditionalInformation.map(_.checkYourAnswersAdditionalInformation)) }

@section4AccommodationCompleted = @{session.accommodationDetails.flatMap(_.sectionCompleted).map(_.name)}
@sectionLettingHistoryCompleted = @{ "yes" }

@completedSections = @{
(forType match {
case FOR6048 => Seq(
section1Completed, // 1. Connection to the property
section2Completed, // 2. About you and the property
section4Completed, // 3. Letting history
sectionLettingHistoryCompleted, // 3. Letting history
section4AccommodationCompleted, // 4. Accommodation details
section3Completed, // 5. Trading history
section5Completed, // 6. Your lease or agreement
Expand Down Expand Up @@ -261,11 +264,37 @@ <h2 id="lettingHistory" class="app-task-list__section">
<span class="app-task-list__section-number">3. </span> @messages("label.section.lettingHistory")
</h2>
<ul class="app-task-list__items">
@includes.taskListItem("residential-tenants", "checkYourAnswersLettingHistory.residentialTenants",
controllers.aboutfranchisesorlettings.routes.FranchiseOrLettingsTiedToPropertyController.show(), // TODO: ResidentialTenantsController
section4Completed, // TODO: 3. Letting history
session.aboutTheTradingHistory.flatMap(_.occupationAndAccountingInformation), // TODO: data saved by ResidentialTenantsController
section2Completed.isEmpty
@includes.taskListItem(
taskId = "residential-tenants",
taskNameKey = "checkYourAnswersLettingHistory.residentialTenants",
taskPage = controllers.lettingHistory.routes.PermanentResidentsController.show,
sectionCompletedRadioValue = LettingHistoryTaskListHelper.isTaskComplete("residential-tenants"),
pageAnswer = LettingHistory.hasPermanentResidents(session),
cannotStartYet = false
)
@includes.taskListItem(
taskId = "temporary-occupiers",
taskNameKey = "checkYourAnswersLettingHistory.temporaryOccupiers",
taskPage = controllers.lettingHistory.routes.CompletedLettingsController.show,
sectionCompletedRadioValue = LettingHistoryTaskListHelper.isTaskComplete("temporary-occupiers"),
pageAnswer = LettingHistory.hasCompletedLettings(session),
cannotStartYet = false
)
@includes.taskListItem(
taskId = "letting-intention",
taskNameKey = "checkYourAnswersLettingHistory.lettingIntention",
taskPage = controllers.lettingHistory.routes.HowManyNightsController.show,
sectionCompletedRadioValue = LettingHistoryTaskListHelper.isTaskComplete("letting-intention"),
pageAnswer = LettingHistory.intendedLettings(session),
cannotStartYet = false
)
@includes.taskListItem(
taskId = "advertising-online",
taskNameKey = "checkYourAnswersLettingHistory.advertisingProperty",
taskPage = Call("GET", "/path/to/do-you-advert-online"),
sectionCompletedRadioValue = LettingHistoryTaskListHelper.isTaskComplete("advertising-online"),
pageAnswer = None, // TODO pageAnswer = LettingHistory.advertisingOnline(session),
cannotStartYet = (LettingHistoryTaskListHelper.isTaskComplete("letting-intention") == "yes")
)
</ul>
</li>
Expand Down Expand Up @@ -696,7 +725,7 @@ <h2 id="leaseOrAgreement" class="app-task-list__section">
session.aboutLeaseOrAgreementPartOne.flatMap(_.rentOpenMarketValueDetails).isEmpty
)
}

</ul>
</li>
}
Expand Down
3 changes: 3 additions & 0 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -3680,6 +3680,9 @@ error.changeOccupationAndAccountingInfo.required = Select yes if you would like

# CYA LETTING HISTORY
checkYourAnswersLettingHistory.residentialTenants = Residential tenants
checkYourAnswersLettingHistory.temporaryOccupiers = Temporary occupiers
checkYourAnswersLettingHistory.lettingIntention = Letting intention
checkYourAnswersLettingHistory.advertisingProperty = Advertising the property

# CYA ACCOMMODATION DETAILS
checkYourAnswersAccommodation.accommodationDetails = Accommodation details
Expand Down
3 changes: 3 additions & 0 deletions conf/messages.cy
Original file line number Diff line number Diff line change
Expand Up @@ -3567,6 +3567,9 @@ error.changeOccupationAndAccountingInfo.required = Select yes if you would like

# CYA LETTING HISTORY
checkYourAnswersLettingHistory.residentialTenants = Residential tenants
checkYourAnswersLettingHistory.temporaryOccupiers = Temporary occupiers
checkYourAnswersLettingHistory.lettingIntention = Letting intention
checkYourAnswersLettingHistory.advertisingProperty = Advertising the property

# CYA ACCOMMODATION DETAILS
checkYourAnswersAccommodation.accommodationDetails = Accommodation details
Expand Down

0 comments on commit 12ba88b

Please sign in to comment.