Skip to content

Commit

Permalink
Merge branch 'PIN-4084' into PIN-4257
Browse files Browse the repository at this point in the history
  • Loading branch information
nttdata-rtorsoli authored Nov 27, 2023
2 parents b887187 + 515ec77 commit a5ce5c3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
23 changes: 10 additions & 13 deletions src/main/resources/interface-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -230,18 +229,18 @@ 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
.fold(createTenant(seed, Nil, now, getTenantKind(Nil, seed.externalId).fromAPI))(Future.successful)
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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] = jsonFormat12(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]

Expand Down

0 comments on commit a5ce5c3

Please sign in to comment.