From 515ec77113e35125fca33ccaa824eae97a856c3c Mon Sep 17 00:00:00 2001 From: nttdata-rtorsoli Date: Fri, 24 Nov 2023 17:35:42 +0100 Subject: [PATCH] PIN-4084 Created ResourceId --- .../resources/interface-specification.yml | 23 ++++++++----------- .../api/impl/TenantApiMarshallerImpl.scala | 4 ++-- .../api/impl/TenantApiServiceImpl.scala | 9 ++++---- .../tenantprocess/api/impl/package.scala | 10 ++++---- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/main/resources/interface-specification.yml b/src/main/resources/interface-specification.yml index a920616..acc5954 100644 --- a/src/main/resources/interface-specification.yml +++ b/src/main/resources/interface-specification.yml @@ -221,7 +221,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/CompactTenant' + $ref: '#/components/schemas/ResourceId' '409': description: Selfcare Id is already assigned and is different from the request content: @@ -817,18 +817,15 @@ components: maxLength: 64 required: - code - CompactTenant: - description: Tenant Compact model - type: object - properties: - id: - type: string - format: uuid - externalId: - $ref: '#/components/schemas/ExternalId' - required: - - id - - externalId + ResourceId: + description: Modified resource id + type: object + properties: + id: + type: string + format: uuid + required: + - id Tenant: description: Tenant model type: object diff --git a/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/TenantApiMarshallerImpl.scala b/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/TenantApiMarshallerImpl.scala index 5bf0c20..eb39a40 100644 --- a/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/TenantApiMarshallerImpl.scala +++ b/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/TenantApiMarshallerImpl.scala @@ -39,6 +39,6 @@ object TenantApiMarshallerImpl extends TenantApiMarshaller with SprayJsonSupport override implicit def fromEntityUnmarshallerMailSeed: FromEntityUnmarshaller[MailSeed] = sprayJsonUnmarshaller[MailSeed] - override implicit def toEntityMarshallerCompactTenant: ToEntityMarshaller[CompactTenant] = - sprayJsonMarshaller[CompactTenant] + override implicit def toEntityMarshallerResourceId: ToEntityMarshaller[ResourceId] = + sprayJsonMarshaller[ResourceId] } diff --git a/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/TenantApiServiceImpl.scala b/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/TenantApiServiceImpl.scala index a7607b4..c633509 100644 --- a/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/TenantApiServiceImpl.scala +++ b/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/TenantApiServiceImpl.scala @@ -38,7 +38,6 @@ import it.pagopa.interop.tenantprocess.api.adapters.TenantManagementAdapters._ import it.pagopa.interop.tenantprocess.error.ResponseHandlers._ import it.pagopa.interop.tenantprocess.error.TenantProcessErrors._ import it.pagopa.interop.tenantprocess.model._ -import it.pagopa.interop.tenantprocess.model.{CompactTenant => ProcessCompactTenant} import it.pagopa.interop.tenantprocess.service._ import it.pagopa.interop.tenantmanagement.model.tenant.PersistentExternalId @@ -208,7 +207,7 @@ final case class TenantApiServiceImpl( override def selfcareUpsertTenant(seed: SelfcareTenantSeed)(implicit contexts: Seq[(String, String)], - toEntityMarshallerTenant: ToEntityMarshaller[ProcessCompactTenant], + toEntityMarshallerTenant: ToEntityMarshaller[ResourceId], toEntityMarshallerProblem: ToEntityMarshaller[Problem] ): Route = authorize(ADMIN_ROLE, API_ROLE, SECURITY_ROLE, INTERNAL_ROLE) { val operationLabel = s"Creating tenant with external id ${seed.externalId} via SelfCare request" @@ -230,7 +229,7 @@ final case class TenantApiServiceImpl( tenant.selfcareId.fold(updateTenant())(verifyConflict) } - val result: Future[ProcessCompactTenant] = for { + val result: Future[ResourceId] = for { existingTenant <- findTenant(seed.externalId) _ <- existingTenant.traverse(t => assertResourceAllowed(t.id)) tenant <- existingTenant @@ -238,10 +237,10 @@ final case class TenantApiServiceImpl( tenantKind <- getTenantKindLoadingCertifiedAttributes(tenant.attributes, tenant.externalId) _ <- updateSelfcareId(tenant, tenantKind) _ <- tenantManagementService.addTenantMail(tenant.id, seed.digitalAddress.toDependency) - } yield ProcessCompactTenant(tenant.id, tenant.externalId.toApi) + } yield ResourceId(tenant.id) onComplete(result) { - selfcareUpsertTenantResponse[ProcessCompactTenant](operationLabel)(selfcareUpsertTenant200) + selfcareUpsertTenantResponse[ResourceId](operationLabel)(selfcareUpsertTenant200) } } diff --git a/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/package.scala b/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/package.scala index 50b4549..850fdf2 100644 --- a/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/package.scala +++ b/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/package.scala @@ -42,11 +42,11 @@ package object impl extends SprayJsonSupport with DefaultJsonProtocol { implicit def tenantVerifierFormat: RootJsonFormat[TenantVerifier] = jsonFormat4(TenantVerifier) implicit def tenantRevokerFormat: RootJsonFormat[TenantRevoker] = jsonFormat5(TenantRevoker) - implicit def compactTenantFormat: RootJsonFormat[CompactTenant] = jsonFormat2(CompactTenant) - implicit def tenantFormat: RootJsonFormat[Tenant] = jsonFormat11(Tenant) - implicit def tenantsFormat: RootJsonFormat[Tenants] = jsonFormat2(Tenants) - implicit def problemErrorFormat: RootJsonFormat[ProblemError] = jsonFormat2(ProblemError) - implicit def problemFormat: RootJsonFormat[Problem] = jsonFormat6(Problem) + implicit def resourceIdFormat: RootJsonFormat[ResourceId] = jsonFormat1(ResourceId) + implicit def tenantFormat: RootJsonFormat[Tenant] = jsonFormat11(Tenant) + implicit def tenantsFormat: RootJsonFormat[Tenants] = jsonFormat2(Tenants) + implicit def problemErrorFormat: RootJsonFormat[ProblemError] = jsonFormat2(ProblemError) + implicit def problemFormat: RootJsonFormat[Problem] = jsonFormat6(Problem) final val entityMarshallerProblem: ToEntityMarshaller[Problem] = sprayJsonMarshaller[Problem]