diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/vigilanceArea/VigilanceAreasDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/vigilanceArea/VigilanceAreasDataOutput.kt new file mode 100644 index 000000000..72e2b897d --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/vigilanceArea/VigilanceAreasDataOutput.kt @@ -0,0 +1,55 @@ +package fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.vigilanceArea + +import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.* +import org.locationtech.jts.geom.MultiPolygon +import java.time.ZonedDateTime + +data class VigilanceAreasDataOutput( + val id: Int? = null, + val comments: String? = null, + val computedEndDate: ZonedDateTime? = null, + val createdBy: String? = null, + val endDatePeriod: ZonedDateTime? = null, + val endingCondition: EndingConditionEnum? = null, + val endingOccurrenceDate: ZonedDateTime? = null, + val endingOccurrencesNumber: Int? = null, + val frequency: FrequencyEnum? = null, + val geom: MultiPolygon? = null, + val isArchived: Boolean, + val isDraft: Boolean, + val links: List? = null, + val linkedAMPs: List? = listOf(), + val linkedRegulatoryAreas: List? = listOf(), + val name: String? = null, + val source: String? = null, + val startDatePeriod: ZonedDateTime? = null, + val themes: List? = null, + val visibility: VisibilityEnum? = null, +) { + companion object { + fun fromVigilanceArea(vigilanceArea: VigilanceAreaEntity): VigilanceAreasDataOutput { + return VigilanceAreasDataOutput( + id = vigilanceArea.id, + comments = vigilanceArea.comments, + computedEndDate = vigilanceArea.computedEndDate, + createdBy = vigilanceArea.createdBy, + endDatePeriod = vigilanceArea.endDatePeriod, + endingCondition = vigilanceArea.endingCondition, + endingOccurrenceDate = vigilanceArea.endingOccurrenceDate, + endingOccurrencesNumber = vigilanceArea.endingOccurrencesNumber, + frequency = vigilanceArea.frequency, + geom = vigilanceArea.geom, + isArchived = vigilanceArea.isArchived, + isDraft = vigilanceArea.isDraft, + links = vigilanceArea.links, + linkedAMPs = vigilanceArea.linkedAMPs, + linkedRegulatoryAreas = vigilanceArea.linkedRegulatoryAreas, + name = vigilanceArea.name, + source = vigilanceArea.source, + startDatePeriod = vigilanceArea.startDatePeriod, + themes = vigilanceArea.themes, + visibility = vigilanceArea.visibility, + ) + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreas.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreas.kt index fb896d492..9aeb254e9 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreas.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreas.kt @@ -1,16 +1,15 @@ package fr.gouv.cacem.monitorenv.infrastructure.api.endpoints.bff.v1 -import fr.gouv.cacem.monitorenv.domain.use_cases.natinfs.GetAllNatinfs import fr.gouv.cacem.monitorenv.domain.use_cases.vigilanceArea.CreateOrUpdateVigilanceArea import fr.gouv.cacem.monitorenv.domain.use_cases.vigilanceArea.DeleteVigilanceArea import fr.gouv.cacem.monitorenv.domain.use_cases.vigilanceArea.GetVigilanceAreaById import fr.gouv.cacem.monitorenv.domain.use_cases.vigilanceArea.GetVigilanceAreas import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.inputs.vigilanceArea.VigilanceAreaDataInput import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.vigilanceArea.VigilanceAreaDataOutput +import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.vigilanceArea.VigilanceAreasDataOutput import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import jakarta.websocket.server.PathParam -import org.slf4j.LoggerFactory import org.springframework.http.HttpStatus import org.springframework.web.bind.annotation.* @@ -23,8 +22,6 @@ class VigilanceAreas( private val getVigilanceAreaById: GetVigilanceAreaById, private val deleteVigilanceArea: DeleteVigilanceArea, ) { - private val logger = LoggerFactory.getLogger(GetAllNatinfs::class.java) - @PutMapping("", consumes = ["application/json"]) @Operation(summary = "Create a new vigilance area") fun create( @@ -38,10 +35,10 @@ class VigilanceAreas( @GetMapping("") @Operation(summary = "List vigilance areas") - fun getAll(): List { + fun getAll(): List { val vigilanceAreas = getVigilanceAreas.execute() - return vigilanceAreas.map { VigilanceAreaDataOutput.fromVigilanceArea(it) } + return vigilanceAreas.map { VigilanceAreasDataOutput.fromVigilanceArea(it) } } @GetMapping("/{vigilanceAreaId}") diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaVigilanceAreaRepository.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaVigilanceAreaRepository.kt index 03def38cc..88b45ee74 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaVigilanceAreaRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaVigilanceAreaRepository.kt @@ -49,7 +49,7 @@ class JpaVigilanceAreaRepository( @Transactional override fun findAll(): List { - return dbVigilanceAreaRepository.findAll().map { it.toVigilanceAreaEntity() } + return dbVigilanceAreaRepository.findAllByIsDeletedIsFalse().map { it.toVigilanceAreaEntity() } } override fun findAllByGeometry(geometry: Geometry): List { diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBVigilanceAreaRepository.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBVigilanceAreaRepository.kt index 331ca4a32..02feee00c 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBVigilanceAreaRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBVigilanceAreaRepository.kt @@ -19,16 +19,7 @@ interface IDBVigilanceAreaRepository : JpaRepository { ) fun delete(id: Int) - @Query( - value = - """ - SELECT * - FROM vigilance_areas - WHERE is_deleted IS FALSE - """, - nativeQuery = true, - ) - override fun findAll(): List + fun findAllByIsDeletedIsFalse(): List @Modifying(clearAutomatically = true, flushAutomatically = true) @Query( diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreasITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreasITests.kt index 0c5eee5be..cc17f0dc5 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreasITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreasITests.kt @@ -140,14 +140,6 @@ class VigilanceAreasITests { .andExpect( jsonPath("$[0].links").doesNotExist(), ) - .andExpect(jsonPath("$[0].images[0].name", equalTo("image1.jpg"))) - .andExpect(jsonPath("$[0].images[0].mimeType", equalTo("image/jpeg"))) - .andExpect(jsonPath("$[0].images[0].size", equalTo(1024))) - .andExpect(jsonPath("$[0].images[0].content", equalTo("AQID"))) - .andExpect(jsonPath("$[0].images[1].name", equalTo("image2.png"))) - .andExpect(jsonPath("$[0].images[1].mimeType", equalTo("image/png"))) - .andExpect(jsonPath("$[0].images[1].size", equalTo(2048))) - .andExpect(jsonPath("$[0].images[1].content", equalTo("BAUG"))) .andExpect(jsonPath("$[0].source", equalTo("Source de la zone de vigilance"))) .andExpect(jsonPath("$[0].startDatePeriod", equalTo("2024-08-18T00:00:00Z"))) .andExpect(jsonPath("$[0].themes").doesNotExist()) @@ -166,9 +158,6 @@ class VigilanceAreasITests { .andExpect( jsonPath("$[0].links").doesNotExist(), ) - .andExpect( - jsonPath("$[1].images").isEmpty(), - ) .andExpect(jsonPath("$[1].source", equalTo("Un particulier"))) .andExpect(jsonPath("$[1].startDatePeriod", equalTo("2024-12-01T00:00:00Z"))) .andExpect(jsonPath("$[1].themes").doesNotExist()) diff --git a/frontend/cypress/e2e/main_window/vigilance_area/create_vigilance_area.spec.ts b/frontend/cypress/e2e/main_window/vigilance_area/create_vigilance_area.spec.ts index 14b4c9c15..7f2fdad34 100644 --- a/frontend/cypress/e2e/main_window/vigilance_area/create_vigilance_area.spec.ts +++ b/frontend/cypress/e2e/main_window/vigilance_area/create_vigilance_area.spec.ts @@ -96,10 +96,10 @@ describe('Create Vigilance Area', () => { expect(createdVigilanceArea.comments).equal('Ceci est un commentaire') expect(createdVigilanceArea.createdBy).equal('ABC') expect(createdVigilanceArea.isDraft).equal(true) - expect(createdVigilanceArea.images).to.have.length(1) + /* expect(createdVigilanceArea.images).to.have.length(1) expect(createdVigilanceArea.images[0].name).equal('vigilanceAreaImage.png') expect(createdVigilanceArea.images[0].size).equal(396656) - expect(createdVigilanceArea.images[0].mimeType).equal('image/png') + expect(createdVigilanceArea.images[0].mimeType).equal('image/png') */ cy.getDataCy('banner-stack').should('be.visible') cy.getDataCy('banner-stack').contains('La zone de vigilance a bien été créée')