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

ADR-1425: Additional validations for DSD #221

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
10 changes: 6 additions & 4 deletions app/controllers/dutySuspended/DutySuspendedBeerController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
package controllers.dutySuspended

import controllers.actions._
import forms.dutySuspended.DutySuspendedBeerFormProvider
import forms.dutySuspended.DutySuspendedFormProvider

import javax.inject.Inject
import models.Mode
import navigation.DeclareDutySuspendedDeliveriesNavigator
import pages.dutySuspended.DutySuspendedBeerPage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import connectors.UserAnswersConnector
import models.AlcoholRegime.Beer
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.dutySuspended.DutySuspendedBeerView

Expand All @@ -38,17 +40,16 @@ class DutySuspendedBeerController @Inject() (
getData: DataRetrievalAction,
requireData: DataRequiredAction,
checkRegime: CheckBeerRegimeAction,
formProvider: DutySuspendedBeerFormProvider,
formProvider: DutySuspendedFormProvider,
val controllerComponents: MessagesControllerComponents,
view: DutySuspendedBeerView
)(implicit ec: ExecutionContext)
extends FrontendBaseController
with I18nSupport {

val form = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) {
implicit request =>
val form = formProvider(Beer)
val preparedForm = request.userAnswers.get(DutySuspendedBeerPage) match {
case None => form
case Some(value) => form.fill(value)
Expand All @@ -59,6 +60,7 @@ class DutySuspendedBeerController @Inject() (

def onSubmit(mode: Mode): Action[AnyContent] =
(identify andThen getData andThen requireData andThen checkRegime).async { implicit request =>
val form = formProvider(Beer)
form
.bindFromRequest()
.fold(
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/dutySuspended/DutySuspendedCiderController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
package controllers.dutySuspended

import controllers.actions._
import forms.dutySuspended.DutySuspendedCiderFormProvider
import forms.dutySuspended.DutySuspendedFormProvider

import javax.inject.Inject
import models.Mode
import navigation.DeclareDutySuspendedDeliveriesNavigator
import pages.dutySuspended.DutySuspendedCiderPage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import connectors.UserAnswersConnector
import models.AlcoholRegime.Cider
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.dutySuspended.DutySuspendedCiderView

Expand All @@ -38,17 +40,16 @@ class DutySuspendedCiderController @Inject() (
getData: DataRetrievalAction,
requireData: DataRequiredAction,
checkRegime: CheckCiderRegimeAction,
formProvider: DutySuspendedCiderFormProvider,
formProvider: DutySuspendedFormProvider,
val controllerComponents: MessagesControllerComponents,
view: DutySuspendedCiderView
)(implicit ec: ExecutionContext)
extends FrontendBaseController
with I18nSupport {

val form = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) {
implicit request =>
val form = formProvider(Cider)
val preparedForm = request.userAnswers.get(DutySuspendedCiderPage) match {
case None => form
case Some(value) => form.fill(value)
Expand All @@ -59,6 +60,7 @@ class DutySuspendedCiderController @Inject() (

def onSubmit(mode: Mode): Action[AnyContent] =
(identify andThen getData andThen requireData andThen checkRegime).async { implicit request =>
val form = formProvider(Cider)
form
.bindFromRequest()
.fold(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package controllers.dutySuspended

import controllers.actions._
import forms.dutySuspended.DutySuspendedOtherFermentedFormProvider
import forms.dutySuspended.DutySuspendedFormProvider

import javax.inject.Inject
import models.Mode
Expand All @@ -26,6 +26,7 @@ import pages.dutySuspended.DutySuspendedOtherFermentedPage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import connectors.UserAnswersConnector
import models.AlcoholRegime.OtherFermentedProduct
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.dutySuspended.DutySuspendedOtherFermentedView

Expand All @@ -39,17 +40,16 @@ class DutySuspendedOtherFermentedController @Inject() (
getData: DataRetrievalAction,
requireData: DataRequiredAction,
checkRegime: CheckOtherFermentedRegimeAction,
formProvider: DutySuspendedOtherFermentedFormProvider,
formProvider: DutySuspendedFormProvider,
val controllerComponents: MessagesControllerComponents,
view: DutySuspendedOtherFermentedView
)(implicit ec: ExecutionContext)
extends FrontendBaseController
with I18nSupport {

val form = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) {
implicit request =>
val form = formProvider(OtherFermentedProduct)
val preparedForm = request.userAnswers.get(DutySuspendedOtherFermentedPage) match {
case None => form
case Some(value) => form.fill(value)
Expand All @@ -60,6 +60,7 @@ class DutySuspendedOtherFermentedController @Inject() (

def onSubmit(mode: Mode): Action[AnyContent] =
(identify andThen getData andThen requireData andThen checkRegime).async { implicit request =>
val form = formProvider(OtherFermentedProduct)
form
.bindFromRequest()
.fold(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
package controllers.dutySuspended

import controllers.actions._
import forms.dutySuspended.DutySuspendedSpiritsFormProvider
import forms.dutySuspended.DutySuspendedFormProvider

import javax.inject.Inject
import models.Mode
import navigation.DeclareDutySuspendedDeliveriesNavigator
import pages.dutySuspended.DutySuspendedSpiritsPage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import connectors.UserAnswersConnector
import models.AlcoholRegime.Spirits
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.dutySuspended.DutySuspendedSpiritsView

Expand All @@ -38,17 +40,16 @@ class DutySuspendedSpiritsController @Inject() (
getData: DataRetrievalAction,
requireData: DataRequiredAction,
checkRegime: CheckSpiritsRegimeAction,
formProvider: DutySuspendedSpiritsFormProvider,
formProvider: DutySuspendedFormProvider,
val controllerComponents: MessagesControllerComponents,
view: DutySuspendedSpiritsView
)(implicit ec: ExecutionContext)
extends FrontendBaseController
with I18nSupport {

val form = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) {
implicit request =>
val form = formProvider(Spirits)
val preparedForm = request.userAnswers.get(DutySuspendedSpiritsPage) match {
case None => form
case Some(value) => form.fill(value)
Expand All @@ -59,6 +60,7 @@ class DutySuspendedSpiritsController @Inject() (

def onSubmit(mode: Mode): Action[AnyContent] =
(identify andThen getData andThen requireData andThen checkRegime).async { implicit request =>
val form = formProvider(Spirits)
form
.bindFromRequest()
.fold(
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/dutySuspended/DutySuspendedWineController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
package controllers.dutySuspended

import controllers.actions._
import forms.dutySuspended.DutySuspendedWineFormProvider
import forms.dutySuspended.DutySuspendedFormProvider

import javax.inject.Inject
import models.Mode
import navigation.DeclareDutySuspendedDeliveriesNavigator
import pages.dutySuspended.DutySuspendedWinePage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import connectors.UserAnswersConnector
import models.AlcoholRegime.Wine
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.dutySuspended.DutySuspendedWineView

Expand All @@ -38,17 +40,16 @@ class DutySuspendedWineController @Inject() (
getData: DataRetrievalAction,
requireData: DataRequiredAction,
checkRegime: CheckWineRegimeAction,
formProvider: DutySuspendedWineFormProvider,
formProvider: DutySuspendedFormProvider,
val controllerComponents: MessagesControllerComponents,
view: DutySuspendedWineView
)(implicit ec: ExecutionContext)
extends FrontendBaseController
with I18nSupport {

val form = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData andThen checkRegime) {
implicit request =>
val form = formProvider(Wine)
val preparedForm = request.userAnswers.get(DutySuspendedWinePage) match {
case None => form
case Some(value) => form.fill(value)
Expand All @@ -59,6 +60,7 @@ class DutySuspendedWineController @Inject() (

def onSubmit(mode: Mode): Action[AnyContent] =
(identify andThen getData andThen requireData andThen checkRegime).async { implicit request =>
val form = formProvider(Wine)
form
.bindFromRequest()
.fold(
Expand Down
58 changes: 0 additions & 58 deletions app/forms/dutySuspended/DutySuspendedBeerFormProvider.scala

This file was deleted.

58 changes: 0 additions & 58 deletions app/forms/dutySuspended/DutySuspendedCiderFormProvider.scala

This file was deleted.

40 changes: 40 additions & 0 deletions app/forms/dutySuspended/DutySuspendedFormProvider.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 forms.dutySuspended

import javax.inject.Inject
import forms.mappings.Mappings
import models.AlcoholRegime
import play.api.data.Form
import models.dutySuspended.DutySuspendedVolume
import play.api.i18n.Messages

class DutySuspendedFormProvider @Inject() extends Mappings {
def apply(regime: AlcoholRegime)(implicit messages: Messages): Form[DutySuspendedVolume] = Form(
"volumes" -> dutySuspendedVolumes(
"dutySuspendedVolume.error.invalid",
"dutySuspendedVolume.error.noValue",
"dutySuspendedVolume.error.decimalPlaces",
"dutySuspendedVolume.error.minimumValue",
"dutySuspendedVolume.error.maximumValue",
"dutySuspendedVolume.error.lessThanExpected",
"dutySuspendedVolume.error.incorrectSign",
"dutySuspendedVolume.error.zeroTotalLitres",
Seq(messages(s"return.regime.$regime"))
)
)
}
Loading