Skip to content

Commit

Permalink
Merge pull request #64 from hmrc/Sprint-2/page-generation
Browse files Browse the repository at this point in the history
Sprint 2: Page Generation
  • Loading branch information
besscerule authored May 15, 2024
2 parents 3570037 + bed435a commit 98a7beb
Show file tree
Hide file tree
Showing 39 changed files with 2,092 additions and 1 deletion.
72 changes: 72 additions & 0 deletions app/controllers/Category1AssesmentsController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 controllers

import controllers.actions._
import forms.Category1AssesmentsFormProvider
import javax.inject.Inject
import models.Mode
import navigation.Navigator
import pages.Category1AssesmentsPage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.Category1AssesmentsView

import scala.concurrent.{ExecutionContext, Future}

class Category1AssesmentsController @Inject()(
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
navigator: Navigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
formProvider: Category1AssesmentsFormProvider,
val controllerComponents: MessagesControllerComponents,
view: Category1AssesmentsView
)(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport {

private val form = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>

val preparedForm = request.userAnswers.get(Category1AssesmentsPage) match {
case None => form
case Some(value) => form.fill(value)
}

Ok(view(preparedForm, mode))
}

def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>

form.bindFromRequest().fold(
formWithErrors =>
Future.successful(BadRequest(view(formWithErrors, mode))),

value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(Category1AssesmentsPage, value))
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(navigator.nextPage(Category1AssesmentsPage, mode, updatedAnswers))
)
}
}
39 changes: 39 additions & 0 deletions app/controllers/CreateRecordStartController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 controllers

import controllers.actions._
import javax.inject.Inject
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.CreateRecordStartView

class CreateRecordStartController @Inject()(
override val messagesApi: MessagesApi,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
val controllerComponents: MessagesControllerComponents,
view: CreateRecordStartView
) extends FrontendBaseController with I18nSupport {

def onPageLoad: Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>
Ok(view())
}
}
39 changes: 39 additions & 0 deletions app/controllers/CreateRecordSuccessController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 controllers

import controllers.actions._
import javax.inject.Inject
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.CreateRecordSuccessView

class CreateRecordSuccessController @Inject()(
override val messagesApi: MessagesApi,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
val controllerComponents: MessagesControllerComponents,
view: CreateRecordSuccessView
) extends FrontendBaseController with I18nSupport {

def onPageLoad: Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>
Ok(view())
}
}
72 changes: 72 additions & 0 deletions app/controllers/GoodsDescriptionController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 controllers

import controllers.actions._
import forms.GoodsDescriptionFormProvider
import javax.inject.Inject
import models.Mode
import navigation.Navigator
import pages.GoodsDescriptionPage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.GoodsDescriptionView

import scala.concurrent.{ExecutionContext, Future}

class GoodsDescriptionController @Inject()(
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
navigator: Navigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
formProvider: GoodsDescriptionFormProvider,
val controllerComponents: MessagesControllerComponents,
view: GoodsDescriptionView
)(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport {

private val form = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>

val preparedForm = request.userAnswers.get(GoodsDescriptionPage) match {
case None => form
case Some(value) => form.fill(value)
}

Ok(view(preparedForm, mode))
}

def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>

form.bindFromRequest().fold(
formWithErrors =>
Future.successful(BadRequest(view(formWithErrors, mode))),

value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(GoodsDescriptionPage, value))
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(navigator.nextPage(GoodsDescriptionPage, mode, updatedAnswers))
)
}
}
72 changes: 72 additions & 0 deletions app/controllers/HasCorrectGoodsController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 controllers

import controllers.actions._
import forms.HasCorrectGoodsFormProvider
import javax.inject.Inject
import models.Mode
import navigation.Navigator
import pages.HasCorrectGoodsPage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.HasCorrectGoodsView

import scala.concurrent.{ExecutionContext, Future}

class HasCorrectGoodsController @Inject()(
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
navigator: Navigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
formProvider: HasCorrectGoodsFormProvider,
val controllerComponents: MessagesControllerComponents,
view: HasCorrectGoodsView
)(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport {

private val form = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>

val preparedForm = request.userAnswers.get(HasCorrectGoodsPage) match {
case None => form
case Some(value) => form.fill(value)
}

Ok(view(preparedForm, mode))
}

def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>

form.bindFromRequest().fold(
formWithErrors =>
Future.successful(BadRequest(view(formWithErrors, mode))),

value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(HasCorrectGoodsPage, value))
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(navigator.nextPage(HasCorrectGoodsPage, mode, updatedAnswers))
)
}
}
72 changes: 72 additions & 0 deletions app/controllers/HasGoodsDescriptionController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 controllers

import controllers.actions._
import forms.HasGoodsDescriptionFormProvider
import javax.inject.Inject
import models.Mode
import navigation.Navigator
import pages.HasGoodsDescriptionPage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.HasGoodsDescriptionView

import scala.concurrent.{ExecutionContext, Future}

class HasGoodsDescriptionController @Inject()(
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
navigator: Navigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
formProvider: HasGoodsDescriptionFormProvider,
val controllerComponents: MessagesControllerComponents,
view: HasGoodsDescriptionView
)(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport {

private val form = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>

val preparedForm = request.userAnswers.get(HasGoodsDescriptionPage) match {
case None => form
case Some(value) => form.fill(value)
}

Ok(view(preparedForm, mode))
}

def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>

form.bindFromRequest().fold(
formWithErrors =>
Future.successful(BadRequest(view(formWithErrors, mode))),

value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(HasGoodsDescriptionPage, value))
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(navigator.nextPage(HasGoodsDescriptionPage, mode, updatedAnswers))
)
}
}
Loading

0 comments on commit 98a7beb

Please sign in to comment.