Skip to content

Commit

Permalink
VEIOSS-350 | Allow Trader to Select Countries for Return (#4)
Browse files Browse the repository at this point in the history
* VEIOSS-350 | Add dropdown select for country. Create NoPeriodsAvailable page. Add missing captions to initial pages

* VEIOSS-250 | Create AddToListPage for SoldToCountry. Refactor Action to exclude peroid param and refactor all associated controllers. WIP

* VEIOSS-350 | Use Button group in view.
  • Loading branch information
warrenskiwork1979 authored Nov 23, 2023
1 parent 0bf5221 commit a006043
Show file tree
Hide file tree
Showing 72 changed files with 1,450 additions and 343 deletions.
4 changes: 2 additions & 2 deletions .g8/checkboxPage/app/controllers/$className$Controller.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class $className$Controller @Inject()(

val form = formProvider()

def onPageLoad(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData(period) {
def onPageLoad(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData() {
implicit request =>

val preparedForm = request.userAnswers.get($className$Page) match {
Expand All @@ -36,7 +36,7 @@ class $className$Controller @Inject()(
Ok(view(preparedForm, mode, period))
}

def onSubmit(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData(period).async {
def onSubmit(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData().async {
implicit request =>

form.bindFromRequest().fold(
Expand Down
4 changes: 2 additions & 2 deletions .g8/intPage/app/controllers/$className$Controller.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class $className$Controller @Inject()(

val form = formProvider()

def onPageLoad(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData(period) {
def onPageLoad(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData() {
implicit request =>

val preparedForm = request.userAnswers.get($className$Page) match {
Expand All @@ -36,7 +36,7 @@ class $className$Controller @Inject()(
Ok(view(preparedForm, mode, period))
}

def onSubmit(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData(period).async {
def onSubmit(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData().async {
implicit request =>

form.bindFromRequest().fold(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class $className$Controller @Inject()(

val form = formProvider()

def onPageLoad(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData(period) {
def onPageLoad(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData() {
implicit request =>

val preparedForm = request.userAnswers.get($className$Page) match {
Expand All @@ -36,7 +36,7 @@ class $className$Controller @Inject()(
Ok(view(preparedForm, mode, period))
}

def onSubmit(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData(period).async {
def onSubmit(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData().async {
implicit request =>

form.bindFromRequest().fold(
Expand Down
4 changes: 2 additions & 2 deletions .g8/stringPage/app/controllers/$className$Controller.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class $className$Controller @Inject()(

val form = formProvider()

def onPageLoad(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData(period) {
def onPageLoad(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData() {
implicit request =>

val preparedForm = request.userAnswers.get($className$Page) match {
Expand All @@ -36,7 +36,7 @@ class $className$Controller @Inject()(
Ok(view(preparedForm, mode, period))
}

def onSubmit(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData(period).async {
def onSubmit(mode: Mode): Action[AnyContent] = cc.authAndRequireData().async {
implicit request =>

form.bindFromRequest().fold(
Expand Down
4 changes: 2 additions & 2 deletions .g8/yesNoPage/app/controllers/$className$Controller.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class $className;format="cap"$Controller @Inject()(

val form = formProvider()

def onPageLoad(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData(period) {
def onPageLoad(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData() {
implicit request =>

val preparedForm = request.userAnswers.get($className$Page) match {
Expand All @@ -36,7 +36,7 @@ class $className;format="cap"$Controller @Inject()(
Ok(view(preparedForm, mode, period))
}

def onSubmit(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData(period).async {
def onSubmit(mode: Mode, period: Period): Action[AnyContent] = cc.authAndRequireData().async {
implicit request =>

form.bindFromRequest().fold(
Expand Down
37 changes: 37 additions & 0 deletions app/controllers/GetCountry.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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

import models.requests.DataRequest
import models.{Country, Index}
import pages.{JourneyRecoveryPage, SoldToCountryPage, Waypoints}
import play.api.mvc.Results.Redirect
import play.api.mvc.{AnyContent, Result}
import utils.FutureSyntax.FutureOps

import scala.concurrent.Future

trait GetCountry {

protected def getCountry(waypoints: Waypoints, index: Index)
(block: Country => Future[Result])
(implicit request: DataRequest[AnyContent]): Future[Result] =
request.userAnswers
.get(SoldToCountryPage(index))
.map(block(_))
.getOrElse(Redirect(JourneyRecoveryPage.route(waypoints)).toFuture)
}
3 changes: 2 additions & 1 deletion app/controllers/IndexController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package controllers

import controllers.actions.AuthenticatedControllerComponents
import pages.EmptyWaypoints
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
Expand All @@ -30,6 +31,6 @@ class IndexController @Inject()(
protected val controllerComponents: MessagesControllerComponents = cc

def onPageLoad: Action[AnyContent] = cc.authAndGetRegistration { _ =>
Redirect(routes.YourAccountController.onPageLoad)
Redirect(routes.YourAccountController.onPageLoad(waypoints = EmptyWaypoints))
}
}
40 changes: 40 additions & 0 deletions app/controllers/NoOtherPeriodsAvailableController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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

import controllers.actions._
import pages.Waypoints
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.NoOtherPeriodsAvailableView

import javax.inject.Inject

class NoOtherPeriodsAvailableController @Inject()(
override val messagesApi: MessagesApi,
cc: AuthenticatedControllerComponents,
view: NoOtherPeriodsAvailableView
) extends FrontendBaseController with I18nSupport {

protected val controllerComponents: MessagesControllerComponents = cc

def onPageLoad(waypoints: Waypoints): Action[AnyContent] = (cc.actionBuilder andThen cc.identify) {
implicit request =>
Ok(view(waypoints))
}
}
34 changes: 20 additions & 14 deletions app/controllers/SalesToCountryController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,56 @@ package controllers

import controllers.actions._
import forms.SalesToCountryFormProvider
import models.{Index, Period}
import models.Index
import pages.{SalesToCountryPage, Waypoints}
import play.api.data.Form
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import utils.FutureSyntax.FutureOps
import views.html.SalesToCountryView

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

class SalesToCountryController @Inject()(
override val messagesApi: MessagesApi,
cc: AuthenticatedControllerComponents,
formProvider: SalesToCountryFormProvider,
view: SalesToCountryView
)(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport {
override val messagesApi: MessagesApi,
cc: AuthenticatedControllerComponents,
formProvider: SalesToCountryFormProvider,
view: SalesToCountryView
)(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport {

protected val controllerComponents: MessagesControllerComponents = cc

val form = formProvider()
val form: Form[Int] = formProvider()

def onPageLoad(waypoints: Waypoints, period: Period, index: Index): Action[AnyContent] = cc.authAndRequireData(period) {
def onPageLoad(waypoints: Waypoints, index: Index): Action[AnyContent] = cc.authAndRequireData() {
implicit request =>

val preparedForm = request.userAnswers.get(SalesToCountryPage(period, index)) match {
val period = request.userAnswers.period

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

Ok(view(preparedForm, waypoints, period, index))
}

def onSubmit(waypoints: Waypoints, period: Period, index: Index): Action[AnyContent] = cc.authAndRequireData(period).async {
def onSubmit(waypoints: Waypoints, index: Index): Action[AnyContent] = cc.authAndRequireData().async {
implicit request =>

val period = request.userAnswers.period

form.bindFromRequest().fold(
formWithErrors =>
Future.successful(BadRequest(view(formWithErrors, waypoints, period, index))),
BadRequest(view(formWithErrors, waypoints, period, index)).toFuture,

value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(SalesToCountryPage(period, index), value))
_ <- cc.sessionRepository.set(updatedAnswers)
} yield Redirect(SalesToCountryPage(period, index).navigate(waypoints, request.userAnswers, updatedAnswers).route)
updatedAnswers <- Future.fromTry(request.userAnswers.set(SalesToCountryPage(index), value))
_ <- cc.sessionRepository.set(updatedAnswers)
} yield Redirect(SalesToCountryPage(index).navigate(waypoints, request.userAnswers, updatedAnswers).route)
)
}
}
33 changes: 19 additions & 14 deletions app/controllers/SoldGoodsController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,55 @@ package controllers

import controllers.actions._
import forms.SoldGoodsFormProvider
import models.Period
import pages.{SoldGoodsPage, Waypoints}
import play.api.data.Form
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import utils.FutureSyntax.FutureOps
import views.html.SoldGoodsView

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

class SoldGoodsController @Inject()(
override val messagesApi: MessagesApi,
cc: AuthenticatedControllerComponents,
formProvider: SoldGoodsFormProvider,
view: SoldGoodsView
)(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport {
override val messagesApi: MessagesApi,
cc: AuthenticatedControllerComponents,
formProvider: SoldGoodsFormProvider,
view: SoldGoodsView
)(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport {

protected val controllerComponents: MessagesControllerComponents = cc

val form = formProvider()
val form: Form[Boolean] = formProvider()

def onPageLoad(waypoints: Waypoints, period: Period): Action[AnyContent] = cc.authAndRequireData(period) {
def onPageLoad(waypoints: Waypoints): Action[AnyContent] = cc.authAndRequireData() {
implicit request =>

val preparedForm = request.userAnswers.get(SoldGoodsPage(period)) match {
val period = request.userAnswers.period

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

Ok(view(preparedForm, waypoints, period))
}

def onSubmit(waypoints: Waypoints, period: Period): Action[AnyContent] = cc.authAndRequireData(period).async {
def onSubmit(waypoints: Waypoints): Action[AnyContent] = cc.authAndRequireData().async {
implicit request =>

val period = request.userAnswers.period

form.bindFromRequest().fold(
formWithErrors =>
Future.successful(BadRequest(view(formWithErrors, waypoints, period))),
BadRequest(view(formWithErrors, waypoints, period)).toFuture,

value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(SoldGoodsPage(period), value))
_ <- cc.sessionRepository.set(updatedAnswers)
} yield Redirect(SoldGoodsPage(period).navigate(waypoints, request.userAnswers, updatedAnswers).route)
updatedAnswers <- Future.fromTry(request.userAnswers.set(SoldGoodsPage, value))
_ <- cc.sessionRepository.set(updatedAnswers)
} yield Redirect(SoldGoodsPage.navigate(waypoints, request.userAnswers, updatedAnswers).route)
)
}
}
Loading

0 comments on commit a006043

Please sign in to comment.