-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f4b38a
commit baf3b3f
Showing
6 changed files
with
159 additions
and
13 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
45 changes: 45 additions & 0 deletions
45
app/uk/gov/hmrc/helptosavetestadminfrontend/controllers/HelpToSaveApiController.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,45 @@ | ||
/* | ||
* 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.controllers | ||
|
||
import com.google.inject.Inject | ||
import play.api.i18n.{I18nSupport, MessagesApi} | ||
import play.api.mvc.{Action, AnyContent} | ||
import uk.gov.hmrc.helptosavetestadminfrontend.config.AppConfig | ||
import uk.gov.hmrc.helptosavetestadminfrontend.http.WSHttp | ||
import uk.gov.hmrc.helptosavetestadminfrontend.util.Logging | ||
|
||
import scala.concurrent.Future | ||
|
||
class HelpToSaveApiController @Inject()(http: WSHttp)(implicit override val appConfig: AppConfig, val messageApi: MessagesApi) | ||
extends AdminFrontendController(messageApi, appConfig) with I18nSupport with Logging { | ||
|
||
def checkEligibility: Action[AnyContent] = Action.async { implicit request => | ||
Future.successful(SeeOther(appConfig.oAuthRedirectUrl(appConfig.eligibilityCallbackUrl))) | ||
} | ||
|
||
def eligibilityCallback: Action[AnyContent] = Action.async { implicit request => | ||
logger.info(s"inside eligibilityCallback, queryString =${request.queryString}") | ||
Future.successful(Ok("success")) | ||
} | ||
|
||
def accountCallback: Action[AnyContent] = Action.async { implicit request => | ||
logger.info(s"inside accountCallback, queryString =${request.queryString}") | ||
Future.successful(Ok("success")) | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
app/uk/gov/hmrc/helptosavetestadminfrontend/http/WSHttp.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,73 @@ | ||
/* | ||
* 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.http | ||
|
||
import com.google.inject.{ImplementedBy, Inject, Singleton} | ||
import play.api.Mode.Mode | ||
import play.api.libs.json.Writes | ||
import play.api.{Configuration, Environment} | ||
import uk.gov.hmrc.http._ | ||
import uk.gov.hmrc.http.hooks.HttpHook | ||
import uk.gov.hmrc.play.audit.http.HttpAuditing | ||
import uk.gov.hmrc.play.audit.http.connector.AuditConnector | ||
import uk.gov.hmrc.play.config.ServicesConfig | ||
import uk.gov.hmrc.play.http.ws.{WSGet, WSPost} | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
@ImplementedBy(classOf[WSHttpExtension]) | ||
trait WSHttp extends HttpPost with WSPost with HttpGet with WSGet { | ||
|
||
def get(url: String, headers: Map[String, String] = Map.empty[String, String])(implicit hc: HeaderCarrier, ec: ExecutionContext): Future[HttpResponse] | ||
|
||
def post[A](url: String, | ||
body: A, | ||
headers: Map[String, String] = Map.empty[String, String] | ||
)(implicit w: Writes[A], hc: HeaderCarrier, ec: ExecutionContext): Future[HttpResponse] | ||
} | ||
|
||
@Singleton | ||
class WSHttpExtension @Inject() (val auditConnector: AuditConnector, | ||
val runModeConfiguration: Configuration, | ||
environment: Environment) | ||
extends WSHttp with HttpAuditing with ServicesConfig { | ||
|
||
val mode: Mode = environment.mode | ||
|
||
val httpReads: HttpReads[HttpResponse] = new HttpReads[HttpResponse] { | ||
override def read(method: String, url: String, response: HttpResponse): HttpResponse = response | ||
} | ||
|
||
override val hooks: Seq[HttpHook] = NoneRequired | ||
|
||
override def appName: String = getString("appName") | ||
|
||
override def mapErrors(httpMethod: String, url: String, f: Future[HttpResponse])(implicit ec: ExecutionContext): Future[HttpResponse] = f | ||
|
||
/** | ||
* Returns a [[Future[HttpResponse]] without throwing exceptions if the status us not `2xx`. Needed | ||
* to replace [[GET]] method provided by the hmrc library which will throw exceptions in such cases. | ||
*/ | ||
def get(url: String, headers: Map[String, String] = Map.empty[String, String])(implicit hc: HeaderCarrier, ec: ExecutionContext): Future[HttpResponse] = super.GET(url)(httpReads, hc, ec) | ||
|
||
def post[A](url: String, | ||
body: A, | ||
headers: Map[String, String] = Map.empty[String, String] | ||
)(implicit w: Writes[A], hc: HeaderCarrier, ec: ExecutionContext): Future[HttpResponse] = | ||
super.POST(url, body)(w, httpReads, hc.withExtraHeaders(headers.toSeq: _*), ec) | ||
|
||
} |
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