Skip to content

Commit

Permalink
Fix/prsd 804 remove extraneous data (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
AEPR authored Feb 27, 2025
1 parent d3323eb commit f43feb5
Show file tree
Hide file tree
Showing 7 changed files with 591 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class Journey<T : StepId>(

open fun getUnreachableStepRedirect(journeyData: JourneyData) = "/${journeyType.urlPathSegment}/${initialStepId.urlPathSegment}"

fun getStepId(stepName: String): StepId {
fun getStepId(stepName: String): T {
val step = steps.singleOrNull { step -> step.id.urlPathSegment == stepName }
if (step == null) {
throw ResponseStatusException(
Expand Down Expand Up @@ -85,7 +85,7 @@ abstract class Journey<T : StepId>(
}

fun updateJourneyDataAndGetViewNameOrRedirect(
stepId: StepId,
stepId: T,
pageData: PageData,
model: Model,
subPageNumber: Int?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ import uk.gov.communities.prsdb.webapp.services.LandlordService
class LandlordRegistrationJourney(
validator: Validator,
journeyDataService: JourneyDataService,
addressLookupService: AddressLookupService,
addressDataService: AddressDataService,
landlordService: LandlordService,
absoluteUrlProvider: AbsoluteUrlProvider,
emailNotificationService: EmailNotificationService<LandlordRegistrationConfirmationEmail>,
val addressLookupService: AddressLookupService,
val addressDataService: AddressDataService,
val landlordService: LandlordService,
val absoluteUrlProvider: AbsoluteUrlProvider,
val emailNotificationService: EmailNotificationService<LandlordRegistrationConfirmationEmail>,
) : Journey<LandlordRegistrationStepId>(
journeyType = JourneyType.LANDLORD_REGISTRATION,
validator = validator,
Expand All @@ -59,40 +59,30 @@ class LandlordRegistrationJourney(
listOf(
JourneySection(privacyNoticeTasks(), "registerAsALandlord.section.privacyNotice.heading"),
JourneySection(
registerDetailsTasks(addressLookupService, addressDataService),
registerDetailsTasks(),
"registerAsALandlord.section.yourDetails.heading",
),
JourneySection(
checkAndSubmitDetailsTasks(addressDataService, landlordService, absoluteUrlProvider, emailNotificationService),
checkAndSubmitDetailsTasks(),
"registerAsALandlord.section.checkAndSubmit.heading",
),
)

private fun privacyNoticeTasks(): List<JourneyTask<LandlordRegistrationStepId>> = emptyList()

private fun registerDetailsTasks(
addressLookupService: AddressLookupService,
addressDataService: AddressDataService,
): List<JourneyTask<LandlordRegistrationStepId>> =
private fun registerDetailsTasks(): List<JourneyTask<LandlordRegistrationStepId>> =
listOf(
identityTask(),
JourneyTask.withOneStep(emailStep()),
JourneyTask.withOneStep(phoneNumberStep()),
JourneyTask.withOneStep(countryOfResidenceStep()),
landlordAddressesTask(addressLookupService, addressDataService),
landlordAddressesTask(),
)

private fun checkAndSubmitDetailsTasks(
addressDataService: AddressDataService,
landlordService: LandlordService,
absoluteUrlProvider: AbsoluteUrlProvider,
emailNotificationService: EmailNotificationService<LandlordRegistrationConfirmationEmail>,
): List<JourneyTask<LandlordRegistrationStepId>> =
private fun checkAndSubmitDetailsTasks(): List<JourneyTask<LandlordRegistrationStepId>> =
listOf(
JourneyTask.withOneStep(checkAnswersStep(addressDataService)),
JourneyTask.withOneStep(
declarationStep(journeyDataService, landlordService, addressDataService, absoluteUrlProvider, emailNotificationService),
),
JourneyTask.withOneStep(checkAnswersStep()),
JourneyTask.withOneStep(declarationStep()),
)

private fun identityTask() =
Expand All @@ -106,21 +96,19 @@ class LandlordRegistrationJourney(
),
)

private fun landlordAddressesTask(
addressLookupService: AddressLookupService,
addressDataService: AddressDataService,
) = JourneyTask(
LandlordRegistrationStepId.LookupAddress,
setOf(
lookupAddressStep(),
selectAddressStep(addressLookupService, addressDataService),
manualAddressStep(),
nonEnglandOrWalesAddressStep(),
lookupContactAddressStep(),
selectContactAddressStep(addressLookupService, addressDataService),
manualContactAddressStep(),
),
)
private fun landlordAddressesTask() =
JourneyTask(
LandlordRegistrationStepId.LookupAddress,
setOf(
lookupAddressStep(),
selectAddressStep(),
manualAddressStep(),
nonEnglandOrWalesAddressStep(),
lookupContactAddressStep(),
selectContactAddressStep(),
manualContactAddressStep(),
),
)

private fun verifyIdentityStep() =
Step(
Expand Down Expand Up @@ -298,32 +286,30 @@ class LandlordRegistrationJourney(
saveAfterSubmit = false,
)

private fun selectAddressStep(
addressLookupService: AddressLookupService,
addressDataService: AddressDataService,
) = Step(
id = LandlordRegistrationStepId.SelectAddress,
page =
SelectAddressPage(
formModel = SelectAddressFormModel::class,
templateName = "forms/selectAddressForm",
content =
mapOf(
"title" to "registerAsALandlord.title",
"fieldSetHeading" to "forms.selectAddress.fieldSetHeading",
"submitButtonText" to "forms.buttons.useThisAddress",
"searchAgainUrl" to
"/${REGISTER_LANDLORD_JOURNEY_URL}/" +
LandlordRegistrationStepId.LookupAddress.urlPathSegment,
),
lookupAddressPathSegment = LandlordRegistrationStepId.LookupAddress.urlPathSegment,
addressLookupService = addressLookupService,
addressDataService = addressDataService,
displaySectionHeader = true,
),
nextAction = { journeyData, _ -> selectAddressNextAction(journeyData) },
saveAfterSubmit = false,
)
private fun selectAddressStep() =
Step(
id = LandlordRegistrationStepId.SelectAddress,
page =
SelectAddressPage(
formModel = SelectAddressFormModel::class,
templateName = "forms/selectAddressForm",
content =
mapOf(
"title" to "registerAsALandlord.title",
"fieldSetHeading" to "forms.selectAddress.fieldSetHeading",
"submitButtonText" to "forms.buttons.useThisAddress",
"searchAgainUrl" to
"/${REGISTER_LANDLORD_JOURNEY_URL}/" +
LandlordRegistrationStepId.LookupAddress.urlPathSegment,
),
lookupAddressPathSegment = LandlordRegistrationStepId.LookupAddress.urlPathSegment,
addressLookupService = addressLookupService,
addressDataService = addressDataService,
displaySectionHeader = true,
),
nextAction = { journeyData, _ -> selectAddressNextAction(journeyData) },
saveAfterSubmit = false,
)

private fun manualAddressStep() =
Step(
Expand Down Expand Up @@ -395,36 +381,34 @@ class LandlordRegistrationJourney(
saveAfterSubmit = false,
)

private fun selectContactAddressStep(
addressLookupService: AddressLookupService,
addressDataService: AddressDataService,
) = Step(
id = LandlordRegistrationStepId.SelectContactAddress,
page =
SelectAddressPage(
formModel = SelectAddressFormModel::class,
templateName = "forms/selectAddressForm",
content =
mapOf(
"title" to "registerAsALandlord.title",
"fieldSetHeading" to "forms.selectAddress.fieldSetHeading",
"submitButtonText" to "forms.buttons.continue",
"searchAgainUrl" to
"/${REGISTER_LANDLORD_JOURNEY_URL}/" +
LandlordRegistrationStepId.LookupContactAddress.urlPathSegment,
),
lookupAddressPathSegment = LandlordRegistrationStepId.LookupContactAddress.urlPathSegment,
addressLookupService = addressLookupService,
addressDataService = addressDataService,
displaySectionHeader = true,
),
nextAction = { journeyData, _ ->
selectContactAddressNextAction(
journeyData,
)
},
saveAfterSubmit = false,
)
private fun selectContactAddressStep() =
Step(
id = LandlordRegistrationStepId.SelectContactAddress,
page =
SelectAddressPage(
formModel = SelectAddressFormModel::class,
templateName = "forms/selectAddressForm",
content =
mapOf(
"title" to "registerAsALandlord.title",
"fieldSetHeading" to "forms.selectAddress.fieldSetHeading",
"submitButtonText" to "forms.buttons.continue",
"searchAgainUrl" to
"/${REGISTER_LANDLORD_JOURNEY_URL}/" +
LandlordRegistrationStepId.LookupContactAddress.urlPathSegment,
),
lookupAddressPathSegment = LandlordRegistrationStepId.LookupContactAddress.urlPathSegment,
addressLookupService = addressLookupService,
addressDataService = addressDataService,
displaySectionHeader = true,
),
nextAction = { journeyData, _ ->
selectContactAddressNextAction(
journeyData,
)
},
saveAfterSubmit = false,
)

private fun manualContactAddressStep() =
Step(
Expand All @@ -450,54 +434,40 @@ class LandlordRegistrationJourney(
saveAfterSubmit = false,
)

private fun checkAnswersStep(addressDataService: AddressDataService) =
private fun checkAnswersStep() =
Step(
id = LandlordRegistrationStepId.CheckAnswers,
page = LandlordRegistrationCheckAnswersPage(addressDataService, displaySectionHeader = true),
nextAction = { _, _ -> Pair(LandlordRegistrationStepId.Declaration, null) },
saveAfterSubmit = false,
)

private fun declarationStep(
journeyDataService: JourneyDataService,
landlordService: LandlordService,
addressDataService: AddressDataService,
absoluteUrlProvider: AbsoluteUrlProvider,
emailNotificationService: EmailNotificationService<LandlordRegistrationConfirmationEmail>,
) = Step(
id = LandlordRegistrationStepId.Declaration,
page =
Page(
formModel = DeclarationFormModel::class,
templateName = "forms/declarationForm",
content =
mapOf(
"title" to "registerAsALandlord.title",
"bulletOneFineAmount" to "forms.declaration.fines.bullet.one.landlordRegistrationJourneyAmount",
"bulletTwoFineAmount" to "forms.declaration.fines.bullet.two.landlordRegistrationJourneyAmount",
"options" to
listOf(
CheckboxViewModel(
value = "true",
labelMsgKey = "forms.declaration.checkbox.label",
private fun declarationStep() =
Step(
id = LandlordRegistrationStepId.Declaration,
page =
Page(
formModel = DeclarationFormModel::class,
templateName = "forms/declarationForm",
content =
mapOf(
"title" to "registerAsALandlord.title",
"bulletOneFineAmount" to "forms.declaration.fines.bullet.one.landlordRegistrationJourneyAmount",
"bulletTwoFineAmount" to "forms.declaration.fines.bullet.two.landlordRegistrationJourneyAmount",
"options" to
listOf(
CheckboxViewModel(
value = "true",
labelMsgKey = "forms.declaration.checkbox.label",
),
),
),
"submitButtonText" to "forms.buttons.confirmAndCompleteRegistration",
),
shouldDisplaySectionHeader = true,
),
handleSubmitAndRedirect = { journeyData, _ ->
declarationHandleSubmitAndRedirect(
journeyData,
journeyDataService,
landlordService,
addressDataService,
absoluteUrlProvider,
emailNotificationService,
)
},
saveAfterSubmit = false,
)
"submitButtonText" to "forms.buttons.confirmAndCompleteRegistration",
),
shouldDisplaySectionHeader = true,
),
handleSubmitAndRedirect = { _, _ -> declarationHandleSubmitAndRedirect() },
saveAfterSubmit = false,
)

private fun countryOfResidenceNextAction(journeyData: JourneyData): Pair<LandlordRegistrationStepId, Int?> =
if (LandlordRegistrationJourneyDataHelper.getLivesInEnglandOrWales(journeyData)!!) {
Expand All @@ -521,14 +491,8 @@ class LandlordRegistrationJourney(
Pair(LandlordRegistrationStepId.CheckAnswers, null)
}

private fun declarationHandleSubmitAndRedirect(
journeyData: JourneyData,
journeyDataService: JourneyDataService,
landlordService: LandlordService,
addressDataService: AddressDataService,
absoluteUrlProvider: AbsoluteUrlProvider,
emailNotificationService: EmailNotificationService<LandlordRegistrationConfirmationEmail>,
): String {
private fun declarationHandleSubmitAndRedirect(): String {
val journeyData = last().filteredJourneyData
val landlord =
landlordService.createLandlord(
baseUserId = SecurityContextHolder.getContext().authentication.name,
Expand Down
Loading

0 comments on commit f43feb5

Please sign in to comment.