From 8055f3a896c18a0c00eb05904a1592c040316d67 Mon Sep 17 00:00:00 2001 From: kyeong-hyeok Date: Wed, 22 Nov 2023 14:41:28 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EC=9D=B4=EB=8F=99=EB=B4=89?= =?UTF-8?q?=EC=82=AC=20=EC=8B=A0=EC=B2=AD=20=EC=B7=A8=EC=86=8C,=20?= =?UTF-8?q?=EC=8A=B9=EC=9D=B8,=20=EB=B0=98=EB=A0=A4,=20=EB=B4=89=EC=82=AC?= =?UTF-8?q?=20=EC=99=84=EB=A3=8C=20API=20=EC=9D=91=EB=8B=B5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#141)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApplicationController.java | 26 +++++++++---------- .../response/ApplicationSuccessResponse.java | 7 +++++ .../service/ApplicationService.java | 18 ++++++++----- 3 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/pawwithu/connectdog/domain/application/dto/response/ApplicationSuccessResponse.java diff --git a/src/main/java/com/pawwithu/connectdog/domain/application/controller/ApplicationController.java b/src/main/java/com/pawwithu/connectdog/domain/application/controller/ApplicationController.java index 727b81c9..b680902c 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/application/controller/ApplicationController.java +++ b/src/main/java/com/pawwithu/connectdog/domain/application/controller/ApplicationController.java @@ -90,10 +90,10 @@ public ResponseEntity getVolunteerOneApplica , content = @Content(schema = @Schema(implementation = ErrorResponse.class))) }) @DeleteMapping( "/volunteers/applications/{applicationId}") - public ResponseEntity deleteApplication(@AuthenticationPrincipal UserDetails loginUser, - @PathVariable Long applicationId) { - applicationService.deleteApplication(loginUser.getUsername(), applicationId); - return ResponseEntity.noContent().build(); + public ResponseEntity deleteApplication(@AuthenticationPrincipal UserDetails loginUser, + @PathVariable Long applicationId) { + ApplicationSuccessResponse response = applicationService.deleteApplication(loginUser.getUsername(), applicationId); + return ResponseEntity.ok(response); } @Operation(summary = "봉사 관리 - 승인 대기중 - 이동봉사자 확인 - 봉사 신청 확정", description = "이동봉사자의 봉사 신청을 확정합니다.", @@ -103,10 +103,10 @@ public ResponseEntity deleteApplication(@AuthenticationPrincipal UserDetai , content = @Content(schema = @Schema(implementation = ErrorResponse.class))) }) @PatchMapping( "/intermediaries/applications/{applicationId}") - public ResponseEntity confirmApplication(@AuthenticationPrincipal UserDetails loginUser, + public ResponseEntity confirmApplication(@AuthenticationPrincipal UserDetails loginUser, @PathVariable Long applicationId) { - applicationService.confirmApplication(loginUser.getUsername(), applicationId); - return ResponseEntity.noContent().build(); + ApplicationSuccessResponse response = applicationService.confirmApplication(loginUser.getUsername(), applicationId); + return ResponseEntity.ok(response); } @Operation(summary = "봉사 관리 - 승인 대기중 - 이동봉사자 확인 - 봉사 신청 반려", description = "이동봉사자의 봉사 신청을 반려합니다.", @@ -116,10 +116,10 @@ public ResponseEntity confirmApplication(@AuthenticationPrincipal UserDeta , content = @Content(schema = @Schema(implementation = ErrorResponse.class))) }) @DeleteMapping( "/intermediaries/applications/{applicationId}") - public ResponseEntity cancelApplication(@AuthenticationPrincipal UserDetails loginUser, + public ResponseEntity cancelApplication(@AuthenticationPrincipal UserDetails loginUser, @PathVariable Long applicationId) { - applicationService.cancelApplication(loginUser.getUsername(), applicationId); - return ResponseEntity.noContent().build(); + ApplicationSuccessResponse response = applicationService.cancelApplication(loginUser.getUsername(), applicationId); + return ResponseEntity.ok(response); } @Operation(summary = "봉사 관리 - 승인 대기중 목록 조회", description = "이동봉사 승인 대기중 목록을 조회합니다.", @@ -206,9 +206,9 @@ public ResponseEntity getMyInfo(@Authenticatio , content = @Content(schema = @Schema(implementation = ErrorResponse.class))) }) @PatchMapping( "/intermediaries/applications/{applicationId}/completed") - public ResponseEntity completeApplication(@AuthenticationPrincipal UserDetails loginUser, + public ResponseEntity completeApplication(@AuthenticationPrincipal UserDetails loginUser, @PathVariable Long applicationId) { - applicationService.completeApplication(loginUser.getUsername(), applicationId); - return ResponseEntity.noContent().build(); + ApplicationSuccessResponse response = applicationService.completeApplication(loginUser.getUsername(), applicationId); + return ResponseEntity.ok(response); } } diff --git a/src/main/java/com/pawwithu/connectdog/domain/application/dto/response/ApplicationSuccessResponse.java b/src/main/java/com/pawwithu/connectdog/domain/application/dto/response/ApplicationSuccessResponse.java new file mode 100644 index 00000000..51585d3d --- /dev/null +++ b/src/main/java/com/pawwithu/connectdog/domain/application/dto/response/ApplicationSuccessResponse.java @@ -0,0 +1,7 @@ +package com.pawwithu.connectdog.domain.application.dto.response; + +public record ApplicationSuccessResponse(Boolean isSuccess) { + public static ApplicationSuccessResponse of(Boolean isSuccess) { + return new ApplicationSuccessResponse(isSuccess); + } +} diff --git a/src/main/java/com/pawwithu/connectdog/domain/application/service/ApplicationService.java b/src/main/java/com/pawwithu/connectdog/domain/application/service/ApplicationService.java index 03805bac..dd43d0a2 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/application/service/ApplicationService.java +++ b/src/main/java/com/pawwithu/connectdog/domain/application/service/ApplicationService.java @@ -37,8 +37,6 @@ public class ApplicationService { private final ApplicationRepository applicationRepository; private final CustomApplicationRepository customApplicationRepository; private final IntermediaryRepository intermediaryRepository; - private final ReviewRepository reviewRepository; - private final DogStatusRepository dogStatusRepository; public void volunteerApply(String email, Long postId, VolunteerApplyRequest request) { // 이동봉사자 @@ -87,7 +85,7 @@ public ApplicationVolunteerGetOneResponse getVolunteerOneApplication(String emai return oneApplication; } - public void deleteApplication(String email, Long applicationId) { + public ApplicationSuccessResponse deleteApplication(String email, Long applicationId) { // 이동봉사자 Volunteer volunteer = volunteerRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND)); // 신청 내역 + post @@ -96,9 +94,11 @@ public void deleteApplication(String email, Long applicationId) { // 상태 업데이트 (승인 대기중 -> 모집중) Post post = application.getPost(); post.updateStatus(PostStatus.RECRUITING); + ApplicationSuccessResponse isSuccess = ApplicationSuccessResponse.of(true); + return isSuccess; } - public void confirmApplication(String email, Long applicationId) { + public ApplicationSuccessResponse confirmApplication(String email, Long applicationId) { // 이동봉사 중개 Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND)); // 신청 내역 + post @@ -107,9 +107,11 @@ public void confirmApplication(String email, Long applicationId) { // 상태 업데이트 (승인 대기중 -> 진행중) application.updateStatus(ApplicationStatus.PROGRESSING); post.updateStatus(PostStatus.PROGRESSING); + ApplicationSuccessResponse isSuccess = ApplicationSuccessResponse.of(true); + return isSuccess; } - public void cancelApplication(String email, Long applicationId) { + public ApplicationSuccessResponse cancelApplication(String email, Long applicationId) { // 이동봉사 중개 Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND)); // 신청 내역 + post @@ -118,6 +120,8 @@ public void cancelApplication(String email, Long applicationId) { // 상태 업데이트 (승인 대기중 -> 모집중) Post post = application.getPost(); post.updateStatus(PostStatus.RECRUITING); + ApplicationSuccessResponse isSuccess = ApplicationSuccessResponse.of(true); + return isSuccess; } @Transactional(readOnly = true) @@ -170,7 +174,7 @@ public ApplicationVolunteerInfoResponse getMyInfo(String email) { return volunteerInfo; } - public void completeApplication(String email, Long applicationId) { + public ApplicationSuccessResponse completeApplication(String email, Long applicationId) { // 이동봉사 중개 Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND)); // 신청 내역 + post @@ -179,5 +183,7 @@ public void completeApplication(String email, Long applicationId) { // 상태 업데이트 (진행중 -> 봉사 완료) application.updateStatus(ApplicationStatus.COMPLETED); post.updateStatus(PostStatus.COMPLETED); + ApplicationSuccessResponse isSuccess = ApplicationSuccessResponse.of(true); + return isSuccess; } } From 34715ad0949965c7eb8ab9aa8dccf596f256aa51 Mon Sep 17 00:00:00 2001 From: kyeong-hyeok Date: Wed, 22 Nov 2023 14:41:54 +0900 Subject: [PATCH 2/3] =?UTF-8?q?test:=20=EC=9D=B4=EB=8F=99=EB=B4=89?= =?UTF-8?q?=EC=82=AC=20=EC=8B=A0=EC=B2=AD=20=EC=B7=A8=EC=86=8C,=20?= =?UTF-8?q?=EC=8A=B9=EC=9D=B8,=20=EB=B0=98=EB=A0=A4,=20=EB=B4=89=EC=82=AC?= =?UTF-8?q?=20=EC=99=84=EB=A3=8C=20Controller=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95=20(#141)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApplicationControllerTest.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/pawwithu/connectdog/domain/application/controller/ApplicationControllerTest.java b/src/test/java/com/pawwithu/connectdog/domain/application/controller/ApplicationControllerTest.java index d9adc1e4..cfaad04d 100644 --- a/src/test/java/com/pawwithu/connectdog/domain/application/controller/ApplicationControllerTest.java +++ b/src/test/java/com/pawwithu/connectdog/domain/application/controller/ApplicationControllerTest.java @@ -135,14 +135,16 @@ void setUp() { void 이동봉사_신청_취소() throws Exception { //given Long applicationId = 1L; + ApplicationSuccessResponse response = new ApplicationSuccessResponse(true); //when + given(applicationService.deleteApplication(anyString(), anyLong())).willReturn(response); ResultActions result = mockMvc.perform( delete("/volunteers/applications/{applicationId}", applicationId) ); //then - result.andExpect(status().isNoContent()); + result.andExpect(status().isOk()); verify(applicationService, times(1)).deleteApplication(anyString(), anyLong()); } @@ -150,14 +152,16 @@ void setUp() { void 이동봉사_신청_승인() throws Exception { //given Long applicationId = 1L; + ApplicationSuccessResponse response = new ApplicationSuccessResponse(true); //when + given(applicationService.confirmApplication(anyString(), anyLong())).willReturn(response); ResultActions result = mockMvc.perform( patch("/intermediaries/applications/{applicationId}", applicationId) ); //then - result.andExpect(status().isNoContent()); + result.andExpect(status().isOk()); verify(applicationService, times(1)).confirmApplication(anyString(), anyLong()); } @@ -165,14 +169,16 @@ void setUp() { void 이동봉사_신청_반려() throws Exception { //given Long applicationId = 1L; + ApplicationSuccessResponse response = new ApplicationSuccessResponse(true); //when + given(applicationService.cancelApplication(anyString(), anyLong())).willReturn(response); ResultActions result = mockMvc.perform( delete("/intermediaries/applications/{applicationId}", applicationId) ); //then - result.andExpect(status().isNoContent()); + result.andExpect(status().isOk()); verify(applicationService, times(1)).cancelApplication(anyString(), anyLong()); } @@ -306,17 +312,19 @@ void setUp() { } @Test - void 이동봉사_완료() throws Exception { + void 이동봉사_완료하기() throws Exception { //given Long applicationId = 1L; + ApplicationSuccessResponse response = new ApplicationSuccessResponse(true); //when + given(applicationService.completeApplication(anyString(), anyLong())).willReturn(response); ResultActions result = mockMvc.perform( patch("/intermediaries/applications/{applicationId}/completed", applicationId) ); //then - result.andExpect(status().isNoContent()); + result.andExpect(status().isOk()); verify(applicationService, times(1)).completeApplication(anyString(), anyLong()); } From cdfd1100681fb822cc1803df0ee3c27cef93a66b Mon Sep 17 00:00:00 2001 From: kyeong-hyeok Date: Wed, 22 Nov 2023 14:45:33 +0900 Subject: [PATCH 3/3] =?UTF-8?q?chore:=20@=20Transactional(readOnly=20=3D?= =?UTF-8?q?=20true)=20=EC=B6=94=EA=B0=80=20(#141)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/intermediary/service/IntermediaryService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/pawwithu/connectdog/domain/intermediary/service/IntermediaryService.java b/src/main/java/com/pawwithu/connectdog/domain/intermediary/service/IntermediaryService.java index a4f9c171..6bebd3bc 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/intermediary/service/IntermediaryService.java +++ b/src/main/java/com/pawwithu/connectdog/domain/intermediary/service/IntermediaryService.java @@ -80,6 +80,7 @@ public List getIntermediaryDogStatuses(Long return intermediaryDogStatuses; } + @Transactional(readOnly = true) public IntermediaryGetHomeResponse getIntermediaryHome(String email) { Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND)); Map countOfPostStatus = customPostRepository.getCountOfPostStatus(intermediary.getId(), null);