From a23bfa23f4c7773280594e3b9142bae10a1a1d47 Mon Sep 17 00:00:00 2001 From: rschneider <97682836+rainer-exxcellent@users.noreply.github.com> Date: Tue, 6 Jun 2023 08:46:38 +0200 Subject: [PATCH] fix(api): #222 Wrong Schema for Entities with Error Response --- .../api/model/response/EntitiesWithErrors.kt | 70 ++++++++++++++++--- .../service/BusinessPartnerBuildService.kt | 12 ++-- 2 files changed, 65 insertions(+), 17 deletions(-) diff --git a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/response/EntitiesWithErrors.kt b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/response/EntitiesWithErrors.kt index 14f47497d..e4ba56481 100644 --- a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/response/EntitiesWithErrors.kt +++ b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/response/EntitiesWithErrors.kt @@ -22,14 +22,12 @@ package org.eclipse.tractusx.bpdm.pool.api.model.response import io.swagger.v3.oas.annotations.media.Schema import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressResponse -@Schema(name = "EntitiesWithErrorsResponse", description = "Holds information about successfully and failed entities after the creating/updating of several objects") - -data class EntitiesWithErrors( +open class EntitiesWithErrors( @Schema(description = "Successfully created entities") - val entities: Collection, + open val entities: Collection, @Schema(description = "Errors for not created entities") - val errors: Collection> + open val errors: Collection> ) { val entityCount: Int get() = entities.size @@ -37,9 +35,59 @@ data class EntitiesWithErrors( get() = errors.size } -typealias LegalEntityPartnerCreateResponseWrapper = EntitiesWithErrors -typealias LegalEntityPartnerUpdateResponseWrapper = EntitiesWithErrors -typealias SitePartnerCreateResponseWrapper = EntitiesWithErrors -typealias SitePartnerUpdateResponseWrapper = EntitiesWithErrors -typealias AddressPartnerCreateResponseWrapper = EntitiesWithErrors -typealias AddressPartnerUpdateResponseWrapper = EntitiesWithErrors +@Schema( + name = "LegalEntityCreateWrapper", + description = "Holds information about successfully and failed entities after the creating/updating of several objects" +) +data class LegalEntityPartnerCreateResponseWrapper( + override val entities: Collection, + override val errors: Collection> +) : EntitiesWithErrors(entities, errors) + +@Schema( + name = "LegalEntityUpdateWrapper", + description = "Holds information about successfully and failed entities after the creating/updating of several objects" +) +data class LegalEntityPartnerUpdateResponseWrapper( + override val entities: Collection, + override val errors: Collection> +) : EntitiesWithErrors(entities, errors) + +@Schema( + name = "SiteCreateWrapper", + description = "Holds information about successfully and failed entities after the creating/updating of several objects" +) +data class SitePartnerCreateResponseWrapper( + override val entities: Collection, + override val errors: Collection> +) : EntitiesWithErrors(entities, errors) + +@Schema( + name = "SiteUpdateWrapper", + description = "Holds information about successfully and failed entities after the creating/updating of several objects" +) +data class SitePartnerUpdateResponseWrapper( + override val entities: Collection, + override val errors: Collection> +) : EntitiesWithErrors(entities, errors) + +@Schema( + name = "AddressCreateWrapper", + description = "Holds information about successfully and failed entities after the creating/updating of several objects" +) +data class AddressPartnerCreateResponseWrapper( + override val entities: Collection, + override val errors: Collection> +) : EntitiesWithErrors(entities, errors) + +@Schema( + name = "AddressUpdateWrapper", + description = "Holds information about successfully and failed entities after the creating/updating of several objects" +) +data class AddressPartnerUpdateResponseWrapper( + override val entities: Collection, + override val errors: Collection> +) : EntitiesWithErrors(entities, errors) + + + diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/BusinessPartnerBuildService.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/BusinessPartnerBuildService.kt index 19df97ac4..3c91b4732 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/BusinessPartnerBuildService.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/BusinessPartnerBuildService.kt @@ -88,7 +88,7 @@ class BusinessPartnerBuildService( val validEntities = legalEntities.map { it.toUpsertDto(legalEntityWithIndexByBpnMap[it.bpn]!!.second) } - return EntitiesWithErrors(validEntities, errors) + return LegalEntityPartnerCreateResponseWrapper(validEntities, errors) } @Transactional @@ -125,7 +125,7 @@ class BusinessPartnerBuildService( val validEntities = sites.map { it.toUpsertDto(siteWithIndexByBpnMap[it.bpn]!!.second) } - return EntitiesWithErrors(validEntities, errors) + return SitePartnerCreateResponseWrapper(validEntities, errors) } @Transactional @@ -150,7 +150,7 @@ class BusinessPartnerBuildService( changelogService.createChangelogEntries(addressResponses.map { ChangelogEntryDto(it.address.bpna, ChangelogType.CREATE, ChangelogSubject.ADDRESS) }) - return EntitiesWithErrors(addressResponses, errors) + return AddressPartnerCreateResponseWrapper(addressResponses, errors) } /** @@ -184,7 +184,7 @@ class BusinessPartnerBuildService( val validEntities = legalEntityRepository.saveAll(legalEntities).map { it.toUpsertDto(null) } - return EntitiesWithErrors(validEntities, errors) + return LegalEntityPartnerUpdateResponseWrapper(validEntities, errors) } @Transactional @@ -212,7 +212,7 @@ class BusinessPartnerBuildService( } val validEntities = siteRepository.saveAll(sites).map { it.toUpsertDto(null) } - return EntitiesWithErrors(validEntities, errors) + return SitePartnerUpdateResponseWrapper(validEntities, errors) } fun updateAddresses(requests: Collection): AddressPartnerUpdateResponseWrapper { @@ -233,7 +233,7 @@ class BusinessPartnerBuildService( changelogService.createChangelogEntries(validAddresses.map { ChangelogEntryDto(it.bpn, ChangelogType.UPDATE, ChangelogSubject.ADDRESS) }) val addressResponses = logisticAddressRepository.saveAll(validAddresses).map { it.toDto() } - return EntitiesWithErrors(addressResponses, errors) + return AddressPartnerUpdateResponseWrapper(addressResponses, errors) } @Transactional