Skip to content

Commit

Permalink
Add public api to archive reportings
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Oct 13, 2023
1 parent 73975bd commit c536819
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package fr.gouv.cnsp.monitorfish.infrastructure.api.public_api

import fr.gouv.cnsp.monitorfish.domain.use_cases.reporting.ArchiveReporting
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.websocket.server.PathParam
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/v1/reportings")
@Tag(name = "Public APIs for reporting")
class PublicReportingController(
private val archiveReporting: ArchiveReporting,
) {

@PutMapping(value = ["/{reportingId}/archive"])
@Operation(summary = "Archive a reporting")
fun archiveReporting(
@PathParam("Reporting id")
@PathVariable(name = "reportingId")
reportingId: Int,
) {
archiveReporting.execute(reportingId)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package fr.gouv.cnsp.monitorfish.infrastructure.api.public_api

import fr.gouv.cnsp.monitorfish.config.OIDCProperties
import fr.gouv.cnsp.monitorfish.config.SecurityConfig
import fr.gouv.cnsp.monitorfish.config.SentryConfig
import fr.gouv.cnsp.monitorfish.domain.use_cases.reporting.ArchiveReporting
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.context.annotation.Import
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status

@Import(SecurityConfig::class, OIDCProperties::class, SentryConfig::class)
@WebMvcTest(value = [PublicReportingController::class])
class PublicReportingControllerITests {

@Autowired
private lateinit var api: MockMvc

@MockBean
private lateinit var archiveReporting: ArchiveReporting

@Test
fun `Should archive a reporting`() {
// When
api.perform(put("/api/v1/reportings/123/archive"))
// Then
.andExpect(status().isOk)

Mockito.verify(archiveReporting).execute(123)
}
}

0 comments on commit c536819

Please sign in to comment.