-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add public api to archive reportings
- Loading branch information
1 parent
73975bd
commit c536819
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...otlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicReportingController.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,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) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicReportingControllerITests.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,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) | ||
} | ||
} |