-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Tableau de bord] endpoint de sauvegarde #1752
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1ca4eed
feat: save dashboard and briefing. todo: save filters
maximeperrault 25230c1
feat: add endpoint and refacto briefing
maximeperrault 2381dc7
feat: add geom to dashboard
maximeperrault b62e874
feat: add comments and control units and rename briefing to dashboard…
maximeperrault a1c9125
feat: claire's review
maximeperrault File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...end/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/dashboard/DashboardEntity.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,20 @@ | ||
package fr.gouv.cacem.monitorenv.domain.entities.dashboard | ||
|
||
import org.locationtech.jts.geom.Geometry | ||
import java.time.ZonedDateTime | ||
import java.util.UUID | ||
|
||
data class DashboardEntity( | ||
val id: UUID?, | ||
val name: String, | ||
val geom: Geometry, | ||
val comments: String?, | ||
val createdAt: ZonedDateTime?, | ||
val updatedAt: ZonedDateTime?, | ||
val inseeCode: String?, | ||
val amps: List<Int>, | ||
val controlUnits: List<Int>, | ||
val regulatoryAreas: List<Int>, | ||
val reportings: List<Int>, | ||
val vigilanceAreas: List<Int>, | ||
) |
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
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
7 changes: 7 additions & 0 deletions
7
backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/repositories/IDashboardRepository.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,7 @@ | ||
package fr.gouv.cacem.monitorenv.domain.repositories | ||
|
||
import fr.gouv.cacem.monitorenv.domain.entities.dashboard.DashboardEntity | ||
|
||
interface IDashboardRepository { | ||
fun save(dashboard: DashboardEntity): DashboardEntity | ||
} |
25 changes: 25 additions & 0 deletions
25
backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/SaveDashboard.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,25 @@ | ||
package fr.gouv.cacem.monitorenv.domain.use_cases.dashboard | ||
|
||
import fr.gouv.cacem.monitorenv.config.UseCase | ||
import fr.gouv.cacem.monitorenv.domain.entities.dashboard.DashboardEntity | ||
import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageErrorCode | ||
import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageException | ||
import fr.gouv.cacem.monitorenv.domain.repositories.IDashboardRepository | ||
import org.slf4j.LoggerFactory | ||
|
||
@UseCase | ||
class SaveDashboard( | ||
private val dashboardRepository: IDashboardRepository, | ||
) { | ||
private val logger = LoggerFactory.getLogger(SaveDashboard::class.java) | ||
|
||
fun execute(dashboard: DashboardEntity): DashboardEntity { | ||
try { | ||
return dashboardRepository.save(dashboard) | ||
} catch (e: Exception) { | ||
val errorMessage = "dashboard ${dashboard.id} couldn't be saved" | ||
logger.error(errorMessage, e) | ||
throw BackendUsageException(BackendUsageErrorCode.ENTITY_NOT_SAVED, message = errorMessage) | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
.../cacem/monitorenv/infrastructure/api/adapters/bff/inputs/dashboards/DashboardDataInput.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,38 @@ | ||
package fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.inputs.dashboards | ||
|
||
import fr.gouv.cacem.monitorenv.domain.entities.dashboard.DashboardEntity | ||
import org.locationtech.jts.geom.Geometry | ||
import java.time.ZonedDateTime | ||
import java.util.UUID | ||
|
||
class DashboardDataInput( | ||
val id: UUID?, | ||
val name: String, | ||
val geom: Geometry, | ||
val createdAt: ZonedDateTime?, | ||
val updatedAt: ZonedDateTime?, | ||
val comments: String?, | ||
val inseeCode: String?, | ||
val amps: List<Int>, | ||
val controlUnits: List<Int>, | ||
val regulatoryAreas: List<Int>, | ||
val reportings: List<Int>, | ||
val vigilanceAreas: List<Int>, | ||
) { | ||
fun toDashboardEntity(): DashboardEntity { | ||
return DashboardEntity( | ||
id = id, | ||
name = name, | ||
geom = geom, | ||
comments = comments, | ||
createdAt = createdAt, | ||
updatedAt = updatedAt, | ||
inseeCode = inseeCode, | ||
amps = amps, | ||
controlUnits = controlUnits, | ||
reportings = reportings, | ||
regulatoryAreas = regulatoryAreas, | ||
vigilanceAreas = vigilanceAreas, | ||
) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...acem/monitorenv/infrastructure/api/adapters/bff/outputs/dashboards/DashboardDataOutput.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,40 @@ | ||
package fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.dashboards | ||
|
||
import fr.gouv.cacem.monitorenv.domain.entities.dashboard.DashboardEntity | ||
import org.locationtech.jts.geom.Geometry | ||
import java.time.ZonedDateTime | ||
import java.util.UUID | ||
|
||
class DashboardDataOutput( | ||
val id: UUID?, | ||
val name: String, | ||
val geom: Geometry, | ||
val comments: String?, | ||
val createdAt: ZonedDateTime?, | ||
val updatedAt: ZonedDateTime?, | ||
val inseeCode: String?, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem ici |
||
val amps: List<Int>, | ||
val controlUnits: List<Int>, | ||
val regulatoryAreas: List<Int>, | ||
val reportings: List<Int>, | ||
val vigilanceAreas: List<Int>, | ||
) { | ||
companion object { | ||
fun fromDashboardEntity(dashboardEntity: DashboardEntity): DashboardDataOutput { | ||
return DashboardDataOutput( | ||
id = dashboardEntity.id, | ||
name = dashboardEntity.name, | ||
geom = dashboardEntity.geom, | ||
comments = dashboardEntity.comments, | ||
createdAt = dashboardEntity.createdAt, | ||
updatedAt = dashboardEntity.updatedAt, | ||
inseeCode = dashboardEntity.inseeCode, | ||
amps = dashboardEntity.amps, | ||
controlUnits = dashboardEntity.controlUnits, | ||
regulatoryAreas = dashboardEntity.regulatoryAreas, | ||
reportings = dashboardEntity.reportings, | ||
vigilanceAreas = dashboardEntity.vigilanceAreas, | ||
) | ||
} | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
...rs/bff/outputs/ExtractedAreaDataOutput.kt → ...uts/dashboards/ExtractedAreaDataOutput.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
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
43 changes: 43 additions & 0 deletions
43
...main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/DashboardDatasModel.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,43 @@ | ||
package fr.gouv.cacem.monitorenv.infrastructure.database.model | ||
|
||
import fr.gouv.cacem.monitorenv.infrastructure.database.model.reportings.ReportingModel | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.FetchType | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.JoinColumn | ||
import jakarta.persistence.ManyToOne | ||
import jakarta.persistence.OneToOne | ||
import jakarta.persistence.Table | ||
import java.util.UUID | ||
|
||
@Entity | ||
@Table(name = "dashboard_datas") | ||
data class DashboardDatasModel( | ||
@Id | ||
@Column(name = "id", unique = true, nullable = false) | ||
@GeneratedValue(strategy = GenerationType.UUID) | ||
val id: UUID?, | ||
@ManyToOne(fetch = FetchType.LAZY, optional = false) | ||
@JoinColumn(name = "dashboard_id") | ||
var dashboard: DashboardModel?, | ||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "amp_cacem_id") | ||
val amp: AMPModel?, | ||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "reportings_id") | ||
val reportingModel: ReportingModel?, | ||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "vigilance_area_id") | ||
val vigilanceAreaModel: VigilanceAreaModel?, | ||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "regulations_cacem_id") | ||
val regulatoryAreaModel: RegulatoryAreaModel?, | ||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "control_unit_id") | ||
val controlUnitModel: ControlUnitModel?, | ||
@Column(name = "insee_code") | ||
val inseeCode: String?, | ||
) |
127 changes: 127 additions & 0 deletions
127
.../src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/DashboardModel.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,127 @@ | ||
package fr.gouv.cacem.monitorenv.infrastructure.database.model | ||
|
||
import fr.gouv.cacem.monitorenv.domain.entities.dashboard.DashboardEntity | ||
import jakarta.persistence.CascadeType | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.FetchType | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.OneToMany | ||
import jakarta.persistence.PrePersist | ||
import jakarta.persistence.PreUpdate | ||
import jakarta.persistence.Table | ||
import org.locationtech.jts.geom.Geometry | ||
import java.time.ZonedDateTime | ||
import java.util.UUID | ||
|
||
@Entity | ||
@Table(name = "dashboard") | ||
data class DashboardModel( | ||
@Id | ||
@Column(name = "id", unique = true, nullable = false) | ||
@GeneratedValue(strategy = GenerationType.UUID) | ||
val id: UUID?, | ||
val name: String, | ||
val geom: Geometry, | ||
val comments: String?, | ||
var createdAt: ZonedDateTime?, | ||
var updatedAt: ZonedDateTime?, | ||
@OneToMany( | ||
mappedBy = "dashboard", | ||
fetch = FetchType.LAZY, | ||
cascade = [CascadeType.ALL], | ||
) | ||
val dashboardDatas: MutableList<DashboardDatasModel>, | ||
) { | ||
fun toDashboardEntity(): DashboardEntity { | ||
val amps: MutableList<Int> = mutableListOf() | ||
val regulatoryAreas: MutableList<Int> = mutableListOf() | ||
val vigilanceAreas: MutableList<Int> = mutableListOf() | ||
val reportings: MutableList<Int> = mutableListOf() | ||
val controlUnits: MutableList<Int> = mutableListOf() | ||
var inseeCode: String? = null | ||
dashboardDatas.forEach { datas -> | ||
datas.amp.let { | ||
if (it?.id != null) { | ||
amps.add(it.id) | ||
} | ||
} | ||
datas.regulatoryAreaModel.let { | ||
if (it?.id != null) { | ||
regulatoryAreas.add(it.id) | ||
} | ||
} | ||
datas.vigilanceAreaModel.let { | ||
if (it?.id != null) { | ||
vigilanceAreas.add(it.id) | ||
} | ||
} | ||
datas.reportingModel.let { | ||
if (it?.id != null) { | ||
reportings.add(it.id) | ||
} | ||
} | ||
datas.controlUnitModel.let { | ||
if (it?.id != null) { | ||
controlUnits.add(it.id) | ||
} | ||
} | ||
if (datas.inseeCode != null) { | ||
inseeCode = datas.inseeCode | ||
} | ||
} | ||
return DashboardEntity( | ||
id = id, | ||
name = name, | ||
geom = geom, | ||
comments = comments, | ||
createdAt = createdAt, | ||
updatedAt = updatedAt, | ||
inseeCode = inseeCode, | ||
amps = amps, | ||
controlUnits = controlUnits, | ||
regulatoryAreas = regulatoryAreas, | ||
reportings = reportings, | ||
vigilanceAreas = vigilanceAreas, | ||
) | ||
} | ||
|
||
fun addDashboardDatas(dashboardDatasModel: DashboardDatasModel) { | ||
dashboardDatasModel.dashboard = this | ||
this.dashboardDatas.add(dashboardDatasModel) | ||
} | ||
|
||
@PrePersist | ||
private fun prePersist() { | ||
this.createdAt = ZonedDateTime.now() | ||
} | ||
|
||
@PreUpdate | ||
private fun preUpdate() { | ||
this.updatedAt = ZonedDateTime.now() | ||
} | ||
|
||
companion object { | ||
fun fromDashboardEntity( | ||
dashboardEntity: DashboardEntity, | ||
dashboardDatasModels: List<DashboardDatasModel>, | ||
): DashboardModel { | ||
val dashboardModel = | ||
DashboardModel( | ||
id = dashboardEntity.id, | ||
name = dashboardEntity.name, | ||
geom = dashboardEntity.geom, | ||
comments = dashboardEntity.comments, | ||
createdAt = dashboardEntity.createdAt, | ||
updatedAt = dashboardEntity.updatedAt, | ||
dashboardDatas = mutableListOf(), | ||
) | ||
dashboardDatasModels.forEach { | ||
dashboardModel.addDashboardDatas(it) | ||
} | ||
return dashboardModel | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
je pense que le code INSEE sera toujours présent, puisqu'on le récupère de l'api
/extract
, non?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu peux avoir un tableau qui pointe sur aucun département non ? SI on est loin des côtes ?