Skip to content
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

Misuv 6801 proto: WIP / DO NOT MERGE #2024

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion app/audit/models/IncomeSourceReportingMethodAuditModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package audit.models

import audit.Utilities
import auth.MtdItUser
import enums.IncomeSourceTypeName
import play.api.libs.json.{JsObject, JsValue, Json}

case class IncomeSourceReportingMethodAuditModel(isSuccessful: Boolean,
journeyType: String,
journeyType: IncomeSourceTypeName,
operationType: String,
reportingMethodChangeTo: String,
taxYear: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AddIncomeSourceStartDateCheckController @Inject()(authenticate: Authentica
addIncomeSourceStartDateCheckView(
isAgent = isAgent,
backUrl = getBackUrl(incomeSourceType, isAgent, isChange),
form = form(incomeSourceType.addStartDateCheckMessagesPrefix),
form = form(incomeSourceType.lang.addStartDateCheckMessagesPrefix),
postAction = getPostAction(incomeSourceType, isAgent, isChange),
incomeSourceStartDate = longDate(startDate).toLongDate
)
Expand All @@ -119,7 +119,7 @@ class AddIncomeSourceStartDateCheckController @Inject()(authenticate: Authentica
isChange: Boolean)
(implicit mtdItUser: MtdItUser[_]): Future[Result] = {

val messagesPrefix = incomeSourceType.addStartDateCheckMessagesPrefix
val messagesPrefix = incomeSourceType.lang.addStartDateCheckMessagesPrefix
withIncomeSourcesFS {
getStartDate(incomeSourceType).flatMap {
case Some(startDate) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class AddIncomeSourceStartDateController @Inject()(authenticate: AuthenticationP
isChange: Boolean)
(implicit user: MtdItUser[_]): Future[Result] = {

val messagesPrefix = incomeSourceType.startDateMessagesPrefix
val messagesPrefix = incomeSourceType.lang.startDateMessagesPrefix

withIncomeSourcesFSWithSessionCheck(JourneyType(Add, incomeSourceType)) {
if (!isChange && incomeSourceType.equals(UkProperty) || !isChange && incomeSourceType.equals(ForeignProperty)) {
Expand Down Expand Up @@ -125,7 +125,7 @@ class AddIncomeSourceStartDateController @Inject()(authenticate: AuthenticationP
isChange: Boolean)
(implicit user: MtdItUser[_]): Future[Result] = {

val messagesPrefix = incomeSourceType.startDateMessagesPrefix
val messagesPrefix = incomeSourceType.lang.startDateMessagesPrefix

withIncomeSourcesFS {
form(messagesPrefix).bindFromRequest().fold(
Expand Down
40 changes: 20 additions & 20 deletions app/controllers/incomeSources/add/IncomeSourceAddedController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import controllers.agent.predicates.ClientConfirmedController
import controllers.predicates._
import enums.IncomeSourceJourney.{ForeignProperty, IncomeSourceType, SelfEmployment, UkProperty}
import enums.JourneyType.{Add, JourneyType}
import models.incomeSourceDetails.{AddIncomeSourceData, UIJourneySessionData}
import models.core.IncomeSourceId
import models.core.IncomeSourceId.mkIncomeSourceId
import models.core.IncomeSourceT
import models.incomeSourceDetails.{AddIncomeSourceData, UIJourneySessionData}
import play.api.Logger
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents, Result}
Expand All @@ -34,7 +34,6 @@ import uk.gov.hmrc.auth.core.AuthorisedFunctions
import uk.gov.hmrc.http.HeaderCarrier
import utils.{IncomeSourcesUtils, JourneyChecker}
import views.html.incomeSources.add.IncomeSourceAddedObligations

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

Expand Down Expand Up @@ -70,21 +69,19 @@ class IncomeSourceAddedController @Inject()(authenticate: AuthenticationPredicat
}
}

private def handleRequest(isAgent: Boolean, incomeSourceType: IncomeSourceType)(implicit user: MtdItUser[_], ec: ExecutionContext): Future[Result] = {

private def handleRequest(isAgent: Boolean,
incomeSourceType: IncomeSourceType)
(implicit user: MtdItUser[_], ec: ExecutionContext): Future[Result] = {
withIncomeSourcesFSWithSessionCheck(JourneyType(Add, incomeSourceType)) {

sessionService.getMongoKeyTyped[String](AddIncomeSourceData.createdIncomeSourceIdField, JourneyType(Add, incomeSourceType)).flatMap {
case Right(Some(id)) =>

val incomeSourceId: IncomeSourceId = mkIncomeSourceId(id)

incomeSourceDetailsService.getIncomeSourceFromUser(incomeSourceType, incomeSourceId) match {
val iss = IncomeSourceT( mkIncomeSourceId(id), incomeSourceType )
incomeSourceDetailsService.getIncomeSourceFromUser( iss ) match {
case Some((startDate, businessName)) =>
val showPreviousTaxYears: Boolean = startDate.isBefore(dateService.getCurrentTaxYearStart())
handleSuccess(incomeSourceId, incomeSourceType, businessName, showPreviousTaxYears, isAgent)
handleSuccess(iss, businessName, showPreviousTaxYears, isAgent)
case None => Logger("application").error(
s"${if (isAgent) "[Agent]"}" + s"[IncomeSourceAddedController][handleRequest] - unable to find incomeSource by id: $incomeSourceId, IncomeSourceType: $incomeSourceType")
s"${if (isAgent) "[Agent]"}" + s"[IncomeSourceAddedController][handleRequest] - unable to find incomeSource by id: ${iss.id}, IncomeSourceType: $incomeSourceType")
if (isAgent) Future(itvcErrorHandlerAgent.showInternalServerError())
else Future(itvcErrorHandler.showInternalServerError())
}
Expand All @@ -101,28 +98,31 @@ class IncomeSourceAddedController @Inject()(authenticate: AuthenticationPredicat
}
}

def handleSuccess(incomeSourceId: IncomeSourceId, incomeSourceType: IncomeSourceType, businessName: Option[String], showPreviousTaxYears: Boolean, isAgent: Boolean)(implicit user: MtdItUser[_], ec: ExecutionContext): Future[Result] = {
updateMongoAdded(incomeSourceType).flatMap {
def handleSuccess(incomeSource: IncomeSourceT,
businessName: Option[String],
showPreviousTaxYears: Boolean,
isAgent: Boolean)(implicit user: MtdItUser[_], ec: ExecutionContext): Future[Result] = {
updateMongoAdded(incomeSource.incomeSourceType).flatMap {
case false => Logger("application").error(s"${if (isAgent) "[Agent]"}" +
s"Error retrieving data from session, IncomeSourceType: $incomeSourceType")
s"Error retrieving data from session, IncomeSourceType: $incomeSource.incomeSourceType")
Future.successful {
if (isAgent) itvcErrorHandlerAgent.showInternalServerError()
else itvcErrorHandler.showInternalServerError()
}
case true => incomeSourceType match {
case true => incomeSource.incomeSourceType match {
case SelfEmployment =>
businessName match {
case Some(businessName) => nextUpdatesService.getObligationsViewModel(incomeSourceId.value, showPreviousTaxYears) map { viewModel =>
case Some(businessName) => nextUpdatesService.getObligationsViewModel(incomeSource.id.value, showPreviousTaxYears) map { viewModel =>
Ok(obligationsView(businessName = Some(businessName), sources = viewModel, isAgent = isAgent, incomeSourceType = SelfEmployment))
}
case None => nextUpdatesService.getObligationsViewModel(incomeSourceId.value, showPreviousTaxYears) map { viewModel =>
case None => nextUpdatesService.getObligationsViewModel(incomeSource.id.value, showPreviousTaxYears) map { viewModel =>
Ok(obligationsView(sources = viewModel, isAgent = isAgent, incomeSourceType = SelfEmployment))
}
}
case UkProperty => nextUpdatesService.getObligationsViewModel(incomeSourceId.value, showPreviousTaxYears) map { viewModel =>
case UkProperty => nextUpdatesService.getObligationsViewModel(incomeSource.id.value, showPreviousTaxYears) map { viewModel =>
Ok(obligationsView(viewModel, isAgent = isAgent, incomeSourceType = UkProperty))
}
case ForeignProperty => nextUpdatesService.getObligationsViewModel(incomeSourceId.value, showPreviousTaxYears) map { viewModel =>
case ForeignProperty => nextUpdatesService.getObligationsViewModel(incomeSource.id.value, showPreviousTaxYears) map { viewModel =>
Ok(obligationsView(viewModel, isAgent = isAgent, incomeSourceType = ForeignProperty))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import controllers.predicates._
import enums.IncomeSourceJourney.{IncomeSourceType, SelfEmployment}
import enums.JourneyType.{Add, JourneyType}
import forms.incomeSources.add.IncomeSourceReportingMethodForm
import models.core.IncomeSourceId
import models.core.{IncomeSourceId, IncomeSourceT}
import models.core.IncomeSourceId.mkIncomeSourceId
import models.incomeSourceDetails.viewmodels.IncomeSourceReportingMethodViewModel
import models.incomeSourceDetails.{AddIncomeSourceData, LatencyDetails, LatencyYear}
Expand Down Expand Up @@ -109,7 +109,8 @@ class IncomeSourceReportingMethodController @Inject()(val authenticate: Authenti

sessionService.getMongoKeyTyped[String](AddIncomeSourceData.createdIncomeSourceIdField, JourneyType(Add, incomeSourceType)).flatMap {
case Right(Some(id)) =>
handleIncomeSourceIdRetrievalSuccess(incomeSourceType = incomeSourceType, id = id, isAgent = isAgent)
val iss : IncomeSourceT = IncomeSourceT(mkIncomeSourceId(id), incomeSourceType)
handleIncomeSourceIdRetrievalSuccess(iss, isAgent = isAgent)
case Right(_) => Future.failed(new Error("[IncomeSourceReportingMethodController][handleSubmit] Could not find an incomeSourceId in session data"))
case Left(ex) => Future.failed(ex)
}.recover {
Expand All @@ -123,14 +124,14 @@ class IncomeSourceReportingMethodController @Inject()(val authenticate: Authenti
}


private def handleIncomeSourceIdRetrievalSuccess(incomeSourceType: IncomeSourceType, id: String, isAgent: Boolean)(implicit user: MtdItUser[_], hc: HeaderCarrier): Future[Result] = {
private def handleIncomeSourceIdRetrievalSuccess(iss: IncomeSourceT, isAgent: Boolean)
(implicit user: MtdItUser[_], hc: HeaderCarrier): Future[Result] = {

val cannotGoBackRedirect = if (isAgent) controllers.incomeSources.add.routes.YouCannotGoBackErrorController.showAgent(incomeSourceType) else
controllers.incomeSources.add.routes.YouCannotGoBackErrorController.show(incomeSourceType)
val cannotGoBackRedirect = if (isAgent) controllers.incomeSources.add.routes.YouCannotGoBackErrorController.showAgent(iss.incomeSourceType) else
controllers.incomeSources.add.routes.YouCannotGoBackErrorController.show(iss.incomeSourceType)
val errorHandler = if (isAgent) itvcErrorHandlerAgent else itvcErrorHandler

val incomeSourceId: IncomeSourceId = mkIncomeSourceId(id)
sessionService.getMongoKeyTyped[Boolean](AddIncomeSourceData.hasBeenAddedField, JourneyType(Add, incomeSourceType)).flatMap {
sessionService.getMongoKeyTyped[Boolean](AddIncomeSourceData.hasBeenAddedField, JourneyType(Add, iss.incomeSourceType)).flatMap {
case Left(ex) => Logger("application").error(s"${if (isAgent) "[Agent]"}" +
s"Error getting hasBeenAdded field from session: ${ex.getMessage}")
Future.successful(errorHandler.showInternalServerError())
Expand All @@ -139,19 +140,19 @@ class IncomeSourceReportingMethodController @Inject()(val authenticate: Authenti
case _ =>
itsaStatusService.hasMandatedOrVoluntaryStatusCurrentYear.flatMap {
case true =>
getViewModel(incomeSourceType, incomeSourceId).map {
getViewModel(iss).map {
case Some(viewModel) =>
Ok(view(
incomeSourceReportingMethodForm = IncomeSourceReportingMethodForm.form,
incomeSourceReportingViewModel = viewModel,
postAction = submitUrl(isAgent, incomeSourceType),
postAction = submitUrl(isAgent, iss.incomeSourceType),
isAgent = isAgent))
case None =>
Redirect(redirectUrl(isAgent, incomeSourceType))
Redirect(redirectUrl(isAgent, iss.incomeSourceType))
}
case false =>
Future.successful {
Redirect(redirectUrl(isAgent, incomeSourceType))
Redirect(redirectUrl(isAgent, iss.incomeSourceType))
}
}
}
Expand All @@ -162,10 +163,10 @@ class IncomeSourceReportingMethodController @Inject()(val authenticate: Authenti
user.incomeSources.getLatencyDetails(incomeSourceType, incomeSourceId)
}

private def getViewModel(incomeSourceType: IncomeSourceType, incomeSourceId: IncomeSourceId)
private def getViewModel(iss: IncomeSourceT)
(implicit user: MtdItUser[_], hc: HeaderCarrier, ec: ExecutionContext): Future[Option[IncomeSourceReportingMethodViewModel]] = {
val currentTaxYear = dateService.getCurrentTaxYearEnd(isEnabled(TimeMachineAddYear))
val latencyDetails = getLatencyDetails(incomeSourceType, incomeSourceId.value)
val latencyDetails = getLatencyDetails(iss.incomeSourceType, iss.id.value)


latencyDetails match {
Expand Down Expand Up @@ -216,8 +217,8 @@ class IncomeSourceReportingMethodController @Inject()(val authenticate: Authenti
(implicit user: MtdItUser[_], ec: ExecutionContext): Future[Result] = {

val updatedForm = IncomeSourceReportingMethodForm.updateErrorMessagesWithValues(form)

getViewModel(incomeSourceType, id).map {
val iss: IncomeSourceT = IncomeSourceT( id, incomeSourceType)
getViewModel(iss).map {
case Some(viewModel) =>
BadRequest(view(
incomeSourceReportingMethodForm = updatedForm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CeaseCheckIncomeSourceDetailsController @Inject()(val authenticate: Authen
def handleRequest(sources: IncomeSourceDetailsModel, isAgent: Boolean, incomeSourceType: IncomeSourceType)
(implicit user: MtdItUser[_]): Future[Result] = withIncomeSourcesFS {

val messagesPrefix = incomeSourceType.ceaseCheckDetailsPrefix
val messagesPrefix = incomeSourceType.lang.ceaseCheckDetailsPrefix
val sessionDataFuture = getSessionData(incomeSourceType)

sessionDataFuture.flatMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ReportingMethodChangeErrorController @Inject()(val manageIncomeSources: Ma
isAgent = isAgent,
manageIncomeSourcesUrl = getManageIncomeSourcesUrl(isAgent),
manageIncomeSourceDetailsUrl = getManageIncomeSourceDetailsUrl(id, isAgent, incomeSourceType),
messagesPrefix = incomeSourceType.reportingMethodChangeErrorPrefix
messagesPrefix = incomeSourceType.lang.reportingMethodChangeErrorPrefix
)
)
case None =>
Expand Down
Loading