-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MCSC-296 Create Charge Placeholder Screens (#27)
- Loading branch information
Dan Corbin
authored
Jun 16, 2023
1 parent
cc4b3be
commit 1f5a8ff
Showing
37 changed files
with
1,864 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
app/controllers/annualallowance/taxyear/HowMuchAAChargeSchemePaidController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
) | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
app/controllers/annualallowance/taxyear/HowMuchAAChargeYouPaidController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
) | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
app/controllers/annualallowance/taxyear/WhoPaidAAChargeController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app/forms/annualallowance/taxyear/HowMuchAAChargeSchemePaidFormProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
) | ||
} |
35 changes: 35 additions & 0 deletions
35
app/forms/annualallowance/taxyear/HowMuchAAChargeYouPaidFormProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
) | ||
} |
31 changes: 31 additions & 0 deletions
31
app/forms/annualallowance/taxyear/WhoPaidAAChargeFormProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): _*) | ||
} |
Oops, something went wrong.