diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/ControlUnitResourceEntity.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/ControlUnitResourceEntity.kt index cca9ef7ea4..c9c22b938c 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/ControlUnitResourceEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/ControlUnitResourceEntity.kt @@ -43,7 +43,7 @@ data class ControlUnitResourceEntity( return result } - fun toLegacyControlUnitEntity(): LegacyControlUnitResourceEntity { + fun toLegacyControlUnitResourceEntity(): LegacyControlUnitResourceEntity { return LegacyControlUnitResourceEntity( id = requireNotNull(id), name, diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt index 1719762593..369235db98 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt @@ -129,11 +129,13 @@ data class MissionModel( ) { fun toMissionEntity(objectMapper: ObjectMapper): MissionEntity { val controlUnits = controlUnits.mapOrElseEmpty { missionControlUnitModel -> - val controlUnitResources = controlResources.mapOrElseEmpty { it.toControlUnitResource() } + val controlUnitResources = controlResources.mapOrElseEmpty { + it.toControlUnitResource() + }.filter { it.controlUnitId == missionControlUnitModel.unit.id } missionControlUnitModel.unit.toLegacyControlUnit().copy( contact = missionControlUnitModel.contact, - resources = controlUnitResources.map { it.toLegacyControlUnitEntity() }, + resources = controlUnitResources.map { it.toLegacyControlUnitResourceEntity() }, ) } @@ -195,14 +197,14 @@ data class MissionModel( missionModel.envActions?.add(EnvActionModel.fromEnvActionEntity(it, missionModel, mapper)) } - mission.controlUnits.map { + mission.controlUnits.map { controlUnit -> val missionControlUnitModel = MissionControlUnitModel.fromLegacyControlUnit( - it, + controlUnit, missionModel, ) missionModel.controlUnits?.add(missionControlUnitModel) - val missionControlUnitResourceModels = it.resources.map { controlUnitResource -> + val missionControlUnitResourceModels = controlUnit.resources.map { controlUnitResource -> val controlUnitResourceModel = requireNotNull(controlUnitResourceModelMap[controlUnitResource.id]) MissionControlResourceModel(