Skip to content

Commit

Permalink
[MIBM-88][JR] /value-weight-of-goods (#14)
Browse files Browse the repository at this point in the history
* [MIBM-88][JR] add persistence to /goods-destination and add /value-weight-of-goods
  • Loading branch information
jordanrowe authored Sep 29, 2020
1 parent c26b8e6 commit f21d1b8
Show file tree
Hide file tree
Showing 16 changed files with 453 additions and 39 deletions.
4 changes: 2 additions & 2 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$govuk-assets-path: "/merchandise-in-baggage-frontend/assets/lib/govuk-frontend/govuk/assets/";
$hmrc-assets-path: "/merchandise-in-baggage-frontend/assets/lib/hmrc-frontend/hmrc/";
$govuk-assets-path: "/merchandise-in-baggage/assets/lib/govuk-frontend/govuk/assets/";
$hmrc-assets-path: "/merchandise-in-baggage/assets/lib/hmrc-frontend/hmrc/";

@import "lib/govuk-frontend/govuk/all";
@import "lib/hmrc-frontend/hmrc/all";
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.URL
@Singleton
class AppConfig() extends PaymentServiceConf with MongoConfiguration {
lazy val footerLinkItems: Seq[String] = configSource("footerLinkItems").loadOrThrow[Seq[String]]

private val serviceIdentifier = "mib"

private val contactHost = configSource("contact-frontend.host").loadOrThrow[String]

val betaFeedbackUrl = s"$contactHost/contact/beta-feedback-unauthenticated?service=$serviceIdentifier"
}

trait PaymentServiceConf {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,35 @@ import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig
import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.GoodsDestinationFormProvider
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.GoodsDestination
import uk.gov.hmrc.merchandiseinbaggagefrontend.repositories.DeclarationJourneyRepository
import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.GoodsDestinationView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController

import scala.concurrent.{ExecutionContext, Future}

@Singleton
class GoodsDestinationController @Inject()(
override val controllerComponents: MessagesControllerComponents,
actionProvider: DeclarationJourneyActionProvider,
formProvider: GoodsDestinationFormProvider,
repo: DeclarationJourneyRepository,
view: GoodsDestinationView
)(implicit val appConfig: AppConfig) extends FrontendBaseController {
)(implicit ec: ExecutionContext, appConfig: AppConfig) extends DeclarationJourneyUpdateController {

val form: Form[GoodsDestination] = formProvider()

val onPageLoad: Action[AnyContent] = Action { implicit request =>
Ok(view(form))
val onPageLoad: Action[AnyContent] = actionProvider.journeyAction { implicit request =>
Ok(view(request.declarationJourney.maybeGoodsDestination.fold(form)(form.fill)))
}

//TODO implement once session storage has been done under MIBM-77
val onSubmit: Action[AnyContent] = Action { implicit request =>
val onSubmit: Action[AnyContent] = actionProvider.journeyAction.async { implicit request =>
form
.bindFromRequest()
.fold(
formWithErrors => BadRequest(view(formWithErrors)),
value => Redirect(routes.SkeletonJourneyController.valueWeightOfGoods())
formWithErrors => Future.successful(BadRequest(view(formWithErrors))),
value =>
repo.upsert(request.declarationJourney.copy(maybeGoodsDestination = Some(value))).map {_ =>
Redirect(routes.ValueWeightOfGoodsController.onPageLoad())
}
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2020 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 uk.gov.hmrc.merchandiseinbaggagefrontend.controllers

import javax.inject.{Inject, Singleton}
import play.api.data.Form
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig
import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.ValueWeightOfGoodsFormProvider
import uk.gov.hmrc.merchandiseinbaggagefrontend.repositories.DeclarationJourneyRepository
import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.ValueWeightOfGoodsView

import scala.concurrent.{ExecutionContext, Future}

@Singleton
class ValueWeightOfGoodsController @Inject()(override val controllerComponents: MessagesControllerComponents,
actionProvider: DeclarationJourneyActionProvider,
formProvider: ValueWeightOfGoodsFormProvider,
repo: DeclarationJourneyRepository,
view: ValueWeightOfGoodsView)
(implicit ec: ExecutionContext, appConfig: AppConfig)
extends DeclarationJourneyUpdateController {

val form: Form[Boolean] = formProvider()

val onPageLoad: Action[AnyContent] = actionProvider.journeyAction { implicit request =>
request.declarationJourney.maybeGoodsDestination match {
case Some(dest) => Ok(
view(request.declarationJourney.maybeValueWeightOfGoodsExceedsThreshold.fold(form)(form.fill), dest)
)
case None => Redirect(routes.GoodsDestinationController.onPageLoad())
}
}

val onSubmit: Action[AnyContent] = actionProvider.journeyAction.async { implicit request =>
request.declarationJourney.maybeGoodsDestination match {
case Some(dest) =>
form
.bindFromRequest()
.fold(
formWithErrors => Future successful BadRequest(view(formWithErrors, dest)),
value => {
repo.upsert(request.declarationJourney.copy(maybeValueWeightOfGoodsExceedsThreshold = Some(value))).map { _ =>
if (value) Redirect(routes.CannotUseServiceController.onPageLoad())
else Redirect(routes.SkeletonJourneyController.searchGoods())
}
}
)
case None =>
Future successful Redirect(routes.GoodsDestinationController.onPageLoad())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2020 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 uk.gov.hmrc.merchandiseinbaggagefrontend.forms

import javax.inject.Inject
import play.api.data.Form
import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.mappings.Mappings

class ValueWeightOfGoodsFormProvider @Inject() extends Mappings {

def apply(): Form[Boolean] =
Form(
"value" -> boolean("valueWeightOfGoods.error.required")
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.time.format.DateTimeFormatter
import java.util.UUID.randomUUID

import play.api.libs.json.{Format, Json, OFormat}
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.GoodsDestination
import uk.gov.hmrc.merchandiseinbaggagefrontend.utils.ValueClassFormat

case class SessionId(value: String)
Expand Down Expand Up @@ -108,7 +109,9 @@ case class DeclarationJourney(sessionId: SessionId,
maybeName: Option[Name] = None,
maybeAddress: Option[Address] = None,
maybeEori: Option[Eori] = None,
maybeJourneyDetails: Option[JourneyDetails] = None)
maybeJourneyDetails: Option[JourneyDetails] = None,
maybeGoodsDestination: Option[GoodsDestination] = None,
maybeValueWeightOfGoodsExceedsThreshold: Option[Boolean] = None)

object DeclarationJourney {
implicit val format: OFormat[DeclarationJourney] = Json.format[DeclarationJourney]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@*
* Copyright 2020 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.
*@

@import uk.gov.hmrc.govukfrontend.views.html.components
@import uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.routes._
@import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.GoodsDestination

@this(
layout: Layout,
formHelper: FormWithCSRF,
errorSummary: components.errorSummary,
inputYesNo: components.inputYesNo,
button: components.button
)

@(form: Form[_], dest: GoodsDestination)(implicit request: Request[_], messages: Messages, appConfig: AppConfig)

@layout(pageTitle = Some(messages(s"valueWeightOfGoods.${dest.toString}.title"))) {
@formHelper(action = ValueWeightOfGoodsController.onSubmit(), 'autoComplete -> "off", 'novalidate -> "novalidate") {

@errorSummary(form.errors)

@inputYesNo(
form = form,
legend = messages(s"valueWeightOfGoods.${dest.toString}.heading"),
legendAsHeading = true
)

@button("site.continue")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@*
* Copyright 2020 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.
*@

@this(govukPhaseBanner: GovukPhaseBanner)

@(phase: String)(implicit messages: Messages, appConfig: AppConfig)

@feedbackBanner = {
@messages("feedback.before")
<a class='govuk-link' href='@{appConfig.betaFeedbackUrl}'>@messages("feedback.link")</a>
@messages("feedback.after")
}

@govukPhaseBanner(PhaseBanner(
tag = Some(Tag(content = Text(phase))),
content = HtmlContent(feedbackBanner)
))
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*@

@import uk.gov.hmrc.govukfrontend.views.viewmodels.header.Header
@import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.components

@this(
govukTemplate: GovukTemplate,
govukHeader: GovukHeader,
govukFooter: GovukFooter,
govukBackLink: GovukBackLink
govukBackLink: GovukBackLink,
phaseBanner: components.phaseBanner,
)

@(
Expand All @@ -32,7 +34,7 @@
footerItems: Seq[FooterItem] = Seq.empty,
bodyEndBlock: Option[Html] = None,
scriptsBlock: Option[Html] = None
)(contentBlock: Html)(implicit messages: Messages)
)(contentBlock: Html)(implicit messages: Messages, appConfig: AppConfig)

@headerDefault = {
@headerBlock.getOrElse {
Expand All @@ -44,24 +46,29 @@
}
}

@beforeContentDefault = {
@phaseBanner("alpha")
@bodyEndBlock.map(x => x)
}

@footerDefault = {
@footerBlock.getOrElse {
@govukFooter(new Footer(meta = Some(Meta(items = Some(footerItems)))))
}
}

@bodyEndDefault = {
@bodyEndBlock
@scriptsBlock
@bodyEndBlock.map(x => x)
@scriptsBlock.map(x => x)
}

@govukTemplate(
htmlLang = Some(messages.lang.code),
pageTitle = pageTitle,
headBlock = headBlock,
headerBlock = headerDefault,
beforeContentBlock = beforeContentBlock,
beforeContentBlock = Some(beforeContentDefault),
footerBlock = footerDefault,
mainClasses = Some("govuk-main-wrapper--auto-spacing"),
bodyEndBlock = Some(bodyEndDefault)
bodyEndBlock = Some(bodyEndDefault),
)(contentBlock)
5 changes: 4 additions & 1 deletion conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ GET /payment uk.gov.hmrc.merchandiseinbaggagefronten
GET /process-payment uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.PaymentController.onSubmit()

GET /select-declaration-type uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.SkeletonJourneyController.selectDeclarationType
GET /value-weight-of-goods uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.SkeletonJourneyController.valueWeightOfGoods
GET /search-goods uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.SkeletonJourneyController.searchGoods
GET /search-goods-country uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.SkeletonJourneyController.searchGoodsCountry
GET /purchase-details uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.SkeletonJourneyController.purchaseDetails
Expand All @@ -33,6 +32,10 @@ POST /excise-and-restricted-goods uk.gov.hmrc.merchandiseinbaggagefronten
GET /goods-destination uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.GoodsDestinationController.onPageLoad()
POST /goods-destination uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.GoodsDestinationController.onSubmit()

# ValueWeightOfGoods
GET /value-weight-of-goods uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.ValueWeightOfGoodsController.onPageLoad()
POST /value-weight-of-goods uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.ValueWeightOfGoodsController.onSubmit()

# CannotUseService
GET /cannot-use-service uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.CannotUseServiceController.onPageLoad()

Expand Down
4 changes: 4 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ google-analytics {
host = auto
}

contact-frontend {
host = "http://localhost:9250"
}

footerLinkItems = ["cookies", "privacy", "termsConditions", "govukHelp"]

mongodb {
Expand Down
14 changes: 13 additions & 1 deletion conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ service.name = merchandise-in-baggage-frontend
service.homePageUrl = /merchandise-in-baggage-frontend
service.text = This is your new service

# Alpha/Beta Banner
feedback.before = This is a new service - your
feedback.link = feedback
feedback.after = will help us to improve it.

footer.cookies.text = Cookies
footer.cookies.url = /help/cookies
footer.privacy.text = Privacy policy
Expand All @@ -22,7 +27,6 @@ payment.button = Pay now
next.button = Next

selectDeclarationType.title = What do you need to declare?
valueWeightOfGoods.title = Is the total value of the goods over £1500 or 1000kg?
searchGoods.title = What goods are you bringing into the UK?
searchGoodsCountry.title = In what country did you buy the x?
purchaseDetails.title = How much did you pay for the x?
Expand Down Expand Up @@ -81,6 +85,14 @@ goodsDestination.gb = England, Wales or Scotland
goodsDestination.error.required = Select one of the options below


# ValueWeightOfGoods
valueWeightOfGoods.ni.title = Is the total value of the goods over £873 or 1000 kilograms (kg)?
valueWeightOfGoods.gb.title = Is the total value of the goods over £1500 or 1000 kilograms (kg)?
valueWeightOfGoods.ni.title = Is the total value of the goods over £873 or 1000 kilograms (kg)?
valueWeightOfGoods.gb.title = Is the total value of the goods over £1500 or 1000 kilograms (kg)?
valueWeightOfGoods.error.required = Select one of the options below


# CannotUseService
cannotUseService.title = You need to submit a full customs declaration
cannotUseService.heading = You need to submit a full customs declaration
Expand Down
Loading

0 comments on commit f21d1b8

Please sign in to comment.