From 3255a1b0f9f3be3f888f1c5d5a3d65bfc0f7eb2f Mon Sep 17 00:00:00 2001 From: Cr1stal423 <124814908+Cr1stal423@users.noreply.github.com> Date: Tue, 14 Jan 2025 18:06:08 +0200 Subject: [PATCH] fix(userController): use DELETE method for removing UserProfilePicture (#446) --- core/src/main/java/greencity/controller/UserController.java | 3 ++- .../test/java/greencity/controller/UserControllerTest.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/greencity/controller/UserController.java b/core/src/main/java/greencity/controller/UserController.java index 5cf9ee32..63b6a9f4 100644 --- a/core/src/main/java/greencity/controller/UserController.java +++ b/core/src/main/java/greencity/controller/UserController.java @@ -67,6 +67,7 @@ import org.springframework.messaging.handler.annotation.Payload; import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -340,7 +341,7 @@ public ResponseEntity updateUserProfilePicture( @ApiResponse(responseCode = "400", description = HttpStatuses.BAD_REQUEST), @ApiResponse(responseCode = "401", description = HttpStatuses.UNAUTHORIZED), }) - @PatchMapping(path = "/deleteProfilePicture") + @DeleteMapping(path = "/deleteProfilePicture") public ResponseEntity deleteUserProfilePicture(Principal principal) { userService.deleteUserProfilePicture(principal.getName()); return ResponseEntity.ok().build(); diff --git a/core/src/test/java/greencity/controller/UserControllerTest.java b/core/src/test/java/greencity/controller/UserControllerTest.java index 14cdd960..27b2253e 100644 --- a/core/src/test/java/greencity/controller/UserControllerTest.java +++ b/core/src/test/java/greencity/controller/UserControllerTest.java @@ -60,6 +60,8 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -322,7 +324,7 @@ void updateUserProfilePictureTest() throws Exception { void deleteUserProfilePictureTest() throws Exception { Principal principal = mock(Principal.class); when(principal.getName()).thenReturn("test@email.com"); - mockMvc.perform(patch(userLink + "/deleteProfilePicture") + mockMvc.perform(delete(userLink + "/deleteProfilePicture") .principal(principal)) .andExpect(status().isOk());