-
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.
Merge remote-tracking branch 'origin/NINOA-57'
- Loading branch information
Showing
49 changed files
with
1,080 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
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 2019 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 v1.connectors | ||
|
||
import config.AppConfig | ||
import javax.inject.{Inject, Singleton} | ||
import play.api.libs.json.Json | ||
import uk.gov.hmrc.http.HeaderCarrier | ||
import uk.gov.hmrc.play.bootstrap.http.HttpClient | ||
import v1.connectors.httpParsers.HttpResponseTypes.HttpPostResponse | ||
import v1.connectors.httpParsers.RegisterNinoResponseHttpParser.RegisterNinoResponseReads | ||
import v1.models.request.NinoApplication | ||
import v1.models.response.DesResponseModel | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
@Singleton | ||
class DesConnector @Inject()( | ||
http: HttpClient, | ||
appConfig: AppConfig | ||
) { | ||
|
||
def sendRegisterRequest(request: NinoApplication) | ||
(implicit hc: HeaderCarrier, ec: ExecutionContext): Future[HttpPostResponse[DesResponseModel]] = { | ||
|
||
val url = s"${appConfig.desBaseUrl()}/${appConfig.desContext()}" | ||
|
||
http.POST(url, Json.toJson(request))(implicitly, RegisterNinoResponseReads, hc, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2019 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 v1.connectors.httpParsers | ||
|
||
import v1.models.errors.Error | ||
|
||
object HttpResponseTypes { | ||
type HttpPostResponse[T] = Either[Error, T] | ||
} |
48 changes: 48 additions & 0 deletions
48
app/v1/connectors/httpParsers/RegisterNinoResponseHttpParser.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,48 @@ | ||
/* | ||
* Copyright 2019 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 v1.connectors.httpParsers | ||
|
||
import play.api.Logger | ||
import play.api.http.Status | ||
import uk.gov.hmrc.http.{HttpReads, HttpResponse} | ||
import v1.connectors.httpParsers.HttpResponseTypes.HttpPostResponse | ||
import v1.models.errors.{Error, InvalidJsonResponseError} | ||
import v1.models.response.DesResponseModel | ||
|
||
object RegisterNinoResponseHttpParser { | ||
|
||
implicit object RegisterNinoResponseReads extends HttpReads[HttpPostResponse[DesResponseModel]] { | ||
override def read(method: String, url: String, response: HttpResponse): HttpPostResponse[DesResponseModel] = { | ||
response.status match { | ||
case Status.OK => | ||
Logger.debug("[RegisterNinoResponseHttpParser][read] Status OK") | ||
response.json.validate[DesResponseModel].fold( | ||
invalid => { | ||
Logger.debug(s"[RegisterNinoResponseHttpParser][read] Invalid json - $invalid") | ||
Logger.warn(s"[RegisterNinoResponseHttpParser][read] Invalid json") | ||
Left(InvalidJsonResponseError) | ||
}, | ||
Right(_) | ||
) | ||
case status => | ||
Logger.warn(s"[RegisterNinoResponseHttpParser][read] Unexpected $status response returned") | ||
Left(Error(s"$status", "Downstream error returned from DES when submitting a NINO register request")) | ||
} | ||
} | ||
} | ||
|
||
} |
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
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
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
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
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,25 @@ | ||
/* | ||
* Copyright 2019 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 v1.models.response | ||
|
||
import play.api.libs.json.{Format, Json} | ||
|
||
case class DesResponseModel(message: String) | ||
|
||
object DesResponseModel { | ||
implicit val formats: Format[DesResponseModel] = Json.format[DesResponseModel] | ||
} |
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,38 @@ | ||
/* | ||
* Copyright 2019 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 v1.services | ||
|
||
import javax.inject.{Inject, Singleton} | ||
import uk.gov.hmrc.http.HeaderCarrier | ||
import v1.connectors.DesConnector | ||
import v1.connectors.httpParsers.HttpResponseTypes.HttpPostResponse | ||
import v1.models.request.NinoApplication | ||
import v1.models.response.DesResponseModel | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
@Singleton | ||
class DesService @Inject()( | ||
desConnector: DesConnector | ||
) { | ||
|
||
def registerNino(ninoApplication: NinoApplication) | ||
(implicit hc: HeaderCarrier, ec: ExecutionContext): Future[HttpPostResponse[DesResponseModel]] = { | ||
desConnector.sendRegisterRequest(ninoApplication) | ||
} | ||
|
||
} |
Oops, something went wrong.