-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32f2fd4
commit c9e609e
Showing
6 changed files
with
118 additions
and
25 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
.../kotlin/fr/gouv/dgampa/rapportnav/domain/repositories/v2/mission/IEnvMissionRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package fr.gouv.dgampa.rapportnav.domain.repositories.v2.mission | ||
|
||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.env.MissionEntity | ||
import fr.gouv.dgampa.rapportnav.infrastructure.monitorenv.v2.inputs.CreateOrUpdateMissionDataInput | ||
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.MissionEnv | ||
|
||
interface IEnvMissionRepository { | ||
fun createMission(input: CreateOrUpdateMissionDataInput): MissionEntity? | ||
fun createMission(mission: MissionEnv): MissionEntity? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...d/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionEnv.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2 | ||
|
||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum | ||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionTypeEnum | ||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.controlResources.LegacyControlUnitEntity | ||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.env.MissionEntity | ||
import org.locationtech.jts.geom.MultiPolygon | ||
import java.time.ZonedDateTime | ||
|
||
data class MissionEnv( | ||
val id: Int? = null, | ||
val missionTypes: List<MissionTypeEnum>, | ||
var controlUnits: List<LegacyControlUnitEntity> = listOf(), | ||
val openBy: String? = null, | ||
val completedBy: String? = null, | ||
val observationsCacem: String? = null, | ||
val observationsCnsp: String? = null, | ||
val facade: String? = null, | ||
val geom: MultiPolygon? = null, | ||
val startDateTimeUtc: ZonedDateTime, | ||
val endDateTimeUtc: ZonedDateTime? = null, | ||
val missionSource: MissionSourceEnum, | ||
val hasMissionOrder: Boolean, | ||
val isUnderJdp: Boolean = false, | ||
val isGeometryComputedFromControls: Boolean = false, | ||
) { | ||
|
||
companion object { | ||
fun fromMissionEntity(mission: MissionEntity): MissionEnv { | ||
return MissionEnv( | ||
id = mission.id, | ||
missionSource = mission.missionSource, | ||
startDateTimeUtc = mission.startDateTimeUtc, | ||
endDateTimeUtc = mission.endDateTimeUtc, | ||
openBy = mission.openBy, | ||
controlUnits = mission.controlUnits, | ||
hasMissionOrder = mission.hasMissionOrder, | ||
missionTypes = mission.missionTypes, | ||
) | ||
} | ||
} | ||
fun toMissionEntity(): MissionEntity { | ||
return MissionEntity( | ||
id = this.id, | ||
missionTypes = this.missionTypes, | ||
controlUnits = this.controlUnits, | ||
openBy = this.openBy, | ||
completedBy = this.completedBy, | ||
observationsCacem = this.observationsCacem, | ||
observationsCnsp = this.observationsCnsp, | ||
facade = this.facade, | ||
geom = this.geom, | ||
startDateTimeUtc = this.startDateTimeUtc, | ||
endDateTimeUtc = this.endDateTimeUtc, | ||
isDeleted = false, | ||
missionSource = this.missionSource, | ||
hasMissionOrder = this.hasMissionOrder, | ||
isUnderJdp = this.isUnderJdp, | ||
isGeometryComputedFromControls = this.isGeometryComputedFromControls, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
.../main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/v2/MissionRestController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.v2 | ||
|
||
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.CreateEnvMission | ||
import fr.gouv.dgampa.rapportnav.domain.use_cases.user.GetControlUnitsForUser | ||
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.MissionEnv | ||
import io.swagger.v3.oas.annotations.Operation | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/api/v2/missions") | ||
class MissionRestController( | ||
private val createEnvMission: CreateEnvMission, | ||
private val getControlUnitsForUser: GetControlUnitsForUser, | ||
) { | ||
|
||
private val logger = LoggerFactory.getLogger(MissionRestController::class.java) | ||
|
||
@PostMapping("") | ||
@Operation(summary = "Create a new MonitorEnv mission") | ||
fun create( | ||
@RequestBody body: MissionEnv | ||
): MissionEnv? { | ||
try { | ||
val mission = createEnvMission.execute( | ||
mission = body, | ||
controlUnitIds = getControlUnitsForUser.execute() | ||
) | ||
|
||
if (mission != null) { | ||
return MissionEnv.fromMissionEntity(mission) | ||
} | ||
|
||
throw RuntimeException("Error - can't create new MonitorEnv mission") | ||
} | ||
catch (e: Exception) { | ||
logger.error("Error while creating MonitorEnv mission : ", e) | ||
return null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters