Skip to content

Commit

Permalink
Normalize update/delete methods & routes in ReportingController
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Oct 15, 2024
1 parent d1b2f11 commit d58ca34
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ReportingController(
archiveReporting.execute(reportingId)
}

@PutMapping(value = ["/{reportingId}/update"], consumes = ["application/json"])
@PutMapping(value = ["/{reportingId}"], consumes = ["application/json"])
@Operation(summary = "Update a reporting")
fun updateReporting(
@PathParam("Reporting id")
Expand All @@ -78,7 +78,7 @@ class ReportingController(
archiveReportings.execute(ids)
}

@PutMapping(value = ["/{reportingId}/delete"])
@DeleteMapping(value = ["/{reportingId}"])
@Operation(summary = "Delete a reporting")
fun deleteReporting(
@PathParam("Reporting id")
Expand All @@ -88,7 +88,7 @@ class ReportingController(
deleteReporting.execute(reportingId)
}

@PutMapping(value = ["/delete"])
@DeleteMapping(value = [""])
@Operation(summary = "Delete multiple reportings")
fun deleteReporting(
@RequestBody ids: List<Int>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ReportingControllerITests {
@Test
fun `Should delete a reporting`() {
// When
api.perform(put("/bff/v1/reportings/123/delete"))
api.perform(delete("/bff/v1/reportings/123"))
// Then
.andExpect(status().isOk)

Expand All @@ -100,7 +100,7 @@ class ReportingControllerITests {
fun `Should delete multiple reportings`() {
// When
api.perform(
put("/bff/v1/reportings/delete")
delete("/bff/v1/reportings")
.content(objectMapper.writeValueAsString(listOf(1, 2, 3)))
.contentType(MediaType.APPLICATION_JSON),
)
Expand Down Expand Up @@ -299,7 +299,7 @@ class ReportingControllerITests {

// When
api.perform(
put("/bff/v1/reportings/123/update")
put("/bff/v1/reportings/123")
.content(
objectMapper.writeValueAsString(
UpdateReportingDataInput(
Expand Down
13 changes: 5 additions & 8 deletions frontend/src/features/Reporting/reportingApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,21 @@ export const reportingApi = monitorfishApi.injectEndpoints({
transformErrorResponse: response => new FrontendApiError(CREATE_REPORTING_ERROR_MESSAGE, response)
}),

// TODO Replace Backend route with a DELETE instead of a PUT.
deleteReporting: builder.mutation<void, number>({
invalidatesTags: [{ type: RtkCacheTagType.Reportings }],
query: reportingId => ({
method: 'PUT',
url: `/reportings/${reportingId}/delete`
method: 'DELETE',
url: `/reportings/${reportingId}`
}),
transformErrorResponse: response => new FrontendApiError(DELETE_REPORTING_ERROR_MESSAGE, response)
}),

// TODO Replace Backend route with a DELETE instead of a PUT.
deleteReportings: builder.mutation<void, number[]>({
invalidatesTags: [{ type: RtkCacheTagType.Reportings }],
query: reportingIds => ({
body: reportingIds,
method: 'PUT',
url: `/reportings/delete`
method: 'DELETE',
url: `/reportings`
}),
transformErrorResponse: response => new FrontendApiError(DELETE_REPORTINGS_ERROR_MESSAGE, response)
}),
Expand All @@ -79,13 +77,12 @@ export const reportingApi = monitorfishApi.injectEndpoints({
transformErrorResponse: response => new FrontendApiError(GET_REPORTINGS_ERROR_MESSAGE, response)
}),

// TODO Remove the useless "/update" route part in Backend.
updateReporting: builder.mutation<Reporting.Reporting, { id: number; nextReportingFormData: EditedReporting }>({
invalidatesTags: [{ type: RtkCacheTagType.Reportings }],
query: ({ id, nextReportingFormData }) => ({
body: nextReportingFormData,
method: 'PUT',
url: `/reportings/${id}/update`
url: `/reportings/${id}`
}),
transformErrorResponse: response => new FrontendApiError(UPDATE_REPORTING_ERROR_MESSAGE, response)
})
Expand Down

0 comments on commit d58ca34

Please sign in to comment.