Skip to content

Commit

Permalink
feat(action): delete a nav action
Browse files Browse the repository at this point in the history
 - controller delete by id
 - use case delete by id
 - test delete by id
 - front action delete
  • Loading branch information
xtiannyeto committed Dec 30, 2024
1 parent 609ff13 commit 975f837
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.util.*
@RestController
@RequestMapping("/api/v2/missions/{missionId}/actions")
class MissionActionRestController(
private val deleteNavAction: DeleteNavAction,
private val createNavAction: CreateNavAction,
private val updateEnvAction: UpdateEnvAction,
private val updateNavAction: UpdateNavAction,
Expand Down Expand Up @@ -71,4 +72,10 @@ class MissionActionRestController(
this.logger.info(body.id)
return MissionAction.fromMissionActionEntity(response)
}

@DeleteMapping("{actionId}")
@Operation(summary = "Delete a mission action")
fun deleteAction(@PathVariable(name = "actionId") actionId: String): Unit {
deleteNavAction.execute(UUID.fromString(actionId))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CreateNavActionTest {
private lateinit var missionActionRepository: INavMissionActionRepository

@Test
fun `test execute update nav action`() {
fun `test execute create nav action`() {
val actionId = UUID.randomUUID().toString()
val input = MissionNavAction(
id = actionId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package fr.gouv.gmampa.rapportnav.domain.use_cases.mission.action

import fr.gouv.dgampa.rapportnav.domain.repositories.mission.action.INavMissionActionRepository
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.DeleteNavAction
import org.assertj.core.api.Assertions.assertThatNoException
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.doNothing
import org.mockito.kotlin.doReturn
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.test.context.ContextConfiguration
import java.util.*


@SpringBootTest(classes = [DeleteNavAction::class])
@ContextConfiguration(classes = [DeleteNavAction::class])
class DeleteNavActionTest {
@MockBean
private lateinit var missionActionRepository: INavMissionActionRepository

@Test
fun `test execute delete nav action`() {
val actionId = UUID.randomUUID()
doNothing().`when`(missionActionRepository).deleteById(actionId)

val deleteNavAction = DeleteNavAction(
missionActionRepository = missionActionRepository
)
deleteNavAction.execute(actionId)
assertThatNoException()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useMutation, UseMutationResult, useQueryClient } from '@tanstack/react-query'

import axios from '../../../../query-client/axios'

const useDeleteActionMutation = (missionId: number): UseMutationResult<void, Error, string, unknown> => {
const queryClient = useQueryClient()

const deleteAction = (actionId: string): Promise<void> =>
axios.delete(`missions/${missionId}/actions/${actionId}`).then(response => response.data)

const mutation = useMutation({
mutationFn: deleteAction,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['actions'] })
}
})
return mutation
}

export default useDeleteActionMutation
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { Accent, Icon, IconButton, Size, THEME } from '@mtes-mct/monitor-ui'
import { useNavigate } from 'react-router-dom'
import { Stack } from 'rsuite'
import useDeleteActionMutation from '../../../common/services/use-delete-mission-action'

interface MissionActionHeaderActionProps {}
interface MissionActionHeaderActionProps {
actionId: string
missionId: number
}

export const MissionActionHeaderAction: React.FC<MissionActionHeaderActionProps> = () => {
const handleDelete = () => console.log('DELETE')
export const MissionActionHeaderAction: React.FC<MissionActionHeaderActionProps> = ({ missionId, actionId }) => {
const navigate = useNavigate()
const mutation = useDeleteActionMutation(missionId)
const handleDelete = async () => {
await mutation.mutateAsync(actionId)
navigate(`/v2/pam/missions/${missionId}`)
}

return (
<Stack direction="row" spacing="0.5rem">
Expand Down

0 comments on commit 975f837

Please sign in to comment.