-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIBM-88][JR] /value-weight-of-goods (#14)
* [MIBM-88][JR] add persistence to /goods-destination and add /value-weight-of-goods
- Loading branch information
1 parent
c26b8e6
commit f21d1b8
Showing
16 changed files
with
453 additions
and
39 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
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"; |
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
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
67 changes: 67 additions & 0 deletions
67
app/uk/gov/hmrc/merchandiseinbaggagefrontend/controllers/ValueWeightOfGoodsController.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,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()) | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/uk/gov/hmrc/merchandiseinbaggagefrontend/forms/ValueWeightOfGoodsFormProvider.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,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") | ||
) | ||
|
||
} |
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
44 changes: 44 additions & 0 deletions
44
app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/ValueWeightOfGoodsView.scala.html
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,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") | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/components/phaseBanner.scala.html
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,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) | ||
)) |
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
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
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
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
Oops, something went wrong.