Skip to content

Commit

Permalink
Update delete mechanism for statuses and add deletedAt timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
lwih committed Oct 20, 2023
1 parent 9a12658 commit b45ddb8
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ data class ActionStatus(
val status: ActionStatusType,
val reason: ActionStatusReason?,
val isStart: Boolean,
val observations: String?
val observations: String?,
val deletedAt: ZonedDateTime? = null,
) {
fun toNavAction(): NavAction {
return NavAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ interface INavActionControlRepository {

fun save(controlAction: ActionControl): ActionControl

fun deleteById(id: UUID)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package fr.gouv.dgampa.rapportnav.domain.repositories.mission.action

import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionStatus
import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.action.ActionStatusModel
import java.util.*

interface INavActionStatusRepository {
fun findAllByMissionId( missionId: Int): List<ActionStatus>

fun findById(id: UUID): ActionStatusModel

fun existsById(id: UUID): Boolean

fun save(statusAction: ActionStatus): ActionStatus

fun deleteById(id: UUID)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GetNavMissionById(

fun execute(missionId: Int): NavMission {
val controls = navActionControlRepository.findAllByMissionId(missionId=missionId).filter { it.deletedAt == null }.map { it.toNavAction() }
val statuses = navStatusRepository.findAllByMissionId(missionId=missionId).map { it.toNavAction() }
val statuses = navStatusRepository.findAllByMissionId(missionId=missionId).filter { it.deletedAt == null }.map { it.toNavAction() }
val actions = controls + statuses
val mission = NavMission(id = missionId, actions = actions)
return mission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package fr.gouv.dgampa.rapportnav.domain.use_cases.missions.status

import fr.gouv.dgampa.rapportnav.config.UseCase
import fr.gouv.dgampa.rapportnav.domain.repositories.mission.action.INavActionStatusRepository
import java.time.ZonedDateTime
import java.util.*

@UseCase
class DeleteStatus(private val statusRepository: INavActionStatusRepository) {
fun execute(id: UUID): Boolean {
if (this.statusRepository.existsById(id)) {
this.statusRepository.deleteById(id)
val statusAction = this.statusRepository.findById(id = id)
statusAction.deletedAt = ZonedDateTime.now()
this.statusRepository.save(statusAction.toActionStatus())
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ data class ActionStatusModel(

@Column(name = "observations", nullable = true)
var observations: String?,

@Column(name = "deleted_at")
var deletedAt: ZonedDateTime? = null,
) {
fun toActionStatus(): ActionStatus {
return ActionStatus(
Expand All @@ -46,6 +49,7 @@ data class ActionStatusModel(
reason = mapStringToActionStatusReason(reason),
isStart = isStart,
observations = observations,
deletedAt = deletedAt,
)
}

Expand All @@ -58,6 +62,7 @@ data class ActionStatusModel(
reason = statusAction.reason.toStringOrNull(),
isStart = statusAction.isStart,
observations = statusAction.observations,
deletedAt = statusAction.deletedAt,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ interface IDBActionControlRepository: JpaRepository<ActionControlModel, Int> {
fun findAllByMissionId(missionId: Int): List<ActionControlModel>

fun existsById(id: UUID): Boolean

fun save(controlAction: ActionControl): ActionControl

fun deleteById(id: UUID)
fun findById(id: UUID): ActionControlModel

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import java.util.*
interface IDBActionStatusRepository: JpaRepository<ActionStatusModel, Int> {
fun findAllByMissionId(missionId: Int): List<ActionStatusModel>

fun findById(id: UUID): ActionStatusModel

fun existsById(id: UUID): Boolean

fun save(statusAction: ActionStatus): ActionStatus

fun deleteById(id: UUID)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,5 @@ class JPAActionControlRepository (
}
}

@Transactional
override fun deleteById(id: UUID) {
try {
dbActionModelRepository.deleteById(id)
} catch (e: InvalidDataAccessApiUsageException) {
throw Exception("Error deleting control", e)
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class JPAActionStatusRepository (
return dbActionStatusRepository.findAllByMissionId(missionId).map { it.toActionStatus() }
}

override fun findById(id: UUID): ActionStatusModel {
return dbActionStatusRepository.findById(id)
}

override fun existsById(id: UUID): Boolean {
return dbActionStatusRepository.existsById(id)
}
Expand All @@ -34,12 +38,4 @@ class JPAActionStatusRepository (
}
}

@Transactional
override fun deleteById(id: UUID) {
try {
dbActionStatusRepository.deleteById(id)
} catch (e: InvalidDataAccessApiUsageException) {
throw Exception("Error deleting status", e)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DO $$
BEGIN
ALTER TABLE mission_action_status
ADD COLUMN deleted_at TIMESTAMP;
END $$;

0 comments on commit b45ddb8

Please sign in to comment.