Skip to content

Commit

Permalink
more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshhmrc committed Jun 6, 2018
1 parent 0accad2 commit d423c39
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit d423c39

Please sign in to comment.