From a4b1258492b89ffe44c714d115205b2baa774cbc Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Wed, 27 Mar 2024 11:38:31 +0100 Subject: [PATCH] Merge logbook message trip gear and gear type in Backend --- .../domain/entities/logbook/LogbookMessage.kt | 2 +- .../entities/logbook/LogbookTripGear.kt | 8 -- .../outputs/LogbookMessageGearDataOutput.kt | 23 ++++ .../LogbookMessageTripGearDataOutput.kt | 18 --- .../outputs/PriorNotificationDataOutput.kt | 6 +- .../database/entities/LogbookReportEntity.kt | 2 +- .../src/features/Logbook/Logbook.types.ts | 14 +- .../features/Logbook/LogbookMessage.types.ts | 3 +- frontend/src/features/Logbook/api.ts | 6 +- .../LogbookMessages/messages/DEPMessage.tsx | 4 +- .../LogbookMessages/messages/utils.tsx | 2 +- .../summaries/DEPMessageResume.tsx | 128 +++++++++--------- 12 files changed, 107 insertions(+), 109 deletions(-) delete mode 100644 backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookTripGear.kt create mode 100644 backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessageGearDataOutput.kt delete mode 100644 backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessageTripGearDataOutput.kt diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessage.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessage.kt index 00a643d425..83a6ca4931 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessage.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessage.kt @@ -34,6 +34,6 @@ data class LogbookMessage( val transmissionFormat: LogbookTransmissionFormat, val software: String? = null, var isSentByFailoverSoftware: Boolean = false, - val tripGears: List? = listOf(), + val tripGears: List? = listOf(), val tripSegments: List? = listOf(), ) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookTripGear.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookTripGear.kt deleted file mode 100644 index 13ed136589..0000000000 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookTripGear.kt +++ /dev/null @@ -1,8 +0,0 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.logbook - -data class LogbookTripGear( - /** Gear code. */ - val gear: String, - val mesh: Int, - val dimensions: String, -) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessageGearDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessageGearDataOutput.kt new file mode 100644 index 0000000000..56a11f2d0f --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessageGearDataOutput.kt @@ -0,0 +1,23 @@ +package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs + +import fr.gouv.cnsp.monitorfish.domain.entities.logbook.Gear + +class LogbookMessageGearDataOutput( + val gear: String, + val gearName: String?, + val mesh: Double?, + val dimensions: String?, +) { + companion object { + fun fromGear(gear: Gear): LogbookMessageGearDataOutput? { + return gear.gear?.let { gearCode -> + LogbookMessageGearDataOutput( + gear = gearCode, + gearName = gear.gearName, + mesh = gear.mesh, + dimensions = gear.dimensions, + ) + } + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessageTripGearDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessageTripGearDataOutput.kt deleted file mode 100644 index 6f5cfad346..0000000000 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessageTripGearDataOutput.kt +++ /dev/null @@ -1,18 +0,0 @@ -package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs - -import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookTripGear - -class LogbookMessageTripGearDataOutput( - val gear: String, - val mesh: Int, - val dimensions: String, -) { - companion object { - fun fromLogbookTripGear(logbookTripGear: LogbookTripGear) = - LogbookMessageTripGearDataOutput( - gear = logbookTripGear.gear, - mesh = logbookTripGear.mesh, - dimensions = logbookTripGear.dimensions, - ) - } -} diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationDataOutput.kt index 1217d4ebb0..5433d74ad1 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationDataOutput.kt @@ -16,7 +16,7 @@ class PriorNotificationDataOutput( val reportingsCount: Int?, val seaFront: String?, val sentAt: String?, - val tripGears: List, + val tripGears: List, val tripSegments: List, val types: List, val vesselId: Int?, @@ -38,8 +38,8 @@ class PriorNotificationDataOutput( val message = priorNotification.logbookMessage.message as PNO val onBoardCatches = message.catchOnboard.map { LogbookMessageCatchDataOutput.fromCatch(it) } - val tripGears = priorNotification.logbookMessage.tripGears?.map { - LogbookMessageTripGearDataOutput.fromLogbookTripGear(it) + val tripGears = priorNotification.logbookMessage.tripGears?.mapNotNull { + LogbookMessageGearDataOutput.fromGear(it) } ?: emptyList() val tripSegments = priorNotification.logbookMessage.tripSegments?.map { LogbookMessageTripSegmentDataOutput.fromLogbookTripSegment(it) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LogbookReportEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LogbookReportEntity.kt index 81c12ab042..4d2caa2606 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LogbookReportEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LogbookReportEntity.kt @@ -113,7 +113,7 @@ data class LogbookReportEntity( fun toLogbookMessage(mapper: ObjectMapper): LogbookMessage { val message = getERSMessageValueFromJSON(mapper, message, messageType, operationType) - val tripGears = deserializeJSONList(mapper, tripGears, LogbookTripGear::class.java) + val tripGears = deserializeJSONList(mapper, tripGears, Gear::class.java) val tripSegments = deserializeJSONList(mapper, tripSegments, LogbookTripSegment::class.java) return LogbookMessage( diff --git a/frontend/src/features/Logbook/Logbook.types.ts b/frontend/src/features/Logbook/Logbook.types.ts index e0834c76c4..d7b94bc58d 100644 --- a/frontend/src/features/Logbook/Logbook.types.ts +++ b/frontend/src/features/Logbook/Logbook.types.ts @@ -16,6 +16,7 @@ export type FishingActivities = { } // TODO Replace with `LogbookMessage.LogbookMessage`. +// Can be done after using RTK in `getVesselLogbookFromAPI()` since undefined !== null. export type LogbookMessage = { acknowledge: { dateTime: string | null @@ -66,6 +67,7 @@ export type PNOAndLANWeightToleranceAlertValue = { } // TODO Replace this type with `LogbookMessage.Catch`. +// Can be done after using RTK in `getVesselLogbookFromAPI()` since undefined !== null. export type LogbookCatch = { conversionFactor: number | null economicZone: string | null @@ -82,12 +84,14 @@ export type LogbookCatch = { weight: number | null } -// TODO Duplicate with `LogbookMessage.TripGear`? +// TODO Replace this type with `LogbookMessage.Gear`. +// Can be done after using RTK in `getVesselLogbookFromAPI()` since undefined !== null. export type Gear = { - dimensions: string - gear: string - gearName: string - mesh: number + dimensions: string | null + /** Gear code. */ + gear: string | null + gearName: string | null + mesh: number | null } export type PNOAndLANWeightToleranceAlertValueCatches = { diff --git a/frontend/src/features/Logbook/LogbookMessage.types.ts b/frontend/src/features/Logbook/LogbookMessage.types.ts index 4470e4afac..5cc6e973b6 100644 --- a/frontend/src/features/Logbook/LogbookMessage.types.ts +++ b/frontend/src/features/Logbook/LogbookMessage.types.ts @@ -88,9 +88,8 @@ export namespace LogbookMessage { } export type TripGear = { + code: string dimensions: string - /** Gear code. */ - gear: string mesh: number } diff --git a/frontend/src/features/Logbook/api.ts b/frontend/src/features/Logbook/api.ts index e9094196e3..ba47e49bb3 100644 --- a/frontend/src/features/Logbook/api.ts +++ b/frontend/src/features/Logbook/api.ts @@ -33,9 +33,9 @@ export async function getVesselLogbookFromAPI( voyageRequest: NavigateTo | undefined, tripNumber: number | undefined ) { - const internalReferenceNumber = vesselIdentity.internalReferenceNumber || '' - const nextTripNumber = tripNumber || '' - const nextVoyageRequest = voyageRequest || '' + const internalReferenceNumber = vesselIdentity.internalReferenceNumber ?? '' + const nextTripNumber = tripNumber ?? '' + const nextVoyageRequest = voyageRequest ?? '' try { return await monitorfishApiKy diff --git a/frontend/src/features/Logbook/components/VesselLogbook/LogbookMessages/messages/DEPMessage.tsx b/frontend/src/features/Logbook/components/VesselLogbook/LogbookMessages/messages/DEPMessage.tsx index 96e6976580..19813b94a5 100644 --- a/frontend/src/features/Logbook/components/VesselLogbook/LogbookMessages/messages/DEPMessage.tsx +++ b/frontend/src/features/Logbook/components/VesselLogbook/LogbookMessages/messages/DEPMessage.tsx @@ -6,9 +6,9 @@ import { NoValue, Table, TableBody, TableKey, TableRow, TableValue, Zone } from import type { DEPMessageValue } from '../../../../Logbook.types' -type DEPMessageProps = { +type DEPMessageProps = Readonly<{ message: DEPMessageValue -} +}> export function DEPMessage({ message }: DEPMessageProps) { return ( <> diff --git a/frontend/src/features/Logbook/components/VesselLogbook/LogbookMessages/messages/utils.tsx b/frontend/src/features/Logbook/components/VesselLogbook/LogbookMessages/messages/utils.tsx index 0852d786d2..0eb04b8ce4 100644 --- a/frontend/src/features/Logbook/components/VesselLogbook/LogbookMessages/messages/utils.tsx +++ b/frontend/src/features/Logbook/components/VesselLogbook/LogbookMessages/messages/utils.tsx @@ -27,7 +27,7 @@ export function getDatetimeOrDash(dateTimeUtc?: string) { ) } -export function getCodeWithNameOrDash(code?: string, codeName?: string) { +export function getCodeWithNameOrDash(code?: string | null, codeName?: string | null) { if (!code && !codeName) { return - } diff --git a/frontend/src/features/Logbook/components/VesselLogbook/LogbookSummary/summaries/DEPMessageResume.tsx b/frontend/src/features/Logbook/components/VesselLogbook/LogbookSummary/summaries/DEPMessageResume.tsx index 7ddb1c448e..45dc11a0f9 100644 --- a/frontend/src/features/Logbook/components/VesselLogbook/LogbookSummary/summaries/DEPMessageResume.tsx +++ b/frontend/src/features/Logbook/components/VesselLogbook/LogbookSummary/summaries/DEPMessageResume.tsx @@ -9,14 +9,14 @@ import { LogbookMessageResumeHeader } from '../LogbookMessageResumeHeader' import type { DEPMessageValue } from '../../../../Logbook.types' import type { Promisable } from 'type-fest' -type DEPMessageResumeProps = { +type DEPMessageResumeProps = Readonly<{ depMessage: DEPMessageValue hasNoMessage?: boolean isDeleted: boolean isNotAcknowledged: boolean rejectionCause: string | undefined showLogbookMessages: (messageType: string) => Promisable -} +}> export function DEPMessageResume({ depMessage, hasNoMessage = false, @@ -48,69 +48,67 @@ export function DEPMessageResume({ ) return ( - <> - - - {!hasNoMessage && ( - 0 ? depMessage.speciesOnboard.length : 1} - > - - {depMessage.gearOnboard?.length ? ( - depMessage.gearOnboard.map((gear, index) => ( - // eslint-disable-next-line react/no-array-index-key - - Engin à bord {index + 1}{' '} - {getCodeWithNameOrDash(gear.gear, gear.gearName)} -
- Maillage - {gear.mesh ? <>{gear.mesh} mm : -} - Dimensions - {gear.dimensions ? <>{gear.dimensions} m : -} -
-
- )) - ) : ( - Pas d'engins à bord - )} - - - - Captures à bord - - {depMessage.speciesOnboard?.length ? ( - depMessage.speciesOnboard.map(speciesCatch => ( - - {getCodeWithNameOrDash(speciesCatch.species, speciesCatch.speciesName)}-{' '} - {speciesCatch.weight} kg -
-
- )) - ) : ( - aucune - )} -
-
-
-
-
-
- )} -
- + + + {!hasNoMessage && ( + 0 ? depMessage.speciesOnboard.length : 1} + > + + {depMessage.gearOnboard?.length ? ( + depMessage.gearOnboard.map((gear, index) => ( + // eslint-disable-next-line react/no-array-index-key + + Engin à bord {index + 1}{' '} + {getCodeWithNameOrDash(gear.gear, gear.gearName)} +
+ Maillage + {gear.mesh ? <>{gear.mesh} mm : -} + Dimensions + {gear.dimensions ? <>{gear.dimensions} m : -} +
+
+ )) + ) : ( + Pas d'engins à bord + )} + + + + Captures à bord + + {depMessage.speciesOnboard?.length ? ( + depMessage.speciesOnboard.map(speciesCatch => ( + + {getCodeWithNameOrDash(speciesCatch.species, speciesCatch.speciesName)}- {speciesCatch.weight}{' '} + kg +
+
+ )) + ) : ( + aucune + )} +
+
+
+
+
+
+ )} +
) }