Skip to content

Commit

Permalink
MCSC-296 Create Charge Placeholder Screens (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Corbin authored Jun 16, 2023
1 parent cc4b3be commit 1f5a8ff
Show file tree
Hide file tree
Showing 37 changed files with 1,864 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import viewmodels.checkAnswers.annualallowance.taxyear.{PayAChargeSummary, PensionSchemeDetailsSummary, PensionSchemeInputAmountsSummary}
import viewmodels.checkAnswers.annualallowance.taxyear._
import viewmodels.govuk.summarylist._
import views.html.CheckYourAnswersView

Expand All @@ -45,7 +45,10 @@ class CheckYourAAPeriodAnswersController @Inject() (
Seq(
PensionSchemeDetailsSummary.row(request.userAnswers, period, index),
PensionSchemeInputAmountsSummary.row(request.userAnswers, period, index),
PayAChargeSummary.row(request.userAnswers, period, index)
PayAChargeSummary.row(request.userAnswers, period, index),
WhoPaidAAChargeSummary.row(request.userAnswers, period, index),
HowMuchAAChargeYouPaidSummary.row(request.userAnswers, period, index),
HowMuchAAChargeSchemePaidSummary.row(request.userAnswers, period, index)
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2023 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.annualallowance.taxyear

import controllers.actions._
import forms.annualallowance.taxyear.HowMuchAAChargeSchemePaidFormProvider
import models.{Mode, Period, SchemeIndex}
import pages.annualallowance.taxyear.HowMuchAAChargeSchemePaidPage
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.annualallowance.taxyear.HowMuchAAChargeSchemePaidView

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

class HowMuchAAChargeSchemePaidController @Inject() (
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
formProvider: HowMuchAAChargeSchemePaidFormProvider,
val controllerComponents: MessagesControllerComponents,
view: HowMuchAAChargeSchemePaidView
)(implicit ec: ExecutionContext)
extends FrontendBaseController
with I18nSupport {

val form = formProvider()

def onPageLoad(mode: Mode, period: Period, schemeIndex: SchemeIndex): Action[AnyContent] =
(identify andThen getData andThen requireData) { implicit request =>
val preparedForm = request.userAnswers.get(HowMuchAAChargeSchemePaidPage(period, schemeIndex)) match {
case None => form
case Some(value) => form.fill(value)
}

Ok(view(preparedForm, mode, period, schemeIndex))
}

def onSubmit(mode: Mode, period: Period, schemeIndex: SchemeIndex): Action[AnyContent] =
(identify andThen getData andThen requireData).async { implicit request =>
form
.bindFromRequest()
.fold(
formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode, period, schemeIndex))),
value =>
for {
updatedAnswers <-
Future.fromTry(request.userAnswers.set(HowMuchAAChargeSchemePaidPage(period, schemeIndex), value))
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(HowMuchAAChargeSchemePaidPage(period, schemeIndex).navigate(mode, updatedAnswers))
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2023 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.annualallowance.taxyear

import controllers.actions._
import forms.annualallowance.taxyear.HowMuchAAChargeYouPaidFormProvider
import models.{Mode, Period, SchemeIndex}
import pages.annualallowance.taxyear.HowMuchAAChargeYouPaidPage
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.annualallowance.taxyear.HowMuchAAChargeYouPaidView

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

class HowMuchAAChargeYouPaidController @Inject() (
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
formProvider: HowMuchAAChargeYouPaidFormProvider,
val controllerComponents: MessagesControllerComponents,
view: HowMuchAAChargeYouPaidView
)(implicit ec: ExecutionContext)
extends FrontendBaseController
with I18nSupport {

val form = formProvider()

def onPageLoad(mode: Mode, period: Period, schemeIndex: SchemeIndex): Action[AnyContent] =
(identify andThen getData andThen requireData) { implicit request =>
val preparedForm = request.userAnswers.get(HowMuchAAChargeYouPaidPage(period, schemeIndex)) match {
case None => form
case Some(value) => form.fill(value)
}

Ok(view(preparedForm, mode, period, schemeIndex))
}

def onSubmit(mode: Mode, period: Period, schemeIndex: SchemeIndex): Action[AnyContent] =
(identify andThen getData andThen requireData).async { implicit request =>
form
.bindFromRequest()
.fold(
formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode, period, schemeIndex))),
value =>
for {
updatedAnswers <-
Future.fromTry(request.userAnswers.set(HowMuchAAChargeYouPaidPage(period, schemeIndex), value))
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(HowMuchAAChargeYouPaidPage(period, schemeIndex).navigate(mode, updatedAnswers))
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2023 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.annualallowance.taxyear

import controllers.actions._
import forms.annualallowance.taxyear.WhoPaidAAChargeFormProvider
import models.{Mode, Period, SchemeIndex}
import pages.annualallowance.taxyear.WhoPaidAAChargePage
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.annualallowance.taxyear.WhoPaidAAChargeView

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

class WhoPaidAAChargeController @Inject() (
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
formProvider: WhoPaidAAChargeFormProvider,
val controllerComponents: MessagesControllerComponents,
view: WhoPaidAAChargeView
)(implicit ec: ExecutionContext)
extends FrontendBaseController
with I18nSupport {

val form = formProvider()

def onPageLoad(mode: Mode, period: Period, schemeIndex: SchemeIndex): Action[AnyContent] =
(identify andThen getData andThen requireData) { implicit request =>
val preparedForm = request.userAnswers.get(WhoPaidAAChargePage(period, schemeIndex)) match {
case None => form
case Some(value) => form.fill(value)
}

Ok(view(preparedForm, mode, period, schemeIndex))
}

def onSubmit(mode: Mode, period: Period, schemeIndex: SchemeIndex): Action[AnyContent] =
(identify andThen getData andThen requireData).async { implicit request =>
form
.bindFromRequest()
.fold(
formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode, period, schemeIndex))),
value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(WhoPaidAAChargePage(period, schemeIndex), value))
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(WhoPaidAAChargePage(period, schemeIndex).navigate(mode, updatedAnswers))
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2023 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.annualallowance.taxyear

import forms.mappings.Mappings
import play.api.data.Form

import javax.inject.Inject

class HowMuchAAChargeSchemePaidFormProvider @Inject() extends Mappings {

def apply(): Form[Int] =
Form(
"value" -> int(
"howMuchAAChargeSchemePaid.error.required",
"howMuchAAChargeSchemePaid.error.wholeNumber",
"howMuchAAChargeSchemePaid.error.nonNumeric"
)
.verifying(inRange(0, Int.MaxValue, "howMuchAAChargeSchemePaid.error.outOfRange"))
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2023 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.annualallowance.taxyear

import forms.mappings.Mappings
import play.api.data.Form

import javax.inject.Inject

class HowMuchAAChargeYouPaidFormProvider @Inject() extends Mappings {

def apply(): Form[Int] =
Form(
"value" -> int(
"howMuchAAChargeYouPaid.error.required",
"howMuchAAChargeYouPaid.error.wholeNumber",
"howMuchAAChargeYouPaid.error.nonNumeric"
)
.verifying(inRange(0, Int.MaxValue, "howMuchAAChargeYouPaid.error.outOfRange"))
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2023 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.annualallowance.taxyear

import forms.mappings.Mappings
import models.WhoPaidAACharge
import play.api.data.Form

import javax.inject.Inject

class WhoPaidAAChargeFormProvider @Inject() extends Mappings {

def apply(): Form[WhoPaidAACharge] =
Form(
"value" -> enumerable[WhoPaidAACharge]("whoPaidAACharge.error.required")
)
}
47 changes: 47 additions & 0 deletions app/models/WhoPaidAACharge.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2023 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 models

import play.api.i18n.Messages
import uk.gov.hmrc.govukfrontend.views.Aliases.Text
import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.RadioItem

sealed trait WhoPaidAACharge

object WhoPaidAACharge extends Enumerable.Implicits {

case object You extends WithName("you") with WhoPaidAACharge
case object Scheme extends WithName("scheme") with WhoPaidAACharge
case object Both extends WithName("both") with WhoPaidAACharge

val values: Seq[WhoPaidAACharge] = Seq(
You,
Scheme,
Both
)

def options(implicit messages: Messages): Seq[RadioItem] = values.zipWithIndex.map { case (value, index) =>
RadioItem(
content = Text(messages(s"whoPaidAACharge.${value.toString}")),
value = Some(value.toString),
id = Some(s"value_$index")
)
}

implicit val enumerable: Enumerable[WhoPaidAACharge] =
Enumerable(values.map(v => v.toString -> v): _*)
}
Loading

0 comments on commit 1f5a8ff

Please sign in to comment.