diff --git a/src/main/java/com/baro/memofolder/presentation/MemoFolderController.java b/src/main/java/com/baro/memofolder/presentation/MemoFolderController.java index 9f69cd2..1e6c64a 100644 --- a/src/main/java/com/baro/memofolder/presentation/MemoFolderController.java +++ b/src/main/java/com/baro/memofolder/presentation/MemoFolderController.java @@ -7,7 +7,6 @@ import com.baro.memofolder.application.dto.RenameMemoFolderCommand; import com.baro.memofolder.application.dto.SaveMemoFolderCommand; import com.baro.memofolder.application.dto.SaveMemoFolderResult; -import com.baro.memofolder.presentation.dto.DeleteMemoFolderRequest; import com.baro.memofolder.presentation.dto.RenameMemoFolderRequest; import com.baro.memofolder.presentation.dto.SaveMemoFolderRequest; import java.net.URI; @@ -17,9 +16,11 @@ 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; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; @@ -56,10 +57,10 @@ public ResponseEntity renameMemoFolder(AuthMember authMember, @RequestBody return ResponseEntity.noContent().build(); } - @DeleteMapping - public ResponseEntity deleteMemoFolder(AuthMember authMember, @RequestBody DeleteMemoFolderRequest request) { - DeleteMemoFolderCommand command = new DeleteMemoFolderCommand(authMember.id(), request.memoFolderId(), - request.deleteAllMemo()); + @DeleteMapping("/{memoFolderId}") + public ResponseEntity deleteMemoFolder(AuthMember authMember, @PathVariable("memoFolderId") Long memoFolderId, + @RequestParam("deleteAllMemo") boolean deleteAllMemo) { + DeleteMemoFolderCommand command = new DeleteMemoFolderCommand(authMember.id(), memoFolderId, deleteAllMemo); memoFolderService.deleteMemoFolder(command); return ResponseEntity.noContent().build(); } diff --git a/src/test/java/com/baro/common/acceptance/memofolder/MemoFolderAcceptanceSteps.java b/src/test/java/com/baro/common/acceptance/memofolder/MemoFolderAcceptanceSteps.java index c8119a2..be9ea5f 100644 --- a/src/test/java/com/baro/common/acceptance/memofolder/MemoFolderAcceptanceSteps.java +++ b/src/test/java/com/baro/common/acceptance/memofolder/MemoFolderAcceptanceSteps.java @@ -11,9 +11,11 @@ import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; +import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; +import static org.springframework.restdocs.request.RequestDocumentation.queryParameters; import com.baro.auth.domain.Token; -import com.baro.memofolder.presentation.dto.DeleteMemoFolderRequest; import com.baro.memofolder.presentation.dto.RenameMemoFolderRequest; import com.baro.memofolder.presentation.dto.SaveMemoFolderRequest; import io.restassured.response.ExtractableResponse; @@ -143,42 +145,50 @@ public class MemoFolderAcceptanceSteps { .extract(); } - public static ExtractableResponse 폴더_삭제_요청_성공(Token 토큰, DeleteMemoFolderRequest 바디) { - var url = "/memo-folders"; + public static ExtractableResponse 폴더_삭제_요청_성공(Token 토큰, Long 메모폴더Id, boolean 모두삭제여부) { + var url = "/memo-folders/{memoFolderId}"; return given(requestSpec).log().all() .filter(document(DEFAULT_REST_DOCS_PATH, requestHeaders( headerWithName(HttpHeaders.AUTHORIZATION).description("인증 토큰") ), - requestFields( - fieldWithPath("memoFolderId").description("폴더 id"), - fieldWithPath("deleteAllMemo").description("폴더에 있는 메모를 모두 삭제할지 여부") + pathParameters( + parameterWithName("memoFolderId").description("폴더 id") + ), + queryParameters( + parameterWithName("deleteAllMemo").description("폴더에 있는 메모를 모두 삭제할지 여부") ) )) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header(HttpHeaders.AUTHORIZATION, "Bearer " + 토큰.accessToken()).body(바디) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + 토큰.accessToken()) + .pathParam("memoFolderId", 메모폴더Id) + .queryParam("deleteAllMemo", 모두삭제여부) .when().delete(url) .then().log().all() .extract(); } - public static ExtractableResponse 폴더_삭제_요청_실패(Token 토큰, DeleteMemoFolderRequest 바디) { - var url = "/memo-folders"; + public static ExtractableResponse 폴더_삭제_요청_실패(Token 토큰, Long 메모폴더Id, boolean 모두삭제여부) { + var url = "/memo-folders/{memoFolderId}"; return given(requestSpec).log().all() .filter(document(DEFAULT_REST_DOCS_PATH, requestHeaders( headerWithName(HttpHeaders.AUTHORIZATION).description("인증 토큰") ), - requestFields( - fieldWithPath("memoFolderId").description("폴더 id"), - fieldWithPath("deleteAllMemo").description("폴더에 있는 메모를 모두 삭제할지 여부") + pathParameters( + parameterWithName("memoFolderId").description("폴더 id") + ), + queryParameters( + parameterWithName("deleteAllMemo").description("폴더에 있는 메모를 모두 삭제할지 여부") ), responseFields(예외_응답()) )) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header(HttpHeaders.AUTHORIZATION, "Bearer " + 토큰.accessToken()).body(바디) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + 토큰.accessToken()) + .pathParam("memoFolderId", 메모폴더Id) + .queryParam("deleteAllMemo", 모두삭제여부) .when().delete(url) .then().log().all() .extract(); diff --git a/src/test/java/com/baro/memofolder/presentation/MemoFolderApiTest.java b/src/test/java/com/baro/memofolder/presentation/MemoFolderApiTest.java index 081a9a0..fdd7460 100644 --- a/src/test/java/com/baro/memofolder/presentation/MemoFolderApiTest.java +++ b/src/test/java/com/baro/memofolder/presentation/MemoFolderApiTest.java @@ -32,7 +32,6 @@ import com.baro.member.exception.MemberException; import com.baro.member.exception.MemberExceptionType; import com.baro.memofolder.domain.MemoFolderRepository; -import com.baro.memofolder.presentation.dto.DeleteMemoFolderRequest; import com.baro.memofolder.presentation.dto.RenameMemoFolderRequest; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; @@ -194,10 +193,9 @@ class MemoFolderApiTest extends RestApiTest { // given var 토큰 = 로그인(원진()); var 메모폴더ID = 메모_폴더를_생성_하고_ID를_반환한다(토큰, 폴더_이름_바디); - var 바디 = new DeleteMemoFolderRequest(메모폴더ID, true); // when - var 응답 = 폴더_삭제_요청_성공(토큰, 바디); + var 응답 = 폴더_삭제_요청_성공(토큰, 메모폴더ID, true); // then 응답값을_검증한다(응답, 응답값_없음); @@ -208,10 +206,9 @@ class MemoFolderApiTest extends RestApiTest { // given var 토큰 = 로그인(원진()); var 메모폴더ID = 메모_폴더를_생성_하고_ID를_반환한다(토큰, 폴더_이름_바디); - var 바디 = new DeleteMemoFolderRequest(메모폴더ID, false); // when - var 응답 = 폴더_삭제_요청_성공(토큰, 바디); + var 응답 = 폴더_삭제_요청_성공(토큰, 메모폴더ID, false); // then 응답값을_검증한다(응답, 응답값_없음); @@ -222,10 +219,9 @@ class MemoFolderApiTest extends RestApiTest { // given var 토큰 = 로그인(원진()); var 존재하지않는_메모폴더ID = 999L; - var 바디 = new DeleteMemoFolderRequest(존재하지않는_메모폴더ID, false); // when - var 응답 = 폴더_삭제_요청_실패(토큰, 바디); + var 응답 = 폴더_삭제_요청_실패(토큰, 존재하지않는_메모폴더ID, false); // then 응답값을_검증한다(응답, 존재하지_않음); @@ -237,10 +233,9 @@ class MemoFolderApiTest extends RestApiTest { var 원진토큰 = 로그인(원진()); var 준희토큰 = 로그인(준희()); var 메모폴더ID = 메모_폴더를_생성_하고_ID를_반환한다(원진토큰, 폴더_이름_바디); - var 바디 = new DeleteMemoFolderRequest(메모폴더ID, false); // when - var 응답 = 폴더_삭제_요청_실패(준희토큰, 바디); + var 응답 = 폴더_삭제_요청_실패(준희토큰, 메모폴더ID, false); // then 응답값을_검증한다(응답, 권한_없음); @@ -251,11 +246,9 @@ class MemoFolderApiTest extends RestApiTest { // given var 토큰 = 로그인(원진()); var 기본폴더ID = 기본폴더의_ID(); - var 메모폴더ID = 메모_폴더를_생성_하고_ID를_반환한다(토큰, 폴더_이름_바디); - var 바디 = new DeleteMemoFolderRequest(기본폴더ID, false); // when - var 응답 = 폴더_삭제_요청_실패(토큰, 바디); + var 응답 = 폴더_삭제_요청_실패(토큰, 기본폴더ID, false); // then 응답값을_검증한다(응답, 권한_없음);