Skip to content

Commit

Permalink
PIN-4220 tenant-process: Added Mail Id (#81)
Browse files Browse the repository at this point in the history
Co-authored-by: nttdata-rtorsoli <[email protected]>
  • Loading branch information
nttdata-rtorsoli and nttdata-rtorsoli authored Nov 28, 2023
1 parent 9ad8a40 commit d14720e
Show file tree
Hide file tree
Showing 18 changed files with 447 additions and 218 deletions.
148 changes: 112 additions & 36 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/Tenant'
$ref: '#/components/schemas/ResourceId'
'409':
description: Selfcare Id is already assigned and is different from the request
content:
Expand Down Expand Up @@ -410,30 +410,6 @@ paths:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
post:
tags:
- tenant
operationId: updateTenant
description: Updates the tenant
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/TenantDelta'
responses:
'200':
description: Tenant updated
content:
application/json:
schema:
$ref: '#/components/schemas/Tenant'
'404':
description: Tenant Not Found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/tenants/origin/{origin}/code/{code}:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
Expand Down Expand Up @@ -705,6 +681,84 @@ paths:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/tenants/{tenantId}/mails:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- name: tenantId
in: path
description: the tenant id
required: true
schema:
type: string
format: uuid
post:
tags:
- tenant
summary: Add a tenant mail
operationId: addTenantMail
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/MailSeed'
responses:
'204':
description: Tenant Mail Added
'400':
description: Invalid input
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
'403':
description: Forbidden
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
'404':
description: Tenant not found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/tenants/{tenantId}/mails/{mailId}:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- name: tenantId
in: path
description: the tenant id
required: true
schema:
type: string
format: uuid
- name: mailId
in: path
description: the mail id
required: true
schema:
type: string
delete:
tags:
- tenant
summary: Delete a tenant mail
operationId: deleteTenantMail
responses:
'204':
description: Tenant Mail Deleted
'403':
description: Forbidden
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
'404':
description: Tenant not found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/status:
get:
security: []
Expand Down Expand Up @@ -763,6 +817,15 @@ components:
maxLength: 64
required:
- code
ResourceId:
description: Modified resource id
type: object
properties:
id:
type: string
format: uuid
required:
- id
Tenant:
description: Tenant model
type: object
Expand Down Expand Up @@ -795,7 +858,12 @@ components:
name:
type: string
kind:
$ref: '#/components/schemas/TenantKind'
$ref: '#/components/schemas/TenantKind'
onboardedAt:
type: string
format: date-time
subUnitType:
$ref: '#/components/schemas/TenantUnitType'
required:
- id
- certifier
Expand Down Expand Up @@ -1014,20 +1082,24 @@ components:
type: string
minLength: 1
maxLength: 1000
digitalAddress:
$ref: '#/components/schemas/MailSeed'
onboardedAt:
type: string
format: date-time
subUnitType:
$ref: '#/components/schemas/TenantUnitType'
required:
- externalId
- selfcareId
- name
TenantDelta:
description: Tenant Delta model
type: object
properties:
mails:
type: array
items:
$ref: '#/components/schemas/MailSeed'
required:
- mails
- onboardedAt
- subUnitType
TenantUnitType:
type: string
enum:
- AOO
- UO
MailSeed:
description: A specific kind of mail
type: object
Expand All @@ -1049,6 +1121,8 @@ components:
description: A specific kind of mail
type: object
properties:
id:
type: string
kind:
$ref: '#/components/schemas/MailKind'
address:
Expand All @@ -1061,13 +1135,15 @@ components:
type: string
maxLength: 250
required:
- id
- kind
- address
- createdAt
MailKind:
type: string
enum:
- CONTACT_EMAIL
- DIGITAL_ADDRESS
Problem:
properties:
type:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.pagopa.interop.tenantprocess.api.adapters

import it.pagopa.interop.tenantmanagement.client.model.{TenantAttribute, TenantSeed, TenantKind}
import it.pagopa.interop.tenantprocess.api.adapters.ApiAdapters.ExternalIdWrapper
import it.pagopa.interop.tenantprocess.api.adapters.ApiAdapters._
import it.pagopa.interop.tenantprocess.model.{InternalTenantSeed, M2MTenantSeed, SelfcareTenantSeed}

import java.util.UUID
Expand Down Expand Up @@ -58,7 +58,9 @@ object AdaptableSeed {
features = Nil,
attributes = attributes,
name = a.name,
kind = kind
kind = kind,
onboardedAt = Some(a.onboardedAt),
subUnitType = Some(a.subUnitType.toDependency)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,28 @@ package it.pagopa.interop.tenantprocess.api.adapters

import cats.syntax.all._
import it.pagopa.interop.tenantmanagement.model.tenant.PersistentExternalId
import it.pagopa.interop.tenantmanagement.client.model.MailKind.CONTACT_EMAIL
import it.pagopa.interop.tenantmanagement.client.model.MailKind.{DIGITAL_ADDRESS, CONTACT_EMAIL}
import it.pagopa.interop.tenantmanagement.client.model.{
Certifier => DependencyCertifier,
DeclaredTenantAttribute => DependencyDeclaredTenantAttribute,
ExternalId => DependencyExternalId,
MailKind => DependencyMailKind,
MailSeed => DependencyMailSeed,
TenantAttribute => DependencyTenantAttribute,
TenantDelta => DependencyTenantDelta,
TenantFeature => DependencyTenantFeature,
TenantKind => DependencyTenantKind,
TenantVerifier => DependencyTenantVerifier,
VerifiedTenantAttribute => DependencyVerifiedTenantAttribute
VerifiedTenantAttribute => DependencyVerifiedTenantAttribute,
TenantUnitType => DependencyTenantUnitType
}
import it.pagopa.interop.tenantprocess.model._
import it.pagopa.interop.commons.utils.Digester.toSha256

import java.time.OffsetDateTime
import java.util.UUID

object ApiAdapters {

implicit class MailWrapper(private val m: Mail) extends AnyVal {
def fromAPI: DependencyMailSeed =
DependencyMailSeed(kind = m.kind.fromAPI, address = m.address, description = m.description)
}

implicit class TenantKindWrapper(private val tk: TenantKind) extends AnyVal {
def fromAPI: DependencyTenantKind = tk match {
case TenantKind.PA => DependencyTenantKind.PA
Expand All @@ -38,7 +34,8 @@ object ApiAdapters {

implicit class MailKindWrapper(private val mk: MailKind) extends AnyVal {
def fromAPI: DependencyMailKind = mk match {
case MailKind.CONTACT_EMAIL => CONTACT_EMAIL
case MailKind.CONTACT_EMAIL => CONTACT_EMAIL
case MailKind.DIGITAL_ADDRESS => DIGITAL_ADDRESS
}
}

Expand All @@ -50,18 +47,14 @@ object ApiAdapters {
def fromAPI: DependencyCertifier = DependencyCertifier(c.certifierId)
}

implicit class TenantDeltaWrapper(private val td: TenantDelta) extends AnyVal {
def fromAPI(
selfcareId: Option[String],
features: Seq[DependencyTenantFeature],
kind: DependencyTenantKind
): DependencyTenantDelta =
DependencyTenantDelta(selfcareId, features, mails = td.mails.map(_.toDependency), kind)
}

implicit class MailSeedWrapper(private val ms: MailSeed) extends AnyVal {
def toDependency: DependencyMailSeed =
DependencyMailSeed(kind = ms.kind.fromAPI, address = ms.address, description = ms.description)
DependencyMailSeed(
id = toSha256(ms.address.getBytes()),
kind = ms.kind.fromAPI,
address = ms.address,
description = ms.description
)
}

implicit class ExternalIdWrapper(private val id: ExternalId) extends AnyVal {
Expand All @@ -78,6 +71,13 @@ object ApiAdapters {
)
}

implicit class TenantUnitTypeWrapper(private val u: TenantUnitType) extends AnyVal {
def toDependency: DependencyTenantUnitType = u match {
case TenantUnitType.AOO => DependencyTenantUnitType.AOO
case TenantUnitType.UO => DependencyTenantUnitType.UO
}
}

implicit class VerifiedTenantAttributeSeedWrapper(private val seed: VerifiedTenantAttributeSeed) extends AnyVal {
def toCreateDependency(now: OffsetDateTime, requesterId: UUID): DependencyTenantAttribute =
DependencyTenantAttribute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ object ReadModelTenantAdapters extends SprayJsonSupport with DefaultJsonProtocol
attributes = t.attributes.map(_.toApi),
createdAt = t.createdAt,
updatedAt = t.updatedAt,
mails = t.mails.map(_.toApi)
onboardedAt = t.onboardedAt,
mails = t.mails.map(_.toApi),
subUnitType = t.subUnitType.map(_.toApi)
)
def toManagement: Management.Tenant = Management.Tenant(
id = t.id,
Expand All @@ -32,14 +34,17 @@ object ReadModelTenantAdapters extends SprayJsonSupport with DefaultJsonProtocol
attributes = t.attributes.map(_.toManagement),
createdAt = t.createdAt,
updatedAt = t.updatedAt,
mails = t.mails.map(_.toManagement)
onboardedAt = t.onboardedAt,
mails = t.mails.map(_.toManagement),
subUnitType = t.subUnitType.map(_.toManagement)
)
}

implicit class PersistentMailWrapper(private val m: PersistentTenantMail) extends AnyVal {
def toApi: Mail =
Mail(kind = m.kind.toApi, address = m.address, createdAt = m.createdAt, description = m.description)
Mail(id = m.id, kind = m.kind.toApi, address = m.address, createdAt = m.createdAt, description = m.description)
def toManagement: Management.Mail = Management.Mail(
id = m.id,
kind = m.kind.toManagement,
address = m.address,
createdAt = m.createdAt,
Expand All @@ -49,10 +54,23 @@ object ReadModelTenantAdapters extends SprayJsonSupport with DefaultJsonProtocol

implicit class PersistentMailKindWrapper(private val k: PersistentTenantMailKind) extends AnyVal {
def toApi: MailKind = k match {
case PersistentTenantMailKind.ContactEmail => MailKind.CONTACT_EMAIL
case PersistentTenantMailKind.ContactEmail => MailKind.CONTACT_EMAIL
case PersistentTenantMailKind.DigitalAddress => MailKind.DIGITAL_ADDRESS
}
def toManagement: Management.MailKind = k match {
case PersistentTenantMailKind.ContactEmail => Management.MailKind.CONTACT_EMAIL
case PersistentTenantMailKind.ContactEmail => Management.MailKind.CONTACT_EMAIL
case PersistentTenantMailKind.DigitalAddress => Management.MailKind.DIGITAL_ADDRESS
}
}

implicit class PersistentTenantUnitTypeWrapper(private val u: PersistentTenantUnitType) extends AnyVal {
def toApi: TenantUnitType = u match {
case PersistentTenantUnitType.Aoo => TenantUnitType.AOO
case PersistentTenantUnitType.Uo => TenantUnitType.UO
}
def toManagement: Management.TenantUnitType = u match {
case PersistentTenantUnitType.Aoo => Management.TenantUnitType.AOO
case PersistentTenantUnitType.Uo => Management.TenantUnitType.UO
}
}

Expand Down
Loading

0 comments on commit d14720e

Please sign in to comment.