Skip to content

Commit

Permalink
Merge pull request #548 from hmrc/TGP-2699/Implement-endpoint-for-UKI…
Browse files Browse the repository at this point in the history
…MS-number-page

Tgp 2699/implement endpoint for ukims number page
  • Loading branch information
pauloncast authored Nov 6, 2024
2 parents edf4aea + 809ad0c commit 9f2d071
Show file tree
Hide file tree
Showing 8 changed files with 459 additions and 1 deletion.
91 changes: 91 additions & 0 deletions app/controllers/NewUkimsNumberController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2024 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 connectors.TraderProfileConnector
import controllers.actions._
import forms.UkimsNumberFormProvider
import models.Mode
import navigation.Navigator
import pages.{NewUkimsNumberPage, UkimsNumberPage}
import play.api.data.{Form, FormError}
import play.api.i18n.{Messages, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
import views.html.{NewUkimsNumberView, UkimsNumberView}

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

class NewUkimsNumberController @Inject() (
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
navigator: Navigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
formProvider: UkimsNumberFormProvider,
traderProfileConnector: TraderProfileConnector,
val controllerComponents: MessagesControllerComponents,
view: UkimsNumberView,
newView: NewUkimsNumberView
)(implicit ec: ExecutionContext)
extends BaseController {

private val form = formProvider()

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

Ok(newView(preparedForm, routes.NewUkimsNumberController.onSubmit(mode)))
}

def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>
form
.bindFromRequest()
.fold(
formWithErrors =>
Future
.successful(BadRequest(newView(formWithErrors, routes.NewUkimsNumberController.onSubmit(mode)))),
value =>
for {
profile <- traderProfileConnector.getTraderProfile(request.eori)
updatedAnswers <- Future.fromTry(request.userAnswers.set(NewUkimsNumberPage, value))
_ <- sessionRepository.set(updatedAnswers)
} yield
if (value == profile.ukimsNumber) {
val formWithApiErrors =
createFormWithErrors(form, value, "ukimsNumberChangeController.duplicateUkimsNumber")
BadRequest(view(formWithApiErrors, routes.NewUkimsNumberController.onSubmit(mode)))
} else {
Redirect(navigator.nextPage(NewUkimsNumberPage, mode, updatedAnswers))
}
)
}

private def createFormWithErrors[T](form: Form[T], value: T, errorMessageKey: String, field: String = "value")(
implicit messages: Messages
): Form[T] =
form
.fill(value)
.copy(errors = Seq(FormError(field, messages(errorMessageKey))))
}
27 changes: 27 additions & 0 deletions app/pages/NewUkimsNumberPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 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 pages

import play.api.libs.json.JsPath
import utils.Constants.ukimsNumberKey

case object NewUkimsNumberPage extends QuestionPage[String] {

override def path: JsPath = JsPath \ toString

override def toString: String = ukimsNumberKey
}
68 changes: 68 additions & 0 deletions app/views/NewUkimsNumberView.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@*
* Copyright 2024 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 viewmodels.LabelSize._
@import viewmodels.InputWidth._
@import models.Mode


@this(
layout: templates.Layout,
formHelper: FormWithCSRF,
govukErrorSummary: GovukErrorSummary,
govukInput: GovukInput,
govukButton: GovukButton
)

@(form: Form[_], action: Call, isCreateJourney: Boolean = false)(implicit request: Request[_], messages: Messages)

@layout(pageTitle = title(form, messages("newUkimsNumber.title"))) {

@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}

<h1 class="govuk-heading-l">@messages("newUkimsNumber.h1")</h1>
<p class="govuk-body">@messages("newUkimsNumber.p1")</p>
<p class="govuk-body">@messages("newUkimsNumber.p2")</p>

@formHelper(action = action, Symbol("autoComplete") -> "off") {

@govukInput(
InputViewModel(
field = form("value"),
label = LabelViewModel(messages("newUkimsNumber.heading")).withSize(Medium)
)
.withHint(
HintViewModel(messages("newUkimsNumber.hint"))
.withCssClass("text-overflow")
.withAttribute(("style", "word-wrap: break-word"))
)
.withWidth(Fixed30)
)

@govukButton(
ButtonViewModel(messages("site.continue"))
)
}

@if(isCreateJourney) {
<p class="govuk-body">
<a href="@routes.UkimsKickOutController.onPageLoad().url" class="govuk-link">@messages("newUkimsNumber.linkText")</a>
</p>
}

}
5 changes: 5 additions & 0 deletions conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ POST /create-profile/ukims-number
GET /create-profile/ukims-number/check controllers.UkimsNumberController.onPageLoadCreate(mode: Mode = CheckMode)
POST /create-profile/ukims-number/check controllers.UkimsNumberController.onSubmitCreate(mode: Mode = CheckMode)

GET /new/ukims-number controllers.NewUkimsNumberController.onPageLoad(mode: Mode = NormalMode)
POST /new/ukims-number controllers.NewUkimsNumberController.onSubmit(mode: Mode = NormalMode)
GET /new/ukims-number/check controllers.NewUkimsNumberController.onPageLoad(mode: Mode = CheckMode)
POST /new/ukims-number/check controllers.NewUkimsNumberController.onSubmit(mode: Mode = CheckMode)

GET /update-profile/ukims-number controllers.UkimsNumberController.onPageLoadUpdate(mode: Mode = NormalMode)
POST /update-profile/ukims-number controllers.UkimsNumberController.onSubmitUpdate(mode: Mode = NormalMode)
GET /update-profile/ukims-number/check controllers.UkimsNumberController.onPageLoadUpdate(mode: Mode = CheckMode)
Expand Down
14 changes: 14 additions & 0 deletions conf/messages.cy
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ ukimsNumber.error.invalidFormat = Nodwch eich rhif UKIMS yn y fformat cywir
ukimsNumber.checkYourAnswersLabel = Rhif UKIMS
ukimsNumber.change.hidden = Rhif UKIMS

newUkimsNumber.title = Rhif Cynllun Marchnad Fewnol y DU (UKIMS)
newUkimsNumber.h1 = Rhif Cynllun Marchnad Fewnol y DU (UKIMS)
newUkimsNumber.p1 = Mae CThEF yn anfon llythyr gyda rhif awdurdodi UKIMS ar ôl i chi wneud cais. Os nad ydych wedi cofrestru ar gyfer yr UKIMS, ni allwch ddefnyddio''r Proffil Nwyddau Masnachwyr (TGP).
newUkimsNumber.p2 = Mae rhif UKIMS yn dechrau â GB neu XI, wedi''u dilyn gan UKIM, ac mae''ch rhif EORI heb y GB neu''r XI, ac yna wedi''i ddilyn gan 14 o rifau.
newUkimsNumber.heading = Beth yw''ch rhif UKIMS?
newUkimsNumber.hint = Er enghraifft, XIUKIM47699357400020231115081800
newUkimsNumber.linkText = Nid ydwyf wedi fy nghofrestru ar gyfer yr UKIMS
newUkimsNumber.error.required = Nodwch eich rhif UKIMS
newUkimsNumber.error.invalidFormat = Nodwch eich rhif UKIMS yn y fformat cywir
newUkimsNumber.checkYourAnswersLabel = Rhif UKIMS
newUkimsNumber.change.hidden = Rhif UKIMS
hasNirms.title = Cynllun Symud Nwyddau Manwerthu Gogledd Iwerddon (NIRMS)
hasNirms.h1 = Cynllun Symud Nwyddau Manwerthu Gogledd Iwerddon (NIRMS)
hasNirms.h2 = A ydych wedi cofrestru ar gyfer y NIRMS?
Expand Down Expand Up @@ -508,6 +520,8 @@ hasCommodityCodeChange.advice = Bydd newid y cod nwyddau ar y cofnod nwyddau hwn
hasCommodityCodeChange.category = YBydd angen i chi gategoreiddio’r cofnod nwyddau hwn os byddwch yn newid y cod nwyddau.
hasCommodityCodeChange.error.required = Dewiswch os ydych am newid y cod nwyddau

# TODO: Need Welsh Translation for ukimsNumberChangeController.duplicateUkimsNumber. Comment has been added for content designer on TGP-2699


removeGoodsRecord.title = Tynnu’r cofnod nwyddau
removeGoodsRecord.heading = Tynnu’r cofnod nwyddau
Expand Down
13 changes: 13 additions & 0 deletions conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ ukimsNumber.error.invalidFormat = Enter your UKIMS number in the correct format
ukimsNumber.checkYourAnswersLabel = UKIMS number
ukimsNumber.change.hidden = UKIMS number

newUkimsNumber.title = UK Internal Market Scheme (UKIMS) number
newUkimsNumber.h1 = UK Internal Market Scheme (UKIMS) number
newUkimsNumber.p1 = HMRC send a letter with a UKIMS authorisation number after you apply. If you are not UKIMS registered, you can not use Trader Goods Profile (TGP).
newUkimsNumber.p2 = A UKIMS number starts with GB or XI, followed by UKIM, your EORI number without the GB or XI, then 14 numbers.
newUkimsNumber.heading = What is your UKIMS number?
newUkimsNumber.hint = For example, XIUKIM47699357400020231115081800
newUkimsNumber.linkText = I am not UKIMS registered
newUkimsNumber.error.required = Enter your UKIMS number
newUkimsNumber.error.invalidFormat = Enter your UKIMS number in the correct format
newUkimsNumber.checkYourAnswersLabel = UKIMS number
newUkimsNumber.change.hidden = UKIMS number

categoryGuidance.title = Categorisation
categoryGuidance.heading = Categorisation
categoryGuidance.p1 = Categorisation allows you to know what category your goods are in and if they are eligible for Simplified Process for Internal Market Movements (SPIMM).
Expand Down Expand Up @@ -471,6 +483,7 @@ ukimsNumberChangeController.title = UK Internal Market Scheme(UKIMS) number chan
ukimsNumberChangeController.heading = UK Internal Market Scheme(UKIMS) number change
ukimsNumberChangeController.paragraph = As you have a new EORI number, you also have a new UKIMS number. You need to update your UKIMS number on your TGP. Keeping your UKIMS number up to date is important as it can be used on movements.
ukimsNumberChangeController.button = Update UKIMS number
ukimsNumberChangeController.duplicateUkimsNumber = You’ve entered the previous UKIMS number. Enter the new UKIMS number.

profile.title = Profile details
profile.h1 = Profile details
Expand Down
Loading

0 comments on commit 9f2d071

Please sign in to comment.