Skip to content

Commit

Permalink
fix(action): UUID parsing error for fish
Browse files Browse the repository at this point in the history
 - Move uuid parsing in use_case to avoid error
 - update Use_case and test
  • Loading branch information
xtiannyeto committed Jan 2, 2025
1 parent 85c6dd2 commit 895bbf7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ class GetNavActionById(
): GetMissionAction(getStatusForAction, getControlByActionId) {
private val logger = LoggerFactory.getLogger(GetNavActionById::class.java)

fun execute(actionId: UUID?): MissionNavActionEntity? {
fun execute(actionId: String?): MissionNavActionEntity? {
if (actionId == null) {
logger.error("GetNavActionById received a null actionId")
throw IllegalArgumentException("GetNavActionById should not receive null missionId or actionId null")
}
val model = missionActionRepository.findById(actionId).orElse(null) ?: return null
val entity = MissionNavActionEntity.fromMissionActionModel(model)
entity.computeControls(controls = this.getControls(entity))
entity.computeCompleteness()
return entity
return try {
val model = missionActionRepository.findById(UUID.fromString(actionId)).orElse(null) ?: return null
val entity = MissionNavActionEntity.fromMissionActionModel(model)
entity.computeControls(controls = this.getControls(entity))
entity.computeCompleteness()
entity
} catch (e: Exception) {
logger.error("GetNavActionById failed loading action", e)
return null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEnti
import fr.gouv.dgampa.rapportnav.domain.repositories.mission.action.INavMissionActionRepository
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControl
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfraction
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.MissionAction
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.MissionNavAction
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.MissionNavActionData
import org.slf4j.LoggerFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.v2

import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.*
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.*
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.MissionAction
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.MissionEnvAction
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.MissionFishAction
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.MissionNavAction
import io.swagger.v3.oas.annotations.Operation
import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.*
Expand Down Expand Up @@ -41,7 +44,7 @@ class MissionActionRestController(
@PathVariable(name = "missionId") missionId: Int,
@PathVariable(name = "actionId") actionId: String,
): MissionAction? {
val navAction = getNavActionById.execute(actionId = UUID.fromString(actionId))
val navAction = getNavActionById.execute(actionId = actionId)
if (navAction != null) return MissionAction.fromMissionActionEntity(navAction)

val fishAction = getFishActionById.execute(missionId = missionId, actionId = actionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GetNavActionByIdTest {
missionActionRepository = missionActionRepository, getStatusForAction = getStatusForAction,
getControlByActionId = getControlByActionId
)
val missionEnvAction = getNavActionById.execute(actionId = actionId)
val missionEnvAction = getNavActionById.execute(actionId = actionId.toString())

assertThat(missionEnvAction).isNotNull
assertThat(missionEnvAction?.getActionId()).isEqualTo(actionId.toString())
Expand Down

0 comments on commit 895bbf7

Please sign in to comment.