-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API-2532: Initial view of development: (#3)
* API-2532: Initial view of development: - hmrc library and SBT version upgrade - added default Play Guice DI - removed manual stubs - added mocking via mocking library - added scoverage plugin and `precheck.sh` - service locator no longer used * cleaning * cleaning * API-2532: cleaning README
- v0.117.0
- v0.116.0
- v0.115.0
- v0.114.0
- v0.113.0
- v0.112.0
- v0.111.0
- v0.110.0
- v0.109.0
- v0.108.0
- v0.107.0
- v0.106.0
- v0.105.0
- v0.104.0
- v0.103.0
- v0.102.0
- v0.101.0
- v0.100.0
- v0.99.0
- v0.98.0
- v0.97.1
- v0.97.0
- v0.96.0
- v0.95.0
- v0.94.0
- v0.93.0
- v0.92.0
- v0.91.0
- v0.90.0
- v0.89.0
- v0.88.0
- v0.87.0
- v0.86.0
- v0.85.0
- v0.84.0
- v0.83.0
- v0.82.0
- v0.81.0
- v0.80.0
- v0.79.0
- v0.78.0
- v0.77.0
- v0.76.0
- v0.75.0
- v0.74.0
- v0.73.0
- v0.72.0
- v0.71.0
- v0.70.0
- v0.69.0
- v0.68.0
- v0.67.0
- v0.66.0
- v0.65.0
- v0.64.0
- v0.63.0
- v0.62.0
- v0.61.0
- v0.60.0
- v0.59.0
- v0.58.0
- v0.57.0
- v0.56.0
- v0.55.0
- v0.54.0
- v0.53.0
- v0.52.0
- v0.51.0
- v0.50.0
- v0.49.0
- v0.48.0
- v0.47.0
- v0.46.0
- v0.45.0
- v0.44.0
- v0.43.0
- v0.42.0
- v0.41.0
- v0.40.0
- v0.39.0
- v0.38.0
- v0.37.0
- v0.36.0
- v0.35.0
- v0.34.0
- v0.33.0
- v0.32.0
- v0.31.0
- v0.30.0
- v0.29.0
- v0.28.0
- v0.27.0
- v0.26.0
- v0.25.0
- v0.24.0
- v0.23.0
- v0.22.0
- v0.21.0
- v0.20.0
- v0.19.0
- v0.18.0
- v0.17.0
- v0.16.0
- v0.15.0
- v0.14.0
- v0.13.0
- v0.12.0
- v0.11.0
- v0.10.0
- v0.9.0
- v0.8.0
- v0.7.0
- v0.6.0
- v0.5.0
- v0.4.0
- v0.3.0
- v0.2.0
Showing
37 changed files
with
1,452 additions
and
287 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
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
49 changes: 49 additions & 0 deletions
49
app/uk/gov/hmrc/apisubscriptionfields/controller/CommonController.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,49 @@ | ||
/* | ||
* Copyright 2017 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.apisubscriptionfields.controller | ||
|
||
import play.api.Logger | ||
import play.api.libs.json.{JsError, JsSuccess, JsValue, Reads} | ||
import play.api.mvc.{Request, Result} | ||
import uk.gov.hmrc.apisubscriptionfields.model.JsErrorResponse | ||
import uk.gov.hmrc.play.microservice.controller.BaseController | ||
import uk.gov.hmrc.apisubscriptionfields.model.ErrorCode._ | ||
import scala.concurrent.Future | ||
import scala.util.{Failure, Success, Try} | ||
|
||
trait CommonController extends BaseController { | ||
|
||
override protected def withJsonBody[T] | ||
(f: (T) => Future[Result])(implicit request: Request[JsValue], m: Manifest[T], reads: Reads[T]): Future[Result] = { | ||
Try(request.body.validate[T]) match { | ||
case Success(JsSuccess(payload, _)) => f(payload) | ||
case Success(JsError(errs)) => Future.successful(UnprocessableEntity(JsErrorResponse(INVALID_REQUEST_PAYLOAD, JsError.toJson(errs)))) | ||
case Failure(e) => Future.successful(UnprocessableEntity(JsErrorResponse(INVALID_REQUEST_PAYLOAD, e.getMessage))) | ||
} | ||
} | ||
|
||
def recovery: PartialFunction[Throwable, Result] = { | ||
case e => handleException(e) | ||
} | ||
|
||
private[controller] def handleException(e: Throwable) = { | ||
Logger.error(s"An unexpected error occurred: ${e.getMessage}", e) | ||
InternalServerError(JsErrorResponse(UNKNOWN_ERROR, "An unexpected error occurred")) | ||
} | ||
|
||
} | ||
|
43 changes: 0 additions & 43 deletions
43
app/uk/gov/hmrc/apisubscriptionfields/model/ApiSubscriptionFields.scala
This file was deleted.
Oops, something went wrong.
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,62 @@ | ||
/* | ||
* Copyright 2017 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.apisubscriptionfields.model | ||
|
||
import java.util.UUID | ||
|
||
import scala.annotation.tailrec | ||
|
||
case class AppId(value: UUID) extends AnyVal | ||
|
||
case class ApiContext(value: String) extends AnyVal | ||
|
||
case class ApiVersion(value: String) extends AnyVal | ||
|
||
case class SubscriptionFieldsId(value: UUID) extends AnyVal | ||
|
||
object SubscriptionIdentifier { | ||
private val Separator = "##" | ||
private type SeparatorType = String | ||
|
||
def decode(text:String): Option[SubscriptionIdentifier] = { | ||
def findSeparator(separatorToFind: SeparatorType) : SeparatorType = { | ||
if (text.split(separatorToFind).length > 3) | ||
findSeparator(separatorToFind+Separator) | ||
else | ||
separatorToFind | ||
} | ||
|
||
val parts = text.split(findSeparator(Separator)) | ||
Some(SubscriptionIdentifier(AppId(UUID.fromString(parts(0))), ApiContext(parts(1)), ApiVersion(parts(2)))) | ||
} | ||
} | ||
|
||
case class SubscriptionIdentifier(applicationId: AppId, apiContext: ApiContext, apiVersion: ApiVersion) { | ||
import SubscriptionIdentifier._ | ||
|
||
def encode(): String = { | ||
@tailrec | ||
def findSeparator(text: String)(separatorToFind: SeparatorType): SeparatorType = | ||
if (!text.contains(separatorToFind)) | ||
separatorToFind | ||
else | ||
findSeparator(text)(separatorToFind+Separator) | ||
|
||
val longestSeparator: SeparatorType = findSeparator(apiVersion.value)(findSeparator(apiContext.value)(Separator)) | ||
s"${applicationId.value}$longestSeparator${apiContext.value}$longestSeparator${apiVersion.value}" | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/uk/gov/hmrc/apisubscriptionfields/model/Requests.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,20 @@ | ||
/* | ||
* Copyright 2017 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.apisubscriptionfields.model | ||
|
||
case class SubscriptionFieldsRequest(fields: Fields) | ||
|
Oops, something went wrong.