diff --git a/acceptance/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsUnhappySpec.scala b/acceptance/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsUnhappySpec.scala index 71fe4d9..88d08db 100644 --- a/acceptance/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsUnhappySpec.scala +++ b/acceptance/uk/gov/hmrc/apisubscriptionfields/ApiSubscriptionFieldsUnhappySpec.scala @@ -20,16 +20,16 @@ import org.scalatest.OptionValues import play.api.libs.json.Json import play.api.mvc._ import play.api.test.Helpers._ -import uk.gov.hmrc.apisubscriptionfields.model.ErrorCode.{INVALID_REQUEST_PAYLOAD, NOT_FOUND_CODE} +import uk.gov.hmrc.apisubscriptionfields.model.ErrorCode import uk.gov.hmrc.apisubscriptionfields.model.JsErrorResponse import uk.gov.hmrc.apisubscriptionfields.utils.ApplicationLogger import scala.concurrent.Future class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec - with OptionValues - with SubscriptionFieldsTestData - with ApplicationLogger { + with OptionValues + with SubscriptionFieldsTestData + with ApplicationLogger { Feature("Subscription-Fields") { appLogger.logger.info(s"App.mode = ${app.mode.toString}") @@ -37,7 +37,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec Scenario("the API is called to GET non-existing subscription fields") { Given("the API is called to GET non-existing subscription fields") - val request = createRequest(GET, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) + val request = createRequest(GET, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) When("a GET request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -48,7 +48,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe NOT_FOUND And("the response body is empty") - contentAsJson(resultFuture) shouldBe JsErrorResponse(NOT_FOUND_CODE, s"Subscription fields not found for ($fakeRawClientId, $fakeRawContext, $fakeRawVersion)") + contentAsJson(resultFuture) shouldBe JsErrorResponse(ErrorCode.NOT_FOUND, s"Subscription fields not found for ($fakeRawClientId, $fakeRawContext, $fakeRawVersion)") } Scenario("the API is called to GET with an unknown fieldsId") { @@ -66,7 +66,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe NOT_FOUND And("the response body is empty") - contentAsJson(resultFuture) shouldBe JsErrorResponse(NOT_FOUND_CODE, s"FieldsId (${FakeRawFieldsId.toString}) was not found") + contentAsJson(resultFuture) shouldBe JsErrorResponse(ErrorCode.NOT_FOUND, s"FieldsId (${FakeRawFieldsId.toString}) was not found") } Scenario("the API is called to GET an unknown application clientId") { @@ -84,7 +84,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe NOT_FOUND And("the response body is empty") - contentAsJson(resultFuture) shouldBe JsErrorResponse(NOT_FOUND_CODE, s"ClientId ($fakeRawClientId) was not found") + contentAsJson(resultFuture) shouldBe JsErrorResponse(ErrorCode.NOT_FOUND, s"ClientId ($fakeRawClientId) was not found") } Scenario("the API is called to DELETE an unknown subscription field") { @@ -102,7 +102,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe NOT_FOUND And("the response body is empty") - contentAsJson(resultFuture) shouldBe JsErrorResponse(NOT_FOUND_CODE, s"Subscription fields not found for ($fakeRawClientId, $fakeRawContext, $fakeRawVersion)") + contentAsJson(resultFuture) shouldBe JsErrorResponse(ErrorCode.NOT_FOUND, s"Subscription fields not found for ($fakeRawClientId, $fakeRawContext, $fakeRawVersion)") } Scenario("the API is called to PUT subscription fields with an invalid JSON payload") { @@ -121,13 +121,13 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe UNPROCESSABLE_ENTITY And("the response body contains error message") - contentAsJson(resultFuture) shouldBe JsErrorResponse(INVALID_REQUEST_PAYLOAD, _: Json.JsValueWrapper) + contentAsJson(resultFuture) shouldBe JsErrorResponse(ErrorCode.INVALID_REQUEST_PAYLOAD, _: Json.JsValueWrapper) } Scenario("the API is called to PUT subscription fields with an invalid non JSON payload") { Given("the API is called to PUT subscription fields with an invalid non JSON payload") - val request = createRequest(PUT, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) + val request = createRequest(PUT, subscriptionFieldsEndpoint(fakeRawClientId, fakeRawContext, fakeRawVersion)) .withBody(InvalidNonJsonPayload) When("a PUT request with data is sent to the API") @@ -140,7 +140,7 @@ class ApiSubscriptionFieldsUnhappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe UNSUPPORTED_MEDIA_TYPE And("the response body contains error message") - contentAsJson(resultFuture) shouldBe JsErrorResponse(INVALID_REQUEST_PAYLOAD, _: Json.JsValueWrapper) + contentAsJson(resultFuture) shouldBe JsErrorResponse(ErrorCode.INVALID_REQUEST_PAYLOAD, _: Json.JsValueWrapper) } } diff --git a/acceptance/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsUnhappySpec.scala b/acceptance/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsUnhappySpec.scala index 05114c1..ad6d13a 100644 --- a/acceptance/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsUnhappySpec.scala +++ b/acceptance/uk/gov/hmrc/apisubscriptionfields/SubscriptionFieldDefinitionsUnhappySpec.scala @@ -21,14 +21,14 @@ import play.api.libs.json.Json import play.api.mvc._ import play.api.mvc.request.RequestTarget import play.api.test.Helpers._ -import uk.gov.hmrc.apisubscriptionfields.model.ErrorCode.{INVALID_REQUEST_PAYLOAD, NOT_FOUND_CODE} +import uk.gov.hmrc.apisubscriptionfields.model.ErrorCode import uk.gov.hmrc.apisubscriptionfields.model.JsErrorResponse import scala.concurrent.Future class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec - with OptionValues - with SubscriptionFieldsTestData { + with OptionValues + with SubscriptionFieldsTestData { Feature("Fields-Definition") { Scenario("the API is called to GET an unknown fields definition") { @@ -46,7 +46,7 @@ class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe NOT_FOUND And("the response body contains error message") - contentAsJson(resultFuture) shouldBe JsErrorResponse(NOT_FOUND_CODE, s"Fields definition not found for (${FakeContext.value}, unknown)") + contentAsJson(resultFuture) shouldBe JsErrorResponse(ErrorCode.NOT_FOUND, s"Fields definition not found for (${FakeContext.value}, unknown)") } Scenario("the API is called to PUT a fields definition with an invalid JSON payload") { @@ -67,7 +67,7 @@ class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe UNPROCESSABLE_ENTITY And("the response body contains error message") - contentAsJson(resultFuture) shouldBe JsErrorResponse(INVALID_REQUEST_PAYLOAD, _: Json.JsValueWrapper) + contentAsJson(resultFuture) shouldBe JsErrorResponse(ErrorCode.INVALID_REQUEST_PAYLOAD, _: Json.JsValueWrapper) } Scenario("the API is called to PUT a fields definition with an invalid field definition type") { @@ -91,7 +91,6 @@ class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec .withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, fakeRawVersion), queryString = Map.empty)) .withJsonBody(Json.parse(invalidFieldDefinition)) - When("a PUT request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -102,7 +101,7 @@ class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe UNPROCESSABLE_ENTITY And("the response body contains error message") - contentAsJson(resultFuture) shouldBe JsErrorResponse(INVALID_REQUEST_PAYLOAD, _: Json.JsValueWrapper) + contentAsJson(resultFuture) shouldBe JsErrorResponse(ErrorCode.INVALID_REQUEST_PAYLOAD, _: Json.JsValueWrapper) } Scenario("the API is called to PUT a fields definition with an invalid non JSON payload") { @@ -124,7 +123,7 @@ class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe UNSUPPORTED_MEDIA_TYPE And("the response body contains error message") - contentAsJson(resultFuture) shouldBe JsErrorResponse(INVALID_REQUEST_PAYLOAD, _: Json.JsValueWrapper) + contentAsJson(resultFuture) shouldBe JsErrorResponse(ErrorCode.INVALID_REQUEST_PAYLOAD, _: Json.JsValueWrapper) } Scenario("the API is called to DELETE an unknown fields definition") { @@ -135,7 +134,6 @@ class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec .withMethod(DELETE) .withTarget(RequestTarget(uriString = "", path = definitionEndpoint(fakeRawContext, "unknown"), queryString = Map.empty)) - When("a GET request with data is sent to the API") val result: Option[Future[Result]] = route(app, request) @@ -146,7 +144,7 @@ class SubscriptionFieldDefinitionsUnhappySpec extends AcceptanceTestSpec status(resultFuture) shouldBe NOT_FOUND And("the response body is empty") - contentAsJson(resultFuture) shouldBe JsErrorResponse(NOT_FOUND_CODE, s"Fields definition not found for ($fakeRawContext, unknown)") + contentAsJson(resultFuture) shouldBe JsErrorResponse(ErrorCode.NOT_FOUND, s"Fields definition not found for ($fakeRawContext, unknown)") } } diff --git a/app/uk/gov/hmrc/apisubscriptionfields/controller/ApiFieldDefinitionsController.scala b/app/uk/gov/hmrc/apisubscriptionfields/controller/ApiFieldDefinitionsController.scala index bb7d7d8..9896553 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/controller/ApiFieldDefinitionsController.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/controller/ApiFieldDefinitionsController.scala @@ -42,7 +42,7 @@ class ApiFieldDefinitionsController @Inject() (cc: ControllerComponents, service } private def notFoundResponse(apiContext: ApiContext, apiVersion: ApiVersion) = - NotFound(JsErrorResponse(ErrorCode.NOT_FOUND_CODE, s"Fields definition not found for (${apiContext.value}, ${apiVersion.value})")) + NotFound(JsErrorResponse(ErrorCode.NOT_FOUND, s"Fields definition not found for (${apiContext.value}, ${apiVersion.value})")) def validateFieldsDefinition(): Action[JsValue] = Action(parse.json) { request => Try(request.body.validate[FieldDefinitionsRequest]) match { diff --git a/app/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsController.scala b/app/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsController.scala index 2d76f8c..70ddddc 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsController.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/controller/SubscriptionFieldsController.scala @@ -32,7 +32,7 @@ class SubscriptionFieldsController @Inject() (cc: ControllerComponents, service: import JsonFormatters._ private def notFoundResponse(message: String) = { - NotFound(JsErrorResponse(NOT_FOUND_CODE, message)) + NotFound(JsErrorResponse(ErrorCode.NOT_FOUND, message)) } private def notFoundMessage(clientId: ClientId, apiContext: ApiContext, apiVersion: ApiVersion): String = { diff --git a/app/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatters.scala b/app/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatters.scala index feb5722..76728a6 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatters.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/model/JsonFormatters.scala @@ -24,7 +24,6 @@ import play.api.libs.functional.syntax._ import play.api.libs.json.Json.JsValueWrapper import play.api.libs.json._ -import uk.gov.hmrc.apisubscriptionfields.model.FieldDefinitionType.FieldDefinitionType import uk.gov.hmrc.apisubscriptionfields.model.Types._ trait NonEmptyListFormatters { @@ -114,8 +113,6 @@ trait JsonFormatters extends NonEmptyListFormatters with AccessRequirementsForma implicit val ValidationJF: OFormat[ValidationGroup] = Json.format[ValidationGroup] - implicit val FieldDefinitionTypeReads: Reads[FieldDefinitionType] = Reads.enumNameReads(FieldDefinitionType) - implicit val FieldDefinitionReads: Reads[FieldDefinition] = ( (JsPath \ "name").read[FieldName] and (JsPath \ "description").read[String] and diff --git a/app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala b/app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala index 94ff591..9646088 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala @@ -19,7 +19,9 @@ package uk.gov.hmrc.apisubscriptionfields.model import cats.data.{NonEmptyList => NEL} import org.apache.commons.validator.routines.{DomainValidator, UrlValidator} -import uk.gov.hmrc.apisubscriptionfields.model.FieldDefinitionType.FieldDefinitionType +import play.api.libs.json.Format +import uk.gov.hmrc.apiplatform.modules.common.domain.services.SealedTraitJsonFormatting + import uk.gov.hmrc.apisubscriptionfields.model.Types._ sealed trait ValidationRule { @@ -48,14 +50,32 @@ case object UrlValidationRule extends ValidationRule { case class ValidationGroup(errorMessage: String, rules: NEL[ValidationRule]) -object FieldDefinitionType extends Enumeration { - type FieldDefinitionType = Value +sealed trait FieldDefinitionType { + lazy val label = FieldDefinitionType.label(this) +} + +object FieldDefinitionType { @deprecated("We don't use URL type for any validation", since = "0.5x") - val URL = Value("URL") - val SECURE_TOKEN = Value("SecureToken") - val STRING = Value("STRING") - val PPNS_FIELD = Value("PPNSField") + case object URL extends FieldDefinitionType + case object SECURE_TOKEN extends FieldDefinitionType + case object STRING extends FieldDefinitionType + case object PPNS_FIELD extends FieldDefinitionType + + val values = Set(URL, SECURE_TOKEN, STRING, PPNS_FIELD) + + def apply(text: String): Option[FieldDefinitionType] = FieldDefinitionType.values.find(_.label == text) + + def unsafeApply(text: String): FieldDefinitionType = apply(text).getOrElse(throw new RuntimeException(s"$text is not a valid Field Definition Type")) + + def label(fdt: FieldDefinitionType): String = fdt match { + case URL => "URL" + case SECURE_TOKEN => "SecureToken" + case STRING => "STRING" + case PPNS_FIELD => "PPNSField" + } + Format + implicit val format: Format[FieldDefinitionType] = SealedTraitJsonFormatting.createFormatFor[FieldDefinitionType]("Field Definition Type", apply, label) } case class FieldDefinition( diff --git a/app/uk/gov/hmrc/apisubscriptionfields/model/Responses.scala b/app/uk/gov/hmrc/apisubscriptionfields/model/Responses.scala index cb3371a..52f3ba4 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/model/Responses.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/model/Responses.scala @@ -17,7 +17,8 @@ package uk.gov.hmrc.apisubscriptionfields.model import play.api.libs.json.Json.JsValueWrapper -import play.api.libs.json.{JsObject, Json} +import play.api.libs.json.{Format, JsObject, Json} +import uk.gov.hmrc.apiplatform.modules.common.domain.services.SealedTraitJsonFormatting import uk.gov.hmrc.apisubscriptionfields.model.Types._ @@ -38,17 +39,26 @@ sealed trait PPNSCallBackUrlValidationResponse case object PPNSCallBackUrlSuccessResponse extends PPNSCallBackUrlValidationResponse case class PPNSCallBackUrlFailedResponse(errorMsg: String) extends PPNSCallBackUrlValidationResponse -object ErrorCode extends Enumeration { - type ErrorCode = Value +sealed trait ErrorCode - val INVALID_REQUEST_PAYLOAD = Value("INVALID_REQUEST_PAYLOAD") - val UNKNOWN_ERROR = Value("UNKNOWN_ERROR") - val NOT_FOUND_CODE = Value("NOT_FOUND") +object ErrorCode { + + case object INVALID_REQUEST_PAYLOAD extends ErrorCode + case object UNKNOWN_ERROR extends ErrorCode + case object NOT_FOUND extends ErrorCode + + val values = Set(INVALID_REQUEST_PAYLOAD, UNKNOWN_ERROR, NOT_FOUND) + + def apply(text: String): Option[ErrorCode] = ErrorCode.values.find(_.toString() == text.toUpperCase) + + def unsafeApply(text: String): ErrorCode = apply(text).getOrElse(throw new RuntimeException(s"$text is not a valid Error Code")) + + implicit val format: Format[ErrorCode] = SealedTraitJsonFormatting.createFormatFor[ErrorCode]("Error Code", apply) } object JsErrorResponse { - def apply(errorCode: ErrorCode.Value, message: JsValueWrapper): JsObject = + def apply(errorCode: ErrorCode, message: JsValueWrapper): JsObject = Json.obj( "code" -> errorCode.toString, "message" -> message diff --git a/app/uk/gov/hmrc/apisubscriptionfields/repository/FieldDefinitionRepository.scala b/app/uk/gov/hmrc/apisubscriptionfields/repository/FieldDefinitionRepository.scala index 85839c2..7d79da0 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/repository/FieldDefinitionRepository.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/repository/FieldDefinitionRepository.scala @@ -21,14 +21,12 @@ import scala.concurrent.{ExecutionContext, Future} import akka.stream.Materializer import com.google.inject.ImplementedBy -import org.bson.codecs.configuration.CodecRegistries.{fromCodecs, fromRegistries} import org.mongodb.scala.model.Filters.{and, equal} import org.mongodb.scala.model.Indexes.ascending import org.mongodb.scala.model.{Filters, IndexModel, IndexOptions} -import org.mongodb.scala.{MongoClient, MongoCollection} import uk.gov.hmrc.mongo.MongoComponent -import uk.gov.hmrc.mongo.play.json.{Codecs, CollectionFactory, PlayMongoRepository} +import uk.gov.hmrc.mongo.play.json.{Codecs, PlayMongoRepository} import uk.gov.hmrc.apisubscriptionfields.model.Types._ import uk.gov.hmrc.apisubscriptionfields.model._ @@ -52,6 +50,12 @@ class ApiFieldDefinitionsMongoRepository @Inject() (mongo: MongoComponent)(impli collectionName = "fieldsDefinitions", mongoComponent = mongo, domainFormat = JsonFormatters.ApiFieldDefinitionsJF, + extraCodecs = Seq( + Codecs.playFormatCodec(JsonFormatters.ApiContextJF), + Codecs.playFormatCodec(JsonFormatters.ApiVersionJF), + Codecs.playFormatCodec(JsonFormatters.ApiFieldDefinitionsJF), + Codecs.playFormatCodec(JsonFormatters.ValidationJF) + ), indexes = Seq( IndexModel( ascending(List("apiContext", "apiVersion"): _*), @@ -65,22 +69,6 @@ class ApiFieldDefinitionsMongoRepository @Inject() (mongo: MongoComponent)(impli with ApiFieldDefinitionsRepository with ApplicationLogger { - override lazy val collection: MongoCollection[ApiFieldDefinitions] = - CollectionFactory - .collection(mongo.database, collectionName, domainFormat) - .withCodecRegistry( - fromRegistries( - fromCodecs( - Codecs.playFormatCodec(domainFormat), - Codecs.playFormatCodec(JsonFormatters.ApiContextJF), - Codecs.playFormatCodec(JsonFormatters.ApiVersionJF), - Codecs.playFormatCodec(JsonFormatters.ApiFieldDefinitionsJF), - Codecs.playFormatCodec(JsonFormatters.ValidationJF) - ), - MongoClient.DEFAULT_CODEC_REGISTRY - ) - ) - def save(definitions: ApiFieldDefinitions): Future[(ApiFieldDefinitions, IsInsert)] = { val query = and(equal("apiContext", Codecs.toBson(definitions.apiContext.value)), equal("apiVersion", Codecs.toBson(definitions.apiVersion.value))) diff --git a/app/uk/gov/hmrc/apisubscriptionfields/repository/SubscriptionFieldsRepository.scala b/app/uk/gov/hmrc/apisubscriptionfields/repository/SubscriptionFieldsRepository.scala index b7e2ae9..2b88d5c 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/repository/SubscriptionFieldsRepository.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/repository/SubscriptionFieldsRepository.scala @@ -22,14 +22,12 @@ import scala.concurrent.{ExecutionContext, Future} import akka.stream.Materializer import com.google.inject.ImplementedBy -import org.bson.codecs.configuration.CodecRegistries.{fromCodecs, fromRegistries} import org.mongodb.scala.model.Filters.{and, equal} import org.mongodb.scala.model.Indexes.ascending import org.mongodb.scala.model.{IndexModel, IndexOptions} -import org.mongodb.scala.{MongoClient, MongoCollection} import uk.gov.hmrc.mongo.MongoComponent -import uk.gov.hmrc.mongo.play.json.{Codecs, CollectionFactory, PlayMongoRepository} +import uk.gov.hmrc.mongo.play.json.{Codecs, PlayMongoRepository} import uk.gov.hmrc.apisubscriptionfields.model.Types.{Fields, IsInsert} import uk.gov.hmrc.apisubscriptionfields.model._ @@ -61,6 +59,12 @@ class SubscriptionFieldsMongoRepository @Inject() (mongo: MongoComponent, uuidCr collectionName = "subscriptionFields", mongoComponent = mongo, domainFormat = JsonFormatters.SubscriptionFieldsJF, + extraCodecs = Seq( + Codecs.playFormatCodec(JsonFormatters.ApiContextJF), + Codecs.playFormatCodec(JsonFormatters.ApiVersionJF), + Codecs.playFormatCodec(JsonFormatters.SubscriptionFieldsIdjsonFormat), + Codecs.playFormatCodec(JsonFormatters.ValidationJF) + ), indexes = Seq( IndexModel( ascending(List("clientId", "apiContext", "apiVersion"): _*), @@ -86,22 +90,6 @@ class SubscriptionFieldsMongoRepository @Inject() (mongo: MongoComponent, uuidCr with ApplicationLogger with JsonFormatters { - override lazy val collection: MongoCollection[SubscriptionFields] = - CollectionFactory - .collection(mongo.database, collectionName, domainFormat) - .withCodecRegistry( - fromRegistries( - fromCodecs( - Codecs.playFormatCodec(domainFormat), - Codecs.playFormatCodec(JsonFormatters.ApiContextJF), - Codecs.playFormatCodec(JsonFormatters.ApiVersionJF), - Codecs.playFormatCodec(JsonFormatters.SubscriptionFieldsIdjsonFormat), - Codecs.playFormatCodec(JsonFormatters.ValidationJF) - ), - MongoClient.DEFAULT_CODEC_REGISTRY - ) - ) - override def saveAtomic(clientId: ClientId, apiContext: ApiContext, apiVersion: ApiVersion, fields: Fields): Future[(SubscriptionFields, IsInsert)] = { val query = and( equal("clientId", Codecs.toBson(clientId.value)), diff --git a/project/AppDependencies.scala b/project/AppDependencies.scala index b4d7ab9..6f5fafc 100644 --- a/project/AppDependencies.scala +++ b/project/AppDependencies.scala @@ -4,29 +4,30 @@ import play.core.PlayVersion object AppDependencies { def apply(): Seq[ModuleID] = dependencies ++ testDependencies - private lazy val mongoVersion = "0.74.0" - private lazy val bootstrapVersion = "7.12.0" + private lazy val mongoVersion = "1.7.0" + private lazy val bootstrapVersion = "7.23.0" + val commonDomainVersion = "0.10.0" private lazy val dependencies = Seq( - "uk.gov.hmrc" %% "bootstrap-backend-play-28" % bootstrapVersion, - "uk.gov.hmrc.mongo" %% "hmrc-mongo-play-28" % "0.68.0", - "org.julienrf" %% "play-json-derived-codecs" % "6.0.0", - "com.typesafe.play" %% "play-json" % "2.9.2", - "uk.gov.hmrc" %% "http-metrics" % "2.7.0", - "org.typelevel" %% "cats-core" % "2.6.1", - "eu.timepit" %% "refined" % "0.9.13", - "be.venneborg" %% "play28-refined" % "0.6.0", - "commons-validator" % "commons-validator" % "1.6", - "com.beachape" %% "enumeratum-play-json" % "1.6.0" + "uk.gov.hmrc" %% "bootstrap-backend-play-28" % bootstrapVersion, + "uk.gov.hmrc.mongo" %% "hmrc-mongo-play-28" % mongoVersion, + "org.julienrf" %% "play-json-derived-codecs" % "6.0.0", + "com.typesafe.play" %% "play-json" % "2.9.2", + "uk.gov.hmrc" %% "http-metrics" % "2.7.0", + "org.typelevel" %% "cats-core" % "2.9.0", + "eu.timepit" %% "refined" % "0.9.13", + "be.venneborg" %% "play28-refined" % "0.6.0", + "commons-validator" % "commons-validator" % "1.6", + "uk.gov.hmrc" %% "api-platform-common-domain" % commonDomainVersion ) private lazy val testDependencies = Seq( - "uk.gov.hmrc" %% "bootstrap-test-play-28" % bootstrapVersion, - "uk.gov.hmrc.mongo" %% "hmrc-mongo-test-play-28" % "0.68.0", - "org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0", - "org.mockito" %% "mockito-scala-scalatest" % "1.16.42", - "org.pegdown" % "pegdown" % "1.6.0", - "com.typesafe.play" %% "play-test" % play.core.PlayVersion.current, - "com.github.tomakehurst" % "wiremock-jre8-standalone" % "2.27.2" + "uk.gov.hmrc" %% "bootstrap-test-play-28" % bootstrapVersion, + "uk.gov.hmrc.mongo" %% "hmrc-mongo-test-play-28" % mongoVersion, + "uk.gov.hmrc" %% "api-platform-test-common-domain" % commonDomainVersion, + "org.pegdown" % "pegdown" % "1.6.0", + "org.mockito" %% "mockito-scala-scalatest" % "1.17.29", + "com.github.tomakehurst" % "wiremock-jre8-standalone" % "2.27.1", + "org.scalatest" %% "scalatest" % "3.2.17" ).map(d => d % "test,acceptance") }