Skip to content

Commit

Permalink
Merge pull request #550 from hmrc/package-refactor
Browse files Browse the repository at this point in the history
TGP-2902: Profile Package refactor
  • Loading branch information
kenneth-rayner authored Nov 7, 2024
2 parents ad2ad0c + e7d55e4 commit bc716f3
Show file tree
Hide file tree
Showing 119 changed files with 2,333 additions and 1,717 deletions.
2 changes: 1 addition & 1 deletion app/controllers/DownloadRequestSuccessController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DownloadRequestSuccessController @Inject() (
case _ =>
logErrorsAndContinue(
"Email was not found",
routes.IndexController.onPageLoad
routes.IndexController.onPageLoad()
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/IndexController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class IndexController @Inject() (
case Some(_) =>
traderProfileConnector.checkTraderProfile(request.eori).flatMap {
case true => eoriChanged(request)
case false => Future.successful(Redirect(routes.ProfileSetupController.onPageLoad()))
case false => Future.successful(Redirect(controllers.profile.routes.ProfileSetupController.onPageLoad()))
}
case None =>
Future.successful(
Expand All @@ -53,7 +53,7 @@ class IndexController @Inject() (
private def eoriChanged(request: IdentifierRequest[AnyContent])(implicit hc: HeaderCarrier) =
traderProfileConnector.getTraderProfile(request.eori).map {
case TraderProfile(_, _, _, _, eoriChanged) if eoriChanged =>
Redirect(routes.UkimsNumberChangeController.onPageLoad())
Redirect(controllers.profile.routes.UkimsNumberChangeController.onPageLoad())
case _ =>
Redirect(routes.HomePageController.onPageLoad())
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/RequestDataController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class RequestDataController @Inject() (
case _ =>
logErrorsAndContinue(
"Email was not found",
routes.IndexController.onPageLoad
routes.IndexController.onPageLoad()
)
}
}
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/actions/ProfileAuthenticateAction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package controllers.actions

import connectors.TraderProfileConnector
import controllers.routes
import models.requests.IdentifierRequest
import play.api.mvc.Results.Redirect
import play.api.mvc._
Expand All @@ -35,7 +34,7 @@ class ProfileAuthenticateActionImpl @Inject() (
def filter[A](request: IdentifierRequest[A]): Future[Option[Result]] = {
implicit val hc: HeaderCarrier = HeaderCarrierConverter.fromRequestAndSession(request, request.session)
traderProfileConnector.checkTraderProfile(request.eori).map {
case false => Some(Redirect(routes.ProfileSetupController.onPageLoad()))
case false => Some(Redirect(controllers.profile.routes.ProfileSetupController.onPageLoad()))
case true => None
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
* limitations under the License.
*/

package controllers
package controllers.categorisation

import controllers.BaseController
import controllers.actions._
import models.NormalMode
import navigation.Navigator
import pages.CategoryGuidancePage
import navigation.CategorisationNavigator
import pages.categorisation.CategoryGuidancePage
import play.api.i18n.MessagesApi
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import views.html.CategoryGuidanceView
import views.html.categorisation.CategoryGuidanceView

import javax.inject.Inject

Expand All @@ -34,7 +35,7 @@ class CategoryGuidanceController @Inject() (
profileAuth: ProfileAuthenticateAction,
val controllerComponents: MessagesControllerComponents,
view: CategoryGuidanceView,
navigator: Navigator
navigator: CategorisationNavigator
) extends BaseController {

def onPageLoad(recordId: String): Action[AnyContent] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

package controllers
package controllers.profile

import controllers.BaseController
import controllers.actions._
import play.api.i18n.MessagesApi
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import views.html.CreateProfileSuccessView
import views.html.profile.CreateProfileSuccessView

import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@
* limitations under the License.
*/

package controllers
package controllers.profile

import com.google.inject.Inject
import connectors.TraderProfileConnector
import controllers.BaseController
import controllers.actions.{DataRequiredAction, DataRetrievalAction, IdentifierAction, ProfileCheckAction}
import models.{NormalMode, TraderProfile}
import models.helper.CreateProfileJourney
import navigation.Navigator
import pages.CyaCreateProfilePage
import models.{NormalMode, TraderProfile}
import navigation.ProfileNavigator
import pages.profile.CyaCreateProfilePage
import play.api.i18n.MessagesApi
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import services.{AuditService, DataCleansingService}
import viewmodels.checkAnswers._
import viewmodels.checkAnswers.profile._
import viewmodels.govuk.summarylist._
import views.html.CyaCreateProfileView
import views.html.profile.CyaCreateProfileView

import scala.concurrent.{ExecutionContext, Future}

Expand All @@ -42,7 +43,7 @@ class CyaCreateProfileController @Inject() (
view: CyaCreateProfileView,
traderProfileConnector: TraderProfileConnector,
auditService: AuditService,
navigator: Navigator,
navigator: ProfileNavigator,
dataCleansingService: DataCleansingService
)(implicit ec: ExecutionContext)
extends BaseController {
Expand All @@ -65,7 +66,7 @@ class CyaCreateProfileController @Inject() (
Ok(view(list))
case Left(errors) =>
dataCleansingService.deleteMongoData(request.userAnswers.id, CreateProfileJourney)
logErrorsAndContinue(errorMessage, routes.ProfileSetupController.onPageLoad(), errors)
logErrorsAndContinue(errorMessage, controllers.profile.routes.ProfileSetupController.onPageLoad(), errors)
}
}

Expand All @@ -80,7 +81,9 @@ class CyaCreateProfileController @Inject() (

case Left(errors) =>
dataCleansingService.deleteMongoData(request.userAnswers.id, CreateProfileJourney)
Future.successful(logErrorsAndContinue(errorMessage, routes.ProfileSetupController.onPageLoad(), errors))
Future.successful(
logErrorsAndContinue(errorMessage, controllers.profile.routes.ProfileSetupController.onPageLoad(), errors)
)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@
* limitations under the License.
*/

package controllers
package controllers.profile

import cats.data
import cats.data.EitherNec
import connectors.TraderProfileConnector
import controllers.actions._
import controllers.BaseController
import controllers.actions.{DataRequiredAction, DataRetrievalAction, IdentifierAction, ProfileAuthenticateAction}
import models.{NormalMode, TraderProfile, ValidationError}
import navigation.Navigator
import navigation.ProfileNavigator
import org.apache.pekko.Done
import pages._
import pages.profile.CyaMaintainProfilePage
import play.api.i18n.MessagesApi
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import services.AuditService
import uk.gov.hmrc.http.HeaderCarrier
import utils.Constants._
import utils.SessionData._
import viewmodels.checkAnswers._
import viewmodels.govuk.summarylist._
import views.html.CyaMaintainProfileView
import uk.gov.hmrc.http._
import utils.Constants.{hasNiphlKey, hasNirmsKey, niphlNumberKey, nirmsNumberKey, ukimsNumberKey}
import viewmodels.checkAnswers.profile._
import viewmodels.govuk.all.SummaryListViewModel
import views.html.profile.CyaMaintainProfileView

import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}
Expand All @@ -46,7 +47,7 @@ class CyaMaintainProfileController @Inject() (
val controllerComponents: MessagesControllerComponents,
view: CyaMaintainProfileView,
traderProfileConnector: TraderProfileConnector,
navigator: Navigator,
navigator: ProfileNavigator,
auditService: AuditService
)(implicit ec: ExecutionContext)
extends BaseController {
Expand Down Expand Up @@ -256,7 +257,8 @@ class CyaMaintainProfileController @Inject() (
}

private case class TraderProfileBuildFailure(errors: data.NonEmptyChain[ValidationError]) extends Exception {
private val errorsAsString = errors.toChain.toList.map(_.message).mkString(", ")
private val errorsAsString = errors.toChain.toList.map(_.message).mkString(", ")

override def getMessage: String = s"$errorMessage Missing pages: $errorsAsString"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@
* limitations under the License.
*/

package controllers
package controllers.profile

import cats.data
import cats.data.EitherNec
import connectors.TraderProfileConnector
import controllers.actions._
import controllers.{BaseController, routes}
import models.{NormalMode, TraderProfile, ValidationError}
import navigation.Navigator
import pages._
import navigation.ProfileNavigator
import pages.profile.{CyaNewUkimsNumberPage, UkimsNumberUpdatePage}
import play.api.i18n.MessagesApi
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
import services.AuditService
import viewmodels.checkAnswers._
import viewmodels.checkAnswers.profile.UkimsNumberSummary
import viewmodels.govuk.summarylist._
import views.html.CyaNewUkimsNumberView
import views.html.profile.CyaNewUkimsNumberView

import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}
Expand All @@ -43,7 +44,7 @@ class CyaNewUkimsNumberController @Inject() (
val controllerComponents: MessagesControllerComponents,
view: CyaNewUkimsNumberView,
traderProfileConnector: TraderProfileConnector,
navigator: Navigator,
navigator: ProfileNavigator,
auditService: AuditService,
sessionRepository: SessionRepository
)(implicit ec: ExecutionContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,28 @@
* limitations under the License.
*/

package controllers
package controllers.profile

import connectors.TraderProfileConnector
import controllers.BaseController
import controllers.actions._
import forms.HasNiphlFormProvider
import forms.profile.HasNiphlFormProvider
import models.Mode
import navigation.Navigator
import pages.{HasNiphlPage, HasNiphlUpdatePage}
import navigation.ProfileNavigator
import pages.profile.{HasNiphlPage, HasNiphlUpdatePage}
import play.api.i18n.MessagesApi
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import queries.TraderProfileQuery
import repositories.SessionRepository
import views.html.HasNiphlView
import views.html.profile.HasNiphlView

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

class HasNiphlController @Inject() (
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
navigator: Navigator,
navigator: ProfileNavigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
Expand All @@ -51,7 +52,7 @@ class HasNiphlController @Inject() (
def onPageLoadCreate(mode: Mode): Action[AnyContent] =
(identify andThen checkProfile andThen getData andThen requireData) { implicit request =>
val preparedForm = prepareForm(HasNiphlPage, form)
Ok(view(preparedForm, routes.HasNiphlController.onSubmitCreate(mode)))
Ok(view(preparedForm, controllers.profile.routes.HasNiphlController.onSubmitCreate(mode)))
}

def onSubmitCreate(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async {
Expand All @@ -60,7 +61,9 @@ class HasNiphlController @Inject() (
.bindFromRequest()
.fold(
formWithErrors =>
Future.successful(BadRequest(view(formWithErrors, routes.HasNiphlController.onSubmitCreate(mode)))),
Future.successful(
BadRequest(view(formWithErrors, controllers.profile.routes.HasNiphlController.onSubmitCreate(mode)))
),
value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(HasNiphlPage, value))
Expand All @@ -79,10 +82,15 @@ class HasNiphlController @Inject() (
Future.fromTry(request.userAnswers.set(HasNiphlUpdatePage, traderProfile.niphlNumber.isDefined))
_ <- sessionRepository.set(updatedAnswers)
} yield Ok(
view(form.fill(traderProfile.niphlNumber.isDefined), routes.HasNiphlController.onSubmitUpdate(mode))
view(
form.fill(traderProfile.niphlNumber.isDefined),
controllers.profile.routes.HasNiphlController.onSubmitUpdate(mode)
)
)
case Some(value) =>
Future.successful(Ok(view(form.fill(value), routes.HasNiphlController.onSubmitUpdate(mode))))
Future.successful(
Ok(view(form.fill(value), controllers.profile.routes.HasNiphlController.onSubmitUpdate(mode)))
)
}
}

Expand All @@ -92,7 +100,9 @@ class HasNiphlController @Inject() (
.bindFromRequest()
.fold(
formWithErrors =>
Future.successful(BadRequest(view(formWithErrors, routes.HasNiphlController.onSubmitUpdate(mode)))),
Future.successful(
BadRequest(view(formWithErrors, controllers.profile.routes.HasNiphlController.onSubmitUpdate(mode)))
),
value =>
traderProfileConnector.getTraderProfile(request.eori).flatMap { traderProfile =>
for {
Expand Down
Loading

0 comments on commit bc716f3

Please sign in to comment.