Skip to content

Commit

Permalink
PIN-4219 tenant-management: Added Mail Id (#67)
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 033bef8 commit 79ca94b
Show file tree
Hide file tree
Showing 30 changed files with 604 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ object JsonFormats {
private implicit val ptmkFormat: RootJsonFormat[PersistentTenantMailKind] =
new RootJsonFormat[PersistentTenantMailKind] {
override def read(json: JsValue): PersistentTenantMailKind = json match {
case JsString("CONTACT_EMAIL") => PersistentTenantMailKind.ContactEmail
case JsString("CONTACT_EMAIL") => PersistentTenantMailKind.ContactEmail
case JsString("DIGITAL_ADDRESS") => PersistentTenantMailKind.DigitalAddress
case x => throw new DeserializationException(s"Unable to deserialize PersistentTenantKind: unmapped kind $x")
}
override def write(obj: PersistentTenantMailKind): JsValue = obj match {
case PersistentTenantMailKind.ContactEmail => JsString("CONTACT_EMAIL")
case PersistentTenantMailKind.ContactEmail => JsString("CONTACT_EMAIL")
case PersistentTenantMailKind.DigitalAddress => JsString("DIGITAL_ADDRESS")
}
}

Expand All @@ -80,8 +82,22 @@ object JsonFormats {
}
}

private implicit val ptmFormat: RootJsonFormat[PersistentTenantMail] = jsonFormat4(PersistentTenantMail.apply)
implicit val ptFormat: RootJsonFormat[PersistentTenant] = jsonFormat10(PersistentTenant.apply)
private implicit val ptutFormat: RootJsonFormat[PersistentTenantUnitType] =
new RootJsonFormat[PersistentTenantUnitType] {
override def read(json: JsValue): PersistentTenantUnitType = json match {
case JsString("AOO") => PersistentTenantUnitType.Aoo
case JsString("UO") => PersistentTenantUnitType.Uo
case x =>
throw new DeserializationException(s"Unable to deserialize PersistentTenantUnitType: unmapped type $x")
}
override def write(obj: PersistentTenantUnitType): JsValue = obj match {
case PersistentTenantUnitType.Aoo => JsString("AOO")
case PersistentTenantUnitType.Uo => JsString("UO")
}
}

implicit val ptmFormat: RootJsonFormat[PersistentTenantMail] = jsonFormat5(PersistentTenantMail.apply)
implicit val ptFormat: RootJsonFormat[PersistentTenant] = jsonFormat12(PersistentTenant.apply)

implicit val pcFormat: RootJsonFormat[TenantCreated] = jsonFormat1(TenantCreated.apply)
implicit val puFormat: RootJsonFormat[TenantUpdated] = jsonFormat1(TenantUpdated.apply)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@ object TenantEventsSerde {
case x: TenantUpdated => x.toJson
case x: SelfcareMappingCreated => x.toJson
case x: SelfcareMappingDeleted => x.toJson
case x: TenantMailAdded => x.toJson
}

private val tenantCreated: String = "tenant-created"
private val tenantUpdated: String = "tenant-updated"
private val tenantDeleted: String = "tenant-deleted"
private val selfcareMappingCreated: String = "selfcare-mapping-created"
private val selfcareMappingDeleted: String = "selfcare-mapping-deleted"
private val tenantMailAdded: String = "tenant-mail-added"
private val tenantMailDeleted: String = "tenant-mail-deleted"

val jsonToTenant: PartialFunction[String, JsValue => ProjectableEvent] = {
case `tenantCreated` => _.convertTo[TenantCreated]
case `tenantUpdated` => _.convertTo[TenantUpdated]
case `tenantDeleted` => _.convertTo[TenantDeleted]
case `tenantMailAdded` => _.convertTo[TenantMailAdded]
case `tenantMailDeleted` => _.convertTo[TenantMailDeleted]
case `selfcareMappingCreated` => _.convertTo[SelfcareMappingCreated]
case `selfcareMappingDeleted` => _.convertTo[SelfcareMappingDeleted]
}
Expand All @@ -37,6 +42,8 @@ object TenantEventsSerde {
case TenantDeleted(_) => tenantDeleted
case SelfcareMappingCreated(_, _) => selfcareMappingCreated
case SelfcareMappingDeleted(_) => selfcareMappingDeleted
case TenantMailAdded(_, _, _) => tenantMailAdded
case TenantMailDeleted(_, _, _) => tenantMailDeleted
}

// Serdes
Expand Down Expand Up @@ -115,11 +122,13 @@ object TenantEventsSerde {
private implicit val ptmkFormat: RootJsonFormat[PersistentTenantMailKind] =
new RootJsonFormat[PersistentTenantMailKind] {
override def read(json: JsValue): PersistentTenantMailKind = json match {
case JsString("CONTACT_EMAIL") => PersistentTenantMailKind.ContactEmail
case JsString("CONTACT_EMAIL") => PersistentTenantMailKind.ContactEmail
case JsString("DIGITAL_ADDRESS") => PersistentTenantMailKind.DigitalAddress
case x => throw new DeserializationException(s"Unable to deserialize PersistentTenantKind: unmapped kind $x")
}
override def write(obj: PersistentTenantMailKind): JsValue = obj match {
case PersistentTenantMailKind.ContactEmail => JsString("CONTACT_EMAIL")
case PersistentTenantMailKind.ContactEmail => JsString("CONTACT_EMAIL")
case PersistentTenantMailKind.DigitalAddress => JsString("DIGITAL_ADDRESS")
}
}

Expand All @@ -138,13 +147,29 @@ object TenantEventsSerde {
}
}

private implicit val ptmFormat: RootJsonFormat[PersistentTenantMail] = jsonFormat4(PersistentTenantMail.apply)
private implicit val ptutFormat: RootJsonFormat[PersistentTenantUnitType] =
new RootJsonFormat[PersistentTenantUnitType] {
override def read(json: JsValue): PersistentTenantUnitType = json match {
case JsString("AOO") => PersistentTenantUnitType.Aoo
case JsString("UO") => PersistentTenantUnitType.Uo
case x =>
throw new DeserializationException(s"Unable to deserialize PersistentTenantUnitType: unmapped type $x")
}
override def write(obj: PersistentTenantUnitType): JsValue = obj match {
case PersistentTenantUnitType.Aoo => JsString("AOO")
case PersistentTenantUnitType.Uo => JsString("UO")
}
}

private implicit val ptmFormat: RootJsonFormat[PersistentTenantMail] = jsonFormat5(PersistentTenantMail.apply)
private implicit val pexFormat: RootJsonFormat[PersistentExternalId] = jsonFormat2(PersistentExternalId.apply)
private implicit val ptFormat: RootJsonFormat[PersistentTenant] = jsonFormat10(PersistentTenant.apply)
private implicit val ptFormat: RootJsonFormat[PersistentTenant] = jsonFormat12(PersistentTenant.apply)
private implicit val tcFormat: RootJsonFormat[TenantCreated] = jsonFormat1(TenantCreated.apply)
private implicit val tuFormat: RootJsonFormat[TenantUpdated] = jsonFormat1(TenantUpdated.apply)
private implicit val tdFormat: RootJsonFormat[TenantDeleted] = jsonFormat1(TenantDeleted.apply)
private implicit val scmcFormat: RootJsonFormat[SelfcareMappingCreated] = jsonFormat2(SelfcareMappingCreated.apply)
private implicit val scmdFormat: RootJsonFormat[SelfcareMappingDeleted] = jsonFormat1(SelfcareMappingDeleted.apply)
private implicit val tmaFormat: RootJsonFormat[TenantMailAdded] = jsonFormat3(TenantMailAdded.apply)
private implicit val tmdFormat: RootJsonFormat[TenantMailDeleted] = jsonFormat3(TenantMailDeleted.apply)

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import java.util.UUID

sealed trait Event extends Persistable with ProjectableEvent

final case class TenantCreated(tenant: PersistentTenant) extends Event
final case class TenantUpdated(tenant: PersistentTenant) extends Event
final case class TenantDeleted(tenantId: String) extends Event
final case class SelfcareMappingCreated(selfcareId: String, tenantId: UUID) extends Event
final case class SelfcareMappingDeleted(selfcareId: String) extends Event
final case class TenantCreated(tenant: PersistentTenant) extends Event
final case class TenantUpdated(tenant: PersistentTenant) extends Event
final case class TenantDeleted(tenantId: String) extends Event
final case class SelfcareMappingCreated(selfcareId: String, tenantId: UUID) extends Event
final case class SelfcareMappingDeleted(selfcareId: String) extends Event
final case class TenantMailAdded(tenantId: UUID, mailId: String, tenant: PersistentTenant) extends Event
final case class TenantMailDeleted(tenantId: UUID, mailId: String, tenant: PersistentTenant) extends Event
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ final case class PersistentTenant(
createdAt: OffsetDateTime,
updatedAt: Option[OffsetDateTime],
mails: List[PersistentTenantMail],
name: String
name: String,
onboardedAt: Option[OffsetDateTime],
subUnitType: Option[PersistentTenantUnitType]
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ final case class PersistentTenantDelta(
id: UUID,
selfcareId: Option[String],
features: List[PersistentTenantFeature],
mails: List[PersistentTenantMail],
kind: Option[PersistentTenantKind]
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package it.pagopa.interop.tenantmanagement.model.tenant
import java.time.OffsetDateTime

final case class PersistentTenantMail(
id: String,
kind: PersistentTenantMailKind,
address: String,
description: Option[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package it.pagopa.interop.tenantmanagement.model.tenant
sealed trait PersistentTenantMailKind

object PersistentTenantMailKind {
case object ContactEmail extends PersistentTenantMailKind
case object ContactEmail extends PersistentTenantMailKind
case object DigitalAddress extends PersistentTenantMailKind
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package it.pagopa.interop.tenantmanagement.model.tenant

sealed trait PersistentTenantUnitType

object PersistentTenantUnitType {
case object Aoo extends PersistentTenantUnitType
case object Uo extends PersistentTenantUnitType
}
12 changes: 12 additions & 0 deletions src/main/protobuf/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,16 @@ message SelfcareMappingCreatedV1 {

message SelfcareMappingDeletedV1 {
required string selfcareId = 1;
}

message TenantMailAddedV1 {
required string tenantId = 1;
required string mailId = 2;
required TenantV1 tenant = 3;
}

message TenantMailDeletedV1 {
required string tenantId = 1;
required string mailId = 2;
required TenantV1 tenant = 3;
}
9 changes: 9 additions & 0 deletions src/main/protobuf/v1/tenant.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ message TenantV1 {
repeated TenantMailV1 mails = 8;
optional string name = 9;
optional TenantKindV1 kind = 10;
optional int64 onboardedAt= 11;
optional TenantUnitTypeV1 subUnitType = 12;
}

enum TenantKindV1 {
Expand All @@ -33,10 +35,17 @@ message TenantMailV1 {
required string address = 2;
required int64 createdAt = 3;
optional string description = 4;
optional string id = 5;
}

enum TenantMailKindV1 {
CONTACT_EMAIL = 1;
DIGITAL_ADDRESS = 2;
}

enum TenantUnitTypeV1 {
AOO = 1;
UO = 2;
}

message TenantFeatureV1 {
Expand Down
93 changes: 88 additions & 5 deletions src/main/resources/interface-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,72 @@ 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'
'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
'404':
description: Tenant not found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/tenants/selfcareId/{selfcareId}:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
Expand Down Expand Up @@ -534,6 +600,11 @@ components:
$ref: '#/components/schemas/Mail'
name:
type: string
onboardedAt:
type: string
format: date-time
subUnitType:
$ref: '#/components/schemas/TenantUnitType'
required:
- id
- certifier
Expand All @@ -547,19 +618,24 @@ components:
description: A specific kind of mail
type: object
properties:
id:
type: string
kind:
$ref: '#/components/schemas/MailKind'
address:
type: string
description:
type: string
required:
- id
- kind
- address
Mail:
description: A specific kind of mail
type: object
properties:
id:
type: string
kind:
$ref: '#/components/schemas/MailKind'
address:
Expand All @@ -570,9 +646,15 @@ components:
description:
type: string
required:
- id
- kind
- address
- createdAt
TenantUnitType:
type: string
enum:
- AOO
- UO
TenantKind:
type: string
enum:
Expand All @@ -583,6 +665,7 @@ components:
type: string
enum:
- CONTACT_EMAIL
- DIGITAL_ADDRESS
ExternalId:
properties:
origin:
Expand Down Expand Up @@ -613,6 +696,11 @@ components:
type: string
kind:
$ref: '#/components/schemas/TenantKind'
onboardedAt:
type: string
format: date-time
subUnitType:
$ref: '#/components/schemas/TenantUnitType'
required:
- externalId
- features
Expand All @@ -629,15 +717,10 @@ components:
type: array
items:
$ref: '#/components/schemas/TenantFeature'
mails:
type: array
items:
$ref: '#/components/schemas/MailSeed'
kind:
$ref: '#/components/schemas/TenantKind'
required:
- features
- mails
- kind
securitySchemes:
bearerAuth:
Expand Down
Loading

0 comments on commit 79ca94b

Please sign in to comment.