From d423c39c3e39b9fec401b59b52b919a3fce19e21 Mon Sep 17 00:00:00 2001 From: Suresh Mandalapu Date: Wed, 6 Jun 2018 16:07:29 +0100 Subject: [PATCH] more changes --- .../controllers/HelpToSaveApiController.scala | 55 ++++++++++++++++++- .../forms/CreateAccountForm.scala | 54 ++++++++++++++++++ .../views/get_create_account_page.scala.html | 4 +- 3 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 app/uk/gov/hmrc/helptosavetestadminfrontend/forms/CreateAccountForm.scala diff --git a/app/uk/gov/hmrc/helptosavetestadminfrontend/controllers/HelpToSaveApiController.scala b/app/uk/gov/hmrc/helptosavetestadminfrontend/controllers/HelpToSaveApiController.scala index 370e43e..b309aa0 100644 --- a/app/uk/gov/hmrc/helptosavetestadminfrontend/controllers/HelpToSaveApiController.scala +++ b/app/uk/gov/hmrc/helptosavetestadminfrontend/controllers/HelpToSaveApiController.scala @@ -25,7 +25,7 @@ import play.api.libs.json.Json import play.api.mvc.{Action, AnyContent} import uk.gov.hmrc.helptosavetestadminfrontend.config.AppConfig import uk.gov.hmrc.helptosavetestadminfrontend.connectors.AuthConnector -import uk.gov.hmrc.helptosavetestadminfrontend.forms.EligibilityRequestForm +import uk.gov.hmrc.helptosavetestadminfrontend.forms.{CreateAccountForm, EligibilityRequestForm} import uk.gov.hmrc.helptosavetestadminfrontend.http.WSHttp import uk.gov.hmrc.helptosavetestadminfrontend.util.Logging import uk.gov.hmrc.helptosavetestadminfrontend.views @@ -123,11 +123,60 @@ class HelpToSaveApiController @Inject()(http: WSHttp, authConnector: AuthConnect } def getCreateAccountPage(): Action[AnyContent] = Action.async { implicit request => - Future.successful(Ok(views.html.get_check_eligibility_page(EligibilityRequestForm.eligibilityForm))) + Future.successful(Ok(views.html.get_create_account_page(CreateAccountForm.createAccountForm))) } def createAccount(): Action[AnyContent] = Action.async { implicit request => - Future.successful(Ok("success")) + CreateAccountForm.createAccountForm.bindFromRequest().fold( + formWithErrors ⇒ Future.successful(Ok(views.html.get_create_account_page(formWithErrors))), + { + params => + val headers = + Map("Content-Type" -> params.contentType, + "Accept" -> params.accept, + "Gov-Client-User-ID" -> params.govClientUserId, + "Gov-Client-Timezone" -> params.govClientTimezone, + "Gov-Vendor-Version" -> params.govVendorVersion, + "Gov-Vendor-Instance-ID" -> params.govVendorInstanceId, + "Authorization" -> s"Bearer ${tokenCache.get("token")}", + "Cache-Control" -> params.cacheControl + ) + + http.get(s"${appConfig.apiUrl}/individuals/help-to-save/eligibility/${params.nino}", headers) + .map { + response => + response.status match { + case OK => logger.info(s"eligibility response body= ${response.body}") + case other: Int => + logger.warn(s"got $other status during get eligibility_check, body=${response.body}") + } + }.recover { + case ex ⇒ logger.warn(s"error during api eligibility call, error=${ex.getMessage}") + } + + val url = + s""" + |curl -v -X GET \ + |-H "Content-Type: ${params.contentType}" \ + |-H "Accept: ${params.accept}" \ + |-H "Gov-Client-User-ID: ${params.govClientUserId}" \ + |-H "Gov-Client-Timezone: ${params.govClientTimezone}" \ + |-H "Gov-Vendor-Version: ${params.govVendorVersion}" \ + |-H "Gov-Vendor-Instance-ID: ${params.govVendorInstanceId}" \ + |-H "Authorization: Bearer ${tokenCache.get("token")}" \ + |-H "Cache-Control: ${params.cacheControl}" \ + | -d '{ \ + | "header": { \ + | "version": ${params.version}, \ + | "createdTimestamp": ${params.createdTimestamp}, \ + | "clientCode": ${params.clientCode}, \ + | "requestCorrelationId": ${params.requestCorrelationId} \ + | }}' "${appConfig.apiUrl}/individuals/help-to-save/eligibility/${params.nino}" + |""".stripMargin + + Future.successful(Ok(url)) + } + ) } def authorizeCallback(code: String): Action[AnyContent] = Action.async { implicit request => diff --git a/app/uk/gov/hmrc/helptosavetestadminfrontend/forms/CreateAccountForm.scala b/app/uk/gov/hmrc/helptosavetestadminfrontend/forms/CreateAccountForm.scala new file mode 100644 index 0000000..39224c6 --- /dev/null +++ b/app/uk/gov/hmrc/helptosavetestadminfrontend/forms/CreateAccountForm.scala @@ -0,0 +1,54 @@ +/* + * Copyright 2018 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.helptosavetestadminfrontend.forms + +import play.api.data.Forms._ +import play.api.data._ + +object CreateAccountForm { + + def createAccountForm = Form( + mapping( + "contentType" -> nonEmptyText, + "accept" -> nonEmptyText, + "govClientUserId" -> nonEmptyText, + "govClientTimezone" -> nonEmptyText, + "govVendorVersion" -> nonEmptyText, + "govVendorInstanceId" -> nonEmptyText, + "cacheControl" -> nonEmptyText, + "version" -> nonEmptyText, + "createdTimestamp" -> nonEmptyText, + "clientCode" -> nonEmptyText, + "requestCorrelationId" -> nonEmptyText, + "nino" -> nonEmptyText + )(CreateAccountParams.apply)(CreateAccountParams.unapply) + ) + +} + +case class CreateAccountParams(contentType: String, + accept: String, + govClientUserId: String, + govClientTimezone: String, + govVendorVersion: String, + govVendorInstanceId: String, + cacheControl: String, + version: String, + createdTimestamp: String, + clientCode: String, + requestCorrelationId: String, + nino: String) diff --git a/app/uk/gov/hmrc/helptosavetestadminfrontend/views/get_create_account_page.scala.html b/app/uk/gov/hmrc/helptosavetestadminfrontend/views/get_create_account_page.scala.html index 42596c4..e212a5d 100644 --- a/app/uk/gov/hmrc/helptosavetestadminfrontend/views/get_create_account_page.scala.html +++ b/app/uk/gov/hmrc/helptosavetestadminfrontend/views/get_create_account_page.scala.html @@ -16,10 +16,10 @@ @import uk.gov.hmrc.helptosavetestadminfrontend.config.AppConfig @import uk.gov.hmrc.helptosavetestadminfrontend.controllers.routes -@import uk.gov.hmrc.helptosavetestadminfrontend.forms.EligibilityParams +@import uk.gov.hmrc.helptosavetestadminfrontend.forms.CreateAccountParams @import uk.gov.hmrc.helptosavetestadminfrontend.views.html.helpers -@(form: Form[EligibilityParams])(implicit request: Request[_], messages: Messages, appConfig: AppConfig) +@(form: Form[CreateAccountParams])(implicit request: Request[_], messages: Messages, appConfig: AppConfig) @main_template(title = "help-to-save-test-admin-frontend", bodyClasses = None) { @helpers.form(routes.HelpToSaveApiController.checkEligibility(), 'id -> "inputForm") {