Skip to content

Commit

Permalink
[Missions] Ajout des NATINFs CACEM (#2485)
Browse files Browse the repository at this point in the history
## Linked issues

- Resolve #2396

----

- [ ] Tests E2E (Cypress)
  • Loading branch information
louptheron authored Sep 11, 2023
2 parents aaf359d + 742aada commit 5a39d32
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction

interface InfractionRepository {
fun findInfractionByNatinfCode(natinfCode: Int): Infraction
fun findFishingAndSecurityInfractions(): List<Infraction>
fun findAll(): List<Infraction>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction
import fr.gouv.cnsp.monitorfish.domain.repositories.InfractionRepository

@UseCase
class GetFishingAndSecurityInfractions(private val infractionRepository: InfractionRepository) {
class GetAllInfractions(private val infractionRepository: InfractionRepository) {
fun execute(): List<Infraction> {
return infractionRepository.findFishingAndSecurityInfractions()
return infractionRepository.findAll()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fr.gouv.cnsp.monitorfish.infrastructure.api.bff

import fr.gouv.cnsp.monitorfish.domain.use_cases.infraction.GetFishingAndSecurityInfractions
import fr.gouv.cnsp.monitorfish.domain.use_cases.infraction.GetAllInfractions
import fr.gouv.cnsp.monitorfish.infrastructure.api.outputs.InfractionDataOutput
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
Expand All @@ -11,12 +11,12 @@ import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/bff/v1/infractions")
@Tag(name = "APIs for Infractions")
class InfractionController(private val getFishingAndSecurityInfractions: GetFishingAndSecurityInfractions) {
class InfractionController(private val getAllInfractions: GetAllInfractions) {

@GetMapping("")
@Operation(summary = "Get fishing and security infractions")
fun getFishingAndSecurityInfractions(): List<InfractionDataOutput> {
return getFishingAndSecurityInfractions.execute().map { infraction ->
return getAllInfractions.execute().map { infraction ->
InfractionDataOutput.fromInfraction(infraction)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class CaffeineConfiguration {
val vesselsAllPositions = "vessels_all_position"
val vesselsPositionsWithBeaconMalfunctions = "vessels_positions_with_beacon_malfunctions"
val infractions = "infractions"
val fishingAndSecurityInfractions = "fishing_security_infractions"
val infraction = "infraction"
val currentSegments = "current_segment"
val controlAnteriority = "control_anteriority"
Expand Down Expand Up @@ -82,7 +81,6 @@ class CaffeineConfiguration {

val infractionsCache = buildMinutesCache(infractions, ticker, oneWeek)
val infractionCache = buildMinutesCache(infraction, ticker, oneWeek)
val fishingInfractionsCache = buildMinutesCache(fishingAndSecurityInfractions, ticker, oneWeek)

val vesselTrackCache = buildMinutesCache(vesselTrack, ticker, 1)
val vesselsPositionsCache = buildSecondsCache(vesselsPositions, ticker, 30)
Expand Down Expand Up @@ -126,7 +124,6 @@ class CaffeineConfiguration {
logbookRawMessageCache,
infractionsCache,
infractionCache,
fishingInfractionsCache,
currentSegmentsCache,
controlAnteriorityCache,
riskFactorsCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import org.springframework.stereotype.Repository

@Repository
class JpaInfractionRepository(private val dbInfractionRepository: DBInfractionRepository) : InfractionRepository {
@Cacheable(value = ["fishing_security_infractions"])
override fun findFishingAndSecurityInfractions(): List<Infraction> {
return dbInfractionRepository.findAllByInfractionCategoryEqualsSecurityOrFishing().map {
@Cacheable(value = ["infractions"])
override fun findAll(): List<Infraction> {
return dbInfractionRepository.findAll().map {
it.toInfraction()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
package fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.interfaces

import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.InfractionEntity
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.CrudRepository

interface DBInfractionRepository : CrudRepository<InfractionEntity, Long> {
fun findByNatinfCodeEquals(natinfCode: Int): InfractionEntity

@Query(
value = """
SELECT
*
FROM
infractions
WHERE
infraction_category IN ('Sécurité / Rôle', 'Pêche')
""",
nativeQuery = true,
)
fun findAllByInfractionCategoryEqualsSecurityOrFishing(): List<InfractionEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fr.gouv.cnsp.monitorfish.config.SecurityConfig
import fr.gouv.cnsp.monitorfish.config.SentryConfig
import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction
import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.InfractionCategory
import fr.gouv.cnsp.monitorfish.domain.use_cases.infraction.GetFishingAndSecurityInfractions
import fr.gouv.cnsp.monitorfish.domain.use_cases.infraction.GetAllInfractions
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Test
import org.mockito.BDDMockito.given
Expand All @@ -26,12 +26,12 @@ class InfractionControllerITests {
private lateinit var api: MockMvc

@MockBean
private lateinit var getFishingAndSecurityInfractions: GetFishingAndSecurityInfractions
private lateinit var getAllInfractions: GetAllInfractions

@Test
fun `Should get all fishing infractions`() {
// Given
given(this.getFishingAndSecurityInfractions.execute()).willReturn(
given(this.getAllInfractions.execute()).willReturn(
listOf(
Infraction(natinfCode = 7059, infractionCategory = InfractionCategory.FISHING),
Infraction(natinfCode = 7065, infractionCategory = InfractionCategory.FISHING),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class JpaInfractionRepositoryITests : AbstractDBTests() {
@Transactional
fun `findFishingInfractions Should return all fishing and security infractions`() {
// When
val infractions = jpaInfractionRepository.findFishingAndSecurityInfractions()
val infractions = jpaInfractionRepository.findAll()

// Then
assertThat(infractions).hasSize(8)
Expand Down

0 comments on commit 5a39d32

Please sign in to comment.