Skip to content

Commit 05eda90

Browse files
feat: display last position from vessel resume
1 parent 3b2671e commit 05eda90

File tree

65 files changed

+1193
-277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1193
-277
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package fr.gouv.cacem.monitorenv.domain.entities.lastPositions
2+
3+
import org.locationtech.jts.geom.Point
4+
import java.time.ZonedDateTime
5+
6+
data class LastPositionEntity(
7+
val course: Double?,
8+
val destination: String?,
9+
val geom: Point?,
10+
val heading: Double?,
11+
val id: Int,
12+
val mmsi: Int?,
13+
val status: String?,
14+
val speed: Double?,
15+
val shipname: String?,
16+
val timestamp: ZonedDateTime?,
17+
)

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/vessels/Vessel.kt renamed to backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/vessels/VesselEntity.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
package fr.gouv.cacem.monitorenv.domain.entities.vessels
22

3+
import fr.gouv.cacem.monitorenv.domain.entities.lastPositions.LastPositionEntity
34
import java.math.BigDecimal
45

5-
data class Vessel(
6-
val id: Int,
7-
val shipId: Int,
8-
val status: String?,
6+
data class VesselEntity(
97
val category: String?,
8+
val commercialName: String?,
9+
val flag: String?,
10+
val id: Int,
1011
val isBanned: Boolean,
1112
val imo: String?,
12-
val mmsi: String?,
1313
val immatriculation: String?,
14-
val shipName: String?,
15-
val flag: String?,
16-
val portOfRegistry: String?,
17-
val professionalType: String?,
1814
val leisureType: String?,
19-
val commercialName: String?,
2015
val length: BigDecimal?,
16+
val mmsi: String?,
2117
val ownerLastName: String?,
2218
val ownerFirstName: String?,
2319
val ownerDateOfBirth: String?,
@@ -31,4 +27,10 @@ data class Vessel(
3127
val ownerLegalStatus: String?,
3228
val ownerLegalStatusLabel: String?,
3329
val ownerStartDate: String?,
30+
val portOfRegistry: String?,
31+
val professionalType: String?,
32+
val shipId: Int?,
33+
val shipName: String?,
34+
val status: String?,
35+
val lastPositions: MutableList<LastPositionEntity>,
3436
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package fr.gouv.cacem.monitorenv.domain.repositories
2+
3+
import fr.gouv.cacem.monitorenv.domain.entities.lastPositions.LastPositionEntity
4+
5+
interface ILastPositionRepository {
6+
fun findAll(shipId: Int): List<LastPositionEntity>
7+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package fr.gouv.cacem.monitorenv.domain.repositories
22

3-
import fr.gouv.cacem.monitorenv.domain.entities.vessels.Vessel
3+
import fr.gouv.cacem.monitorenv.domain.entities.vessels.VesselEntity
44

55
interface IVesselRepository {
6-
fun findVesselById(id: Int): Vessel?
6+
fun findVesselById(id: Int): VesselEntity?
77

8-
fun search(searched: String): List<Vessel>
8+
fun search(searched: String): List<VesselEntity>
99
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package fr.gouv.cacem.monitorenv.domain.use_cases.lastPositions
2+
3+
import fr.gouv.cacem.monitorenv.config.UseCase
4+
import fr.gouv.cacem.monitorenv.domain.entities.lastPositions.LastPositionEntity
5+
import fr.gouv.cacem.monitorenv.domain.repositories.ILastPositionRepository
6+
7+
@UseCase
8+
class GetLastPositions(
9+
private val lastPositionRepository: ILastPositionRepository,
10+
) {
11+
fun execute(shipId: Int): List<LastPositionEntity> = lastPositionRepository.findAll(shipId)
12+
}

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vessels/GetVesselById.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
package fr.gouv.cacem.monitorenv.domain.use_cases.vessels
22

33
import fr.gouv.cacem.monitorenv.config.UseCase
4-
import fr.gouv.cacem.monitorenv.domain.entities.vessels.Vessel
4+
import fr.gouv.cacem.monitorenv.domain.entities.vessels.VesselEntity
55
import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageErrorCode
66
import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageException
7+
import fr.gouv.cacem.monitorenv.domain.repositories.ILastPositionRepository
78
import fr.gouv.cacem.monitorenv.domain.repositories.IVesselRepository
89
import org.slf4j.LoggerFactory
910

1011
@UseCase
1112
class GetVesselById(
1213
private val vesselRepository: IVesselRepository,
14+
private val lastPositionRepository: ILastPositionRepository,
1315
) {
1416
private val logger = LoggerFactory.getLogger(GetVesselById::class.java)
1517

16-
fun execute(id: Int): Vessel {
18+
fun execute(id: Int): VesselEntity {
1719
vesselRepository.findVesselById(id)?.let { vessel ->
1820
logger.info("GET vessel ${vessel.id}")
21+
vessel.shipId?.let { shipId ->
22+
val lastPositions = lastPositionRepository.findAll(shipId)
23+
vessel.lastPositions.addAll(lastPositions)
24+
}
1925
return vessel
2026
}
2127
throw BackendUsageException(
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package fr.gouv.cacem.monitorenv.domain.use_cases.vessels
22

33
import fr.gouv.cacem.monitorenv.config.UseCase
4-
import fr.gouv.cacem.monitorenv.domain.entities.vessels.Vessel
4+
import fr.gouv.cacem.monitorenv.domain.entities.vessels.VesselEntity
55
import fr.gouv.cacem.monitorenv.domain.repositories.IVesselRepository
66

77
@UseCase
88
class SearchVessels(
99
private val vesselRepository: IVesselRepository,
1010
) {
11-
fun execute(searched: String): List<Vessel> = vesselRepository.search(searched)
11+
fun execute(searched: String): List<VesselEntity> = vesselRepository.search(searched)
1212
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.lastPositions
2+
3+
import fr.gouv.cacem.monitorenv.domain.entities.lastPositions.LastPositionEntity
4+
import org.locationtech.jts.geom.Point
5+
import java.time.ZonedDateTime
6+
7+
data class LastPositionOutput(
8+
val course: Double?,
9+
val destination: String?,
10+
val geom: Point?,
11+
val heading: Double?,
12+
val id: Int,
13+
val mmsi: Int?,
14+
val shipname: String?,
15+
val status: String?,
16+
val speed: Double?,
17+
val timestamp: ZonedDateTime?,
18+
) {
19+
companion object {
20+
fun toLastPositionOutput(lastPosition: LastPositionEntity) =
21+
LastPositionOutput(
22+
course = lastPosition.course,
23+
destination = lastPosition.destination,
24+
geom = lastPosition.geom,
25+
heading = lastPosition.heading,
26+
id = lastPosition.id,
27+
mmsi = lastPosition.mmsi,
28+
shipname = lastPosition.shipname,
29+
status = lastPosition.status,
30+
speed = lastPosition.speed,
31+
timestamp = lastPosition.timestamp,
32+
)
33+
}
34+
}

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/vessels/VesselDataOutput.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.vessels
22

3-
import fr.gouv.cacem.monitorenv.domain.entities.vessels.Vessel
3+
import fr.gouv.cacem.monitorenv.domain.entities.vessels.VesselEntity
4+
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.lastPositions.LastPositionOutput
45
import java.math.BigDecimal
56

67
data class VesselDataOutput(
@@ -28,9 +29,10 @@ data class VesselDataOutput(
2829
val ownerBusinessSegmentLabel: String?,
2930
val ownerLegalStatusLabel: String?,
3031
val ownerStartDate: String?,
32+
val lastPositions: List<LastPositionOutput>,
3133
) {
3234
companion object {
33-
fun fromVessel(vessel: Vessel): VesselDataOutput =
35+
fun fromVessel(vessel: VesselEntity): VesselDataOutput =
3436
VesselDataOutput(
3537
id = vessel.id,
3638
status = vessel.status,
@@ -44,6 +46,7 @@ data class VesselDataOutput(
4446
leisureType = vessel.leisureType,
4547
professionalType = vessel.professionalType,
4648
commercialName = vessel.commercialName,
49+
lastPositions = vessel.lastPositions.map { LastPositionOutput.toLastPositionOutput(it) },
4750
length = vessel.length,
4851
ownerLastName = vessel.ownerLastName,
4952
ownerFirstName = vessel.ownerFirstName,

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/vessels/VesselIdentityDataOutput.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
package fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.vessels
22

3-
import fr.gouv.cacem.monitorenv.domain.entities.vessels.Vessel
3+
import fr.gouv.cacem.monitorenv.domain.entities.vessels.VesselEntity
44

55
data class VesselIdentityDataOutput(
6-
val id: Int,
6+
val category: String?,
77
val flag: String?,
8-
val mmsi: String?,
8+
val id: Int,
99
val imo: String?,
1010
val immatriculation: String?,
11+
val mmsi: String?,
12+
val shipId: Int?,
1113
val shipName: String?,
12-
val category: String?,
1314
) {
1415
companion object {
15-
fun fromVessel(vessel: Vessel): VesselIdentityDataOutput =
16+
fun fromVessel(vessel: VesselEntity): VesselIdentityDataOutput =
1617
VesselIdentityDataOutput(
1718
id = vessel.id,
19+
shipId = vessel.shipId,
1820
flag = vessel.flag,
1921
mmsi = vessel.mmsi,
2022
imo = vessel.imo,

0 commit comments

Comments
 (0)