Skip to content

Commit

Permalink
Merge logbook message trip gear and gear type in Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Mar 27, 2024
1 parent 5e24f7b commit 484121c
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ data class LogbookMessage(
val transmissionFormat: LogbookTransmissionFormat,
val software: String? = null,
var isSentByFailoverSoftware: Boolean = false,
val tripGears: List<LogbookTripGear>? = listOf(),
val tripGears: List<Gear>? = listOf(),
val tripSegments: List<LogbookTripSegment>? = listOf(),
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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,
)
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PriorNotificationDataOutput(
val reportingsCount: Int?,
val seaFront: String?,
val sentAt: String?,
val tripGears: List<LogbookMessageTripGearDataOutput>,
val tripGears: List<LogbookMessageGearDataOutput>,
val tripSegments: List<LogbookMessageTripSegmentDataOutput>,
val types: List<PriorNotificationTypeDataOutput>,
val vesselId: Int?,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/features/Logbook/Logbook.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 = {
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/features/Logbook/LogbookMessage.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ export namespace LogbookMessage {
}

export type TripGear = {
code: string
dimensions: string
/** Gear code. */
gear: string
mesh: number
}

Expand Down
6 changes: 3 additions & 3 deletions frontend/src/features/Logbook/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <NoValue>-</NoValue>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>
}
}>
export function DEPMessageResume({
depMessage,
hasNoMessage = false,
Expand Down Expand Up @@ -48,69 +48,67 @@ export function DEPMessageResume({
)

return (
<>
<Wrapper>
<LogbookMessageResumeHeader
hasNoMessage={hasNoMessage}
isDeleted={isDeleted}
isNotAcknowledged={isNotAcknowledged}
isOpen={isOpen}
messageType={LogbookMessageTypeEnum.DEP.code.toString()}
onHoverText={hasNoMessage ? null : getDEPMessageResumeTitleText()}
rejectionCause={rejectionCause}
setIsOpen={setIsOpen}
showLogbookMessages={showLogbookMessages}
title={hasNoMessage ? null : getDEPMessageResumeTitle()}
/>
{!hasNoMessage && (
<LogbookMessageContent
$gearOnboard={depMessage.gearOnboard ? depMessage.gearOnboard.length : 1}
$isOpen={isOpen}
speciesOnboard={depMessage.speciesOnboard?.length > 0 ? depMessage.speciesOnboard.length : 1}
>
<Zone>
{depMessage.gearOnboard?.length ? (
depMessage.gearOnboard.map((gear, index) => (
// eslint-disable-next-line react/no-array-index-key
<Gear key={gear.gear + index}>
<SubKey>Engin à bord {index + 1}</SubKey>{' '}
<SubValue>{getCodeWithNameOrDash(gear.gear, gear.gearName)}</SubValue>
<br />
<SubKey>Maillage</SubKey>
<SubValue>{gear.mesh ? <>{gear.mesh} mm</> : <NoValue>-</NoValue>}</SubValue>
<SubKey>Dimensions</SubKey>
<SubValue>{gear.dimensions ? <>{gear.dimensions} m</> : <NoValue>-</NoValue>}</SubValue>
<br />
</Gear>
))
) : (
<NoValue>Pas d&apos;engins à bord</NoValue>
)}
<Fields>
<TableBody>
<Field>
<Key>Captures à bord</Key>
<Value>
{depMessage.speciesOnboard?.length ? (
depMessage.speciesOnboard.map(speciesCatch => (
<span key={speciesCatch.species}>
{getCodeWithNameOrDash(speciesCatch.species, speciesCatch.speciesName)}-{' '}
{speciesCatch.weight} kg
<br />
</span>
))
) : (
<NoValue>aucune</NoValue>
)}
</Value>
</Field>
</TableBody>
</Fields>
</Zone>
</LogbookMessageContent>
)}
</Wrapper>
</>
<Wrapper>
<LogbookMessageResumeHeader
hasNoMessage={hasNoMessage}
isDeleted={isDeleted}
isNotAcknowledged={isNotAcknowledged}
isOpen={isOpen}
messageType={LogbookMessageTypeEnum.DEP.code.toString()}
onHoverText={hasNoMessage ? null : getDEPMessageResumeTitleText()}
rejectionCause={rejectionCause}
setIsOpen={setIsOpen}
showLogbookMessages={showLogbookMessages}
title={hasNoMessage ? null : getDEPMessageResumeTitle()}
/>
{!hasNoMessage && (
<LogbookMessageContent
$gearOnboard={depMessage.gearOnboard ? depMessage.gearOnboard.length : 1}
$isOpen={isOpen}
speciesOnboard={depMessage.speciesOnboard?.length > 0 ? depMessage.speciesOnboard.length : 1}
>
<Zone>
{depMessage.gearOnboard?.length ? (
depMessage.gearOnboard.map((gear, index) => (
// eslint-disable-next-line react/no-array-index-key
<Gear key={`${gear.gear}-${index}`}>
<SubKey>Engin à bord {index + 1}</SubKey>{' '}
<SubValue>{getCodeWithNameOrDash(gear.gear, gear.gearName)}</SubValue>
<br />
<SubKey>Maillage</SubKey>
<SubValue>{gear.mesh ? <>{gear.mesh} mm</> : <NoValue>-</NoValue>}</SubValue>
<SubKey>Dimensions</SubKey>
<SubValue>{gear.dimensions ? <>{gear.dimensions} m</> : <NoValue>-</NoValue>}</SubValue>
<br />
</Gear>
))
) : (
<NoValue>Pas d&apos;engins à bord</NoValue>
)}
<Fields>
<TableBody>
<Field>
<Key>Captures à bord</Key>
<Value>
{depMessage.speciesOnboard?.length ? (
depMessage.speciesOnboard.map(speciesCatch => (
<span key={speciesCatch.species}>
{getCodeWithNameOrDash(speciesCatch.species, speciesCatch.speciesName)}- {speciesCatch.weight}{' '}
kg
<br />
</span>
))
) : (
<NoValue>aucune</NoValue>
)}
</Value>
</Field>
</TableBody>
</Fields>
</Zone>
</LogbookMessageContent>
)}
</Wrapper>
)
}

Expand Down

0 comments on commit 484121c

Please sign in to comment.