From 9e126ffa60bbdfda528f1094361f0432f10e37b2 Mon Sep 17 00:00:00 2001 From: Seoyoung-Kyung Date: Fri, 20 Feb 2026 15:24:00 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B0=9C=EC=9D=B8=ED=9A=8C=EA=B3=A0=20i?= =?UTF-8?q?d=20=EC=97=86=EC=9D=B4=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/PersonalRetrospectiveApi.java | 36 ++-- .../PersonalRetrospectiveController.java | 27 ++- .../PersonalRetrospectiveRepository.java | 2 + .../service/PersonalRetrospectiveService.java | 29 ++-- .../service/RetrospectiveValidator.java | 5 + .../PersonalRetrospectiveServiceTest.java | 156 ++++++++++-------- 6 files changed, 133 insertions(+), 122 deletions(-) diff --git a/src/main/java/com/dokdok/retrospective/api/PersonalRetrospectiveApi.java b/src/main/java/com/dokdok/retrospective/api/PersonalRetrospectiveApi.java index 5aeb9d2a..313fdfac 100644 --- a/src/main/java/com/dokdok/retrospective/api/PersonalRetrospectiveApi.java +++ b/src/main/java/com/dokdok/retrospective/api/PersonalRetrospectiveApi.java @@ -226,7 +226,7 @@ ResponseEntity> getPersonalRetros summary = "개인 회고 수정 폼 조회 (developer: 경서영)", description = """ 기존에 작성한 개인 회고를 수정하기 위한 데이터를 조회합니다. - - 권한: 약속 멤버 + - 권한: 약속 멤버 (본인이 작성한 회고만 조회 가능) **응답 구조** - changedThoughts: 기존 생각의 변화 목록 (confirmOrder 순) @@ -236,8 +236,7 @@ ResponseEntity> getPersonalRetros - meetingMembers: 본인 제외 약속 멤버 목록 """, parameters = { - @Parameter(name = "meetingId", description = "약속 식별자", in = ParameterIn.PATH, required = true), - @Parameter(name = "retrospectiveId", description = "개인 회고 식별자", in = ParameterIn.PATH, required = true) + @Parameter(name = "meetingId", description = "약속 식별자", in = ParameterIn.PATH, required = true) } ) @ApiResponses({ @@ -311,17 +310,16 @@ ResponseEntity> getPersonalRetros ) ) }) - @GetMapping(value = "/{retrospectiveId}/form", produces = MediaType.APPLICATION_JSON_VALUE) + @GetMapping(value = "/form/edit", produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity> getPersonalRetrospectiveEditForm( - @PathVariable Long meetingId, - @PathVariable Long retrospectiveId + @PathVariable Long meetingId ); @Operation( summary = "개인 회고 상세 조회 (developer: 경서영)", description = """ - 특정 개인 회고의 상세 정보를 조회합니다. - - 권한: 약속 멤버 + 본인이 작성한 개인 회고의 상세 정보를 조회합니다. + - 권한: 약속 멤버 (본인 회고만 조회 가능) **응답 구조** - changedThoughts: 생각의 변화 목록 (confirmOrder 순, 주제별 사전/사후 의견) @@ -329,8 +327,7 @@ ResponseEntity> getPersonalRetros - freeTexts: 자유 기록 목록 """, parameters = { - @Parameter(name = "meetingId", description = "약속 식별자", in = ParameterIn.PATH, required = true), - @Parameter(name = "retrospectiveId", description = "개인 회고 식별자", in = ParameterIn.PATH, required = true) + @Parameter(name = "meetingId", description = "약속 식별자", in = ParameterIn.PATH, required = true) } ) @ApiResponses({ @@ -404,10 +401,9 @@ ResponseEntity> getPersonalRetros ) ) }) - @GetMapping(value = "/{retrospectiveId}", produces = MediaType.APPLICATION_JSON_VALUE) + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity> getPersonalRetrospective( - @PathVariable Long meetingId, - @PathVariable Long retrospectiveId + @PathVariable Long meetingId ); @Operation( @@ -419,8 +415,7 @@ ResponseEntity> getPersonalRetr - 동작: 기존 데이터 삭제 후 새로운 데이터로 전체 교체 """, parameters = { - @Parameter(name = "meetingId", description = "약속 식별자", in = ParameterIn.PATH, required = true), - @Parameter(name = "retrospectiveId", description = "개인 회고 식별자", in = ParameterIn.PATH, required = true) + @Parameter(name = "meetingId", description = "약속 식별자", in = ParameterIn.PATH, required = true) } ) @ApiResponses({ @@ -506,10 +501,9 @@ ResponseEntity> getPersonalRetr ) ) }) - @PutMapping(value = "/{retrospectiveId}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity> editPersonalRetrospective( @PathVariable Long meetingId, - @PathVariable Long retrospectiveId, @Valid @RequestBody PersonalRetrospectiveRequest request ); @@ -522,8 +516,7 @@ ResponseEntity> editPersonalRetrospec - 제약: 이미 삭제된 회고는 다시 삭제 불가 """, parameters = { - @Parameter(name = "meetingId", description = "약속 식별자", in = ParameterIn.PATH, required = true), - @Parameter(name = "retrospectiveId", description = "개인 회고 식별자", in = ParameterIn.PATH, required = true) + @Parameter(name = "meetingId", description = "약속 식별자", in = ParameterIn.PATH, required = true) } ) @ApiResponses({ @@ -604,9 +597,8 @@ ResponseEntity> editPersonalRetrospec ) ) }) - @DeleteMapping(value = "/{retrospectiveId}", produces = MediaType.APPLICATION_JSON_VALUE) + @DeleteMapping(produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity> deletePersonalRetrospective( - @PathVariable Long meetingId, - @PathVariable Long retrospectiveId + @PathVariable Long meetingId ); } diff --git a/src/main/java/com/dokdok/retrospective/controller/PersonalRetrospectiveController.java b/src/main/java/com/dokdok/retrospective/controller/PersonalRetrospectiveController.java index 321712c4..7dcad071 100644 --- a/src/main/java/com/dokdok/retrospective/controller/PersonalRetrospectiveController.java +++ b/src/main/java/com/dokdok/retrospective/controller/PersonalRetrospectiveController.java @@ -45,50 +45,45 @@ public ResponseEntity> getPersona @Override - @GetMapping("/{retrospectiveId}/form") + @GetMapping("/form/edit") public ResponseEntity> getPersonalRetrospectiveEditForm( - @PathVariable Long meetingId, - @PathVariable Long retrospectiveId + @PathVariable Long meetingId ) { PersonalRetrospectiveEditResponse response - = personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId, retrospectiveId); + = personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId); return ApiResponse.success(response, "개인 회고 수정 폼 조회를 성공했습니다."); } @Override - @PutMapping("/{retrospectiveId}") + @PutMapping public ResponseEntity> editPersonalRetrospective( @PathVariable Long meetingId, - @PathVariable Long retrospectiveId, @Valid @RequestBody PersonalRetrospectiveRequest request ) { PersonalRetrospectiveResponse response = - personalRetrospectiveService.editPersonalRetrospective(meetingId, retrospectiveId, request); + personalRetrospectiveService.editPersonalRetrospective(meetingId, request); return ApiResponse.success(response, "개인 회고 수정을 성공했습니다."); } @Override - @DeleteMapping("/{retrospectiveId}") + @DeleteMapping public ResponseEntity> deletePersonalRetrospective( - @PathVariable Long meetingId, - @PathVariable Long retrospectiveId + @PathVariable Long meetingId ) { - - personalRetrospectiveService.deletePersonalRetrospective(meetingId, retrospectiveId); + personalRetrospectiveService.deletePersonalRetrospective(meetingId); return ApiResponse.deleted("개인 회고 삭제를 성공했습니다."); } @Override - @GetMapping("/{retrospectiveId}") + @GetMapping public ResponseEntity> getPersonalRetrospective( - @PathVariable Long meetingId, - @PathVariable Long retrospectiveId + @PathVariable Long meetingId ) { PersonalRetrospectiveDetailResponse response - = personalRetrospectiveService.getPersonalRetrospective(meetingId, retrospectiveId); + = personalRetrospectiveService.getPersonalRetrospective(meetingId); return ApiResponse.success(response, "개인 회고 조회를 성공했습니다."); } diff --git a/src/main/java/com/dokdok/retrospective/repository/PersonalRetrospectiveRepository.java b/src/main/java/com/dokdok/retrospective/repository/PersonalRetrospectiveRepository.java index 2efebf84..9b4785ac 100644 --- a/src/main/java/com/dokdok/retrospective/repository/PersonalRetrospectiveRepository.java +++ b/src/main/java/com/dokdok/retrospective/repository/PersonalRetrospectiveRepository.java @@ -85,6 +85,8 @@ int countRetrospectivesByBookAndUser( boolean existsByIdAndUserId(Long retrospectiveId, Long userId); + Optional findByMeeting_IdAndUser_Id(Long meetingId, Long userId); + @Query(""" SELECT pmr FROM PersonalMeetingRetrospective pmr diff --git a/src/main/java/com/dokdok/retrospective/service/PersonalRetrospectiveService.java b/src/main/java/com/dokdok/retrospective/service/PersonalRetrospectiveService.java index b0b9f267..73a50fd0 100644 --- a/src/main/java/com/dokdok/retrospective/service/PersonalRetrospectiveService.java +++ b/src/main/java/com/dokdok/retrospective/service/PersonalRetrospectiveService.java @@ -100,16 +100,16 @@ public PersonalRetrospectiveFormResponse getPersonalRetrospectiveForm(Long meeti } @Transactional(readOnly = true) - public PersonalRetrospectiveEditResponse getPersonalRetrospectiveEditForm( - Long meetingId, - Long retrospectiveId - ) { + public PersonalRetrospectiveEditResponse getPersonalRetrospectiveEditForm(Long meetingId) { Long userId = SecurityUtil.getCurrentUserId(); meetingValidator.validateMeeting(meetingId); meetingValidator.validateMeetingMember(meetingId, userId); - retrospectiveValidator.validateRetrospective(retrospectiveId); + + PersonalMeetingRetrospective retrospective + = retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId); + Long retrospectiveId = retrospective.getId(); List changedThoughts = changedThoughtRepository.findByPersonalMeetingRetrospective(retrospectiveId); @@ -138,16 +138,14 @@ public PersonalRetrospectiveEditResponse getPersonalRetrospectiveEditForm( @Transactional public PersonalRetrospectiveResponse editPersonalRetrospective( Long meetingId, - Long retrospectiveId, PersonalRetrospectiveRequest request ) { Long userId = SecurityUtil.getCurrentUserId(); meetingValidator.validateMeeting(meetingId); meetingValidator.validateMeetingMember(meetingId, userId); - retrospectiveValidator.validateRetrospective(retrospectiveId); PersonalMeetingRetrospective retrospective - = retrospectiveValidator.getRetrospective(retrospectiveId, userId); + = retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId); retrospective.clearChangedThoughts(); retrospective.clearOthersPerspectives(); @@ -230,29 +228,28 @@ public CursorResponse g } @Transactional - public void deletePersonalRetrospective(Long meetingId, Long retrospectiveId) { + public void deletePersonalRetrospective(Long meetingId) { Long userId = SecurityUtil.getCurrentUserId(); meetingValidator.validateMeeting(meetingId); meetingValidator.validateMeetingMember(meetingId, userId); PersonalMeetingRetrospective retrospective - = retrospectiveValidator.getRetrospective(retrospectiveId, userId); + = retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId); retrospective.softDelete(); } @Transactional(readOnly = true) - public PersonalRetrospectiveDetailResponse getPersonalRetrospective( - Long meetingId, - Long retrospectiveId - ) { + public PersonalRetrospectiveDetailResponse getPersonalRetrospective(Long meetingId) { Long userId = SecurityUtil.getCurrentUserId(); meetingValidator.validateMeeting(meetingId); meetingValidator.validateMeetingMember(meetingId, userId); - retrospectiveValidator.validateRetrospective(retrospectiveId); - retrospectiveValidator.validateRetrospectiveByUser(retrospectiveId, userId); + + PersonalMeetingRetrospective retrospective + = retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId); + Long retrospectiveId = retrospective.getId(); List changedThoughts = changedThoughtRepository.findByPersonalMeetingRetrospective(retrospectiveId); diff --git a/src/main/java/com/dokdok/retrospective/service/RetrospectiveValidator.java b/src/main/java/com/dokdok/retrospective/service/RetrospectiveValidator.java index bf2c0a3b..9ad75b18 100644 --- a/src/main/java/com/dokdok/retrospective/service/RetrospectiveValidator.java +++ b/src/main/java/com/dokdok/retrospective/service/RetrospectiveValidator.java @@ -76,6 +76,11 @@ public PersonalMeetingRetrospective getRetrospective(Long retrospectiveId, Long } + public PersonalMeetingRetrospective getRetrospectiveByMeetingAndUser(Long meetingId, Long userId) { + return personalRetrospectiveRepository.findByMeeting_IdAndUser_Id(meetingId, userId) + .orElseThrow(() -> new RetrospectiveException(RetrospectiveErrorCode.RETROSPECTIVE_NOT_FOUND)); + } + public void validateMeetingRetrospectiveDeletePermission(MeetingRetrospective retrospective, Long userId) { // 삭제하는 사람이 작성자 본인인지 확인 if (retrospective.getCreatedBy().getId().equals(userId)) { diff --git a/src/test/java/com/dokdok/retrospective/service/PersonalRetrospectiveServiceTest.java b/src/test/java/com/dokdok/retrospective/service/PersonalRetrospectiveServiceTest.java index 7114091a..f17679e4 100644 --- a/src/test/java/com/dokdok/retrospective/service/PersonalRetrospectiveServiceTest.java +++ b/src/test/java/com/dokdok/retrospective/service/PersonalRetrospectiveServiceTest.java @@ -709,6 +709,14 @@ void getPersonalRetrospectiveEditForm_success() { Long retrospectiveId = 100L; Long userId = 3L; + Meeting meeting = Meeting.builder().id(meetingId).build(); + User user = User.builder().id(userId).build(); + PersonalMeetingRetrospective retrospective = PersonalMeetingRetrospective.builder() + .id(retrospectiveId) + .meeting(meeting) + .user(user) + .build(); + List changedThoughts = List.of(); List othersPerspectives = List.of(); List freeTexts = List.of(); @@ -727,7 +735,7 @@ void getPersonalRetrospectiveEditForm_success() { doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - doNothing().when(retrospectiveValidator).validateRetrospective(retrospectiveId); + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)).thenReturn(retrospective); when(changedThoughtRepository.findByPersonalMeetingRetrospective(retrospectiveId)) .thenReturn(changedThoughts); when(othersPerspectiveRepository.findByPersonalMeetingRetrospective(retrospectiveId)) @@ -743,7 +751,7 @@ void getPersonalRetrospectiveEditForm_success() { // when PersonalRetrospectiveEditResponse response = - personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId, retrospectiveId); + personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId); // then assertThat(response.retrospectiveId()).isEqualTo(retrospectiveId); @@ -753,7 +761,7 @@ void getPersonalRetrospectiveEditForm_success() { verify(meetingValidator).validateMeeting(meetingId); verify(meetingValidator).validateMeetingMember(meetingId, userId); - verify(retrospectiveValidator).validateRetrospective(retrospectiveId); + verify(retrospectiveValidator).getRetrospectiveByMeetingAndUser(meetingId, userId); verify(changedThoughtRepository).findByPersonalMeetingRetrospective(retrospectiveId); verify(othersPerspectiveRepository).findByPersonalMeetingRetrospective(retrospectiveId); verify(freeTextRepository).findByPersonalMeetingRetrospective_Id(retrospectiveId); @@ -771,6 +779,14 @@ void getPersonalRetrospectiveEditForm_withEmptyContent_success() { Long retrospectiveId = 100L; Long userId = 3L; + Meeting meeting = Meeting.builder().id(meetingId).build(); + User user = User.builder().id(userId).build(); + PersonalMeetingRetrospective retrospective = PersonalMeetingRetrospective.builder() + .id(retrospectiveId) + .meeting(meeting) + .user(user) + .build(); + List changedThoughts = List.of(); List othersPerspectives = List.of(); List freeTexts = List.of(); @@ -791,7 +807,7 @@ void getPersonalRetrospectiveEditForm_withEmptyContent_success() { doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - doNothing().when(retrospectiveValidator).validateRetrospective(retrospectiveId); + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)).thenReturn(retrospective); when(changedThoughtRepository.findByPersonalMeetingRetrospective(retrospectiveId)) .thenReturn(changedThoughts); when(othersPerspectiveRepository.findByPersonalMeetingRetrospective(retrospectiveId)) @@ -805,7 +821,7 @@ void getPersonalRetrospectiveEditForm_withEmptyContent_success() { // when PersonalRetrospectiveEditResponse response = - personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId, retrospectiveId); + personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId); // then assertThat(response.retrospective().changedThoughts()).isEmpty(); @@ -819,7 +835,6 @@ void getPersonalRetrospectiveEditForm_withEmptyContent_success() { void getPersonalRetrospectiveEditForm_throwsWhenMeetingNotFound() { // given Long meetingId = 999L; - Long retrospectiveId = 100L; Long userId = 3L; try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { @@ -830,7 +845,7 @@ void getPersonalRetrospectiveEditForm_throwsWhenMeetingNotFound() { // when & then assertThatThrownBy(() -> - personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId, retrospectiveId)) + personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId)) .isInstanceOf(MeetingException.class) .hasFieldOrPropertyWithValue("errorCode", MeetingErrorCode.MEETING_NOT_FOUND); @@ -843,7 +858,6 @@ void getPersonalRetrospectiveEditForm_throwsWhenMeetingNotFound() { void getPersonalRetrospectiveEditForm_throwsWhenNotMeetingMember() { // given Long meetingId = 1L; - Long retrospectiveId = 100L; Long userId = 999L; try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { @@ -855,7 +869,7 @@ void getPersonalRetrospectiveEditForm_throwsWhenNotMeetingMember() { // when & then assertThatThrownBy(() -> - personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId, retrospectiveId)) + personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId)) .isInstanceOf(MeetingException.class) .hasFieldOrPropertyWithValue("errorCode", MeetingErrorCode.NOT_MEETING_MEMBER); @@ -868,7 +882,6 @@ void getPersonalRetrospectiveEditForm_throwsWhenNotMeetingMember() { void getPersonalRetrospectiveEditForm_throwsWhenRetrospectiveNotFound() { // given Long meetingId = 1L; - Long retrospectiveId = 999L; Long userId = 3L; try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { @@ -876,12 +889,12 @@ void getPersonalRetrospectiveEditForm_throwsWhenRetrospectiveNotFound() { doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - doThrow(new RetrospectiveException(RetrospectiveErrorCode.RETROSPECTIVE_NOT_FOUND)) - .when(retrospectiveValidator).validateRetrospective(retrospectiveId); + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)) + .thenThrow(new RetrospectiveException(RetrospectiveErrorCode.RETROSPECTIVE_NOT_FOUND)); // when & then assertThatThrownBy(() -> - personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId, retrospectiveId)) + personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId)) .isInstanceOf(RetrospectiveException.class) .hasFieldOrPropertyWithValue("errorCode", RetrospectiveErrorCode.RETROSPECTIVE_NOT_FOUND); @@ -894,7 +907,6 @@ void getPersonalRetrospectiveEditForm_throwsWhenRetrospectiveNotFound() { void getPersonalRetrospectiveEditForm_throwsWhenUnauthenticated() { // given Long meetingId = 1L; - Long retrospectiveId = 100L; try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { securityUtilMock.when(SecurityUtil::getCurrentUserId) @@ -902,7 +914,7 @@ void getPersonalRetrospectiveEditForm_throwsWhenUnauthenticated() { // when & then assertThatThrownBy(() -> - personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId, retrospectiveId)) + personalRetrospectiveService.getPersonalRetrospectiveEditForm(meetingId)) .isInstanceOf(GlobalException.class) .hasFieldOrPropertyWithValue("errorCode", GlobalErrorCode.UNAUTHORIZED); @@ -971,7 +983,7 @@ void editPersonalRetrospective_success() { doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - when(retrospectiveValidator.getRetrospective(retrospectiveId, userId)).thenReturn(existingRetrospective); + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)).thenReturn(existingRetrospective); when(topicValidator.getTopicInMeeting(topicId, meetingId)).thenReturn(topic); when(topicAnswerRepository.findPreOpinion(topicId, userId)).thenReturn(topicAnswer); when(topicRepository.findById(topicId)).thenReturn(Optional.of(topic)); @@ -980,7 +992,7 @@ void editPersonalRetrospective_success() { // when PersonalRetrospectiveResponse response = - personalRetrospectiveService.editPersonalRetrospective(meetingId, retrospectiveId, request); + personalRetrospectiveService.editPersonalRetrospective(meetingId, request); // then assertThat(response.personalMeetingRetrospectiveId()).isEqualTo(retrospectiveId); @@ -989,7 +1001,7 @@ void editPersonalRetrospective_success() { verify(meetingValidator).validateMeeting(meetingId); verify(meetingValidator).validateMeetingMember(meetingId, userId); - verify(retrospectiveValidator).getRetrospective(retrospectiveId, userId); + verify(retrospectiveValidator).getRetrospectiveByMeetingAndUser(meetingId, userId); verify(topicValidator).getTopicInMeeting(topicId, meetingId); verify(topicAnswerRepository).findPreOpinion(topicId, userId); verify(topicRepository).findById(topicId); @@ -1032,12 +1044,12 @@ void editPersonalRetrospective_withEmptyData_success() { doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - when(retrospectiveValidator.getRetrospective(retrospectiveId, userId)).thenReturn(existingRetrospective); + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)).thenReturn(existingRetrospective); when(personalRetrospectiveRepository.save(any(PersonalMeetingRetrospective.class))).thenReturn(saved); // when PersonalRetrospectiveResponse response = - personalRetrospectiveService.editPersonalRetrospective(meetingId, retrospectiveId, request); + personalRetrospectiveService.editPersonalRetrospective(meetingId, request); // then assertThat(response.personalMeetingRetrospectiveId()).isEqualTo(retrospectiveId); @@ -1100,7 +1112,7 @@ void editPersonalRetrospective_withMultipleItems_success() { doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - when(retrospectiveValidator.getRetrospective(retrospectiveId, userId)).thenReturn(existingRetrospective); + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)).thenReturn(existingRetrospective); when(topicValidator.getTopicInMeeting(10L, meetingId)).thenReturn(topic1); when(topicValidator.getTopicInMeeting(20L, meetingId)).thenReturn(topic2); when(topicAnswerRepository.findPreOpinion(anyLong(), eq(userId))).thenReturn(null); @@ -1112,7 +1124,7 @@ void editPersonalRetrospective_withMultipleItems_success() { // when PersonalRetrospectiveResponse response = - personalRetrospectiveService.editPersonalRetrospective(meetingId, retrospectiveId, request); + personalRetrospectiveService.editPersonalRetrospective(meetingId, request); // then assertThat(response.personalMeetingRetrospectiveId()).isEqualTo(retrospectiveId); @@ -1131,7 +1143,6 @@ void editPersonalRetrospective_withMultipleItems_success() { void editPersonalRetrospective_throwsWhenMeetingNotFound() { // given Long meetingId = 999L; - Long retrospectiveId = 100L; Long userId = 3L; PersonalRetrospectiveRequest request = new PersonalRetrospectiveRequest(null, null, null); @@ -1143,7 +1154,7 @@ void editPersonalRetrospective_throwsWhenMeetingNotFound() { // when & then assertThatThrownBy(() -> - personalRetrospectiveService.editPersonalRetrospective(meetingId, retrospectiveId, request)) + personalRetrospectiveService.editPersonalRetrospective(meetingId, request)) .isInstanceOf(MeetingException.class) .hasFieldOrPropertyWithValue("errorCode", MeetingErrorCode.MEETING_NOT_FOUND); @@ -1156,7 +1167,6 @@ void editPersonalRetrospective_throwsWhenMeetingNotFound() { void editPersonalRetrospective_throwsWhenNotMeetingMember() { // given Long meetingId = 1L; - Long retrospectiveId = 100L; Long userId = 999L; PersonalRetrospectiveRequest request = new PersonalRetrospectiveRequest(null, null, null); @@ -1169,7 +1179,7 @@ void editPersonalRetrospective_throwsWhenNotMeetingMember() { // when & then assertThatThrownBy(() -> - personalRetrospectiveService.editPersonalRetrospective(meetingId, retrospectiveId, request)) + personalRetrospectiveService.editPersonalRetrospective(meetingId, request)) .isInstanceOf(MeetingException.class) .hasFieldOrPropertyWithValue("errorCode", MeetingErrorCode.NOT_MEETING_MEMBER); @@ -1182,7 +1192,6 @@ void editPersonalRetrospective_throwsWhenNotMeetingMember() { void editPersonalRetrospective_throwsWhenRetrospectiveNotFound() { // given Long meetingId = 1L; - Long retrospectiveId = 999L; Long userId = 3L; PersonalRetrospectiveRequest request = new PersonalRetrospectiveRequest(null, null, null); @@ -1191,12 +1200,12 @@ void editPersonalRetrospective_throwsWhenRetrospectiveNotFound() { doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - when(retrospectiveValidator.getRetrospective(retrospectiveId, userId)) + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)) .thenThrow(new RetrospectiveException(RetrospectiveErrorCode.RETROSPECTIVE_NOT_FOUND)); // when & then assertThatThrownBy(() -> - personalRetrospectiveService.editPersonalRetrospective(meetingId, retrospectiveId, request)) + personalRetrospectiveService.editPersonalRetrospective(meetingId, request)) .isInstanceOf(RetrospectiveException.class) .hasFieldOrPropertyWithValue("errorCode", RetrospectiveErrorCode.RETROSPECTIVE_NOT_FOUND); @@ -1209,7 +1218,6 @@ void editPersonalRetrospective_throwsWhenRetrospectiveNotFound() { void editPersonalRetrospective_throwsWhenUnauthenticated() { // given Long meetingId = 1L; - Long retrospectiveId = 100L; PersonalRetrospectiveRequest request = new PersonalRetrospectiveRequest(null, null, null); try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { @@ -1218,7 +1226,7 @@ void editPersonalRetrospective_throwsWhenUnauthenticated() { // when & then assertThatThrownBy(() -> - personalRetrospectiveService.editPersonalRetrospective(meetingId, retrospectiveId, request)) + personalRetrospectiveService.editPersonalRetrospective(meetingId, request)) .isInstanceOf(GlobalException.class) .hasFieldOrPropertyWithValue("errorCode", GlobalErrorCode.UNAUTHORIZED); @@ -1260,13 +1268,13 @@ void editPersonalRetrospective_throwsWhenTopicNotFound() { doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - when(retrospectiveValidator.getRetrospective(retrospectiveId, userId)).thenReturn(existingRetrospective); + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)).thenReturn(existingRetrospective); when(topicValidator.getTopicInMeeting(topicId, meetingId)) .thenThrow(new TopicException(TopicErrorCode.TOPIC_NOT_FOUND)); // when & then assertThatThrownBy(() -> - personalRetrospectiveService.editPersonalRetrospective(meetingId, retrospectiveId, request)) + personalRetrospectiveService.editPersonalRetrospective(meetingId, request)) .isInstanceOf(TopicException.class) .hasFieldOrPropertyWithValue("errorCode", TopicErrorCode.TOPIC_NOT_FOUND); @@ -1443,15 +1451,15 @@ void deletePersonalRetrospective_success() { doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - when(retrospectiveValidator.getRetrospective(retrospectiveId, userId)).thenReturn(retrospective); + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)).thenReturn(retrospective); // when - personalRetrospectiveService.deletePersonalRetrospective(meetingId, retrospectiveId); + personalRetrospectiveService.deletePersonalRetrospective(meetingId); // then verify(meetingValidator).validateMeeting(meetingId); verify(meetingValidator).validateMeetingMember(meetingId, userId); - verify(retrospectiveValidator).getRetrospective(retrospectiveId, userId); + verify(retrospectiveValidator).getRetrospectiveByMeetingAndUser(meetingId, userId); } } @@ -1460,7 +1468,6 @@ void deletePersonalRetrospective_success() { void deletePersonalRetrospective_throwsWhenMeetingNotFound() { // given Long meetingId = 999L; - Long retrospectiveId = 100L; Long userId = 3L; try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { @@ -1471,11 +1478,11 @@ void deletePersonalRetrospective_throwsWhenMeetingNotFound() { // when & then assertThatThrownBy(() -> - personalRetrospectiveService.deletePersonalRetrospective(meetingId, retrospectiveId)) + personalRetrospectiveService.deletePersonalRetrospective(meetingId)) .isInstanceOf(MeetingException.class) .hasFieldOrPropertyWithValue("errorCode", MeetingErrorCode.MEETING_NOT_FOUND); - verify(retrospectiveValidator, never()).getRetrospective(any(), any()); + verify(retrospectiveValidator, never()).getRetrospectiveByMeetingAndUser(any(), any()); } } @@ -1484,7 +1491,6 @@ void deletePersonalRetrospective_throwsWhenMeetingNotFound() { void deletePersonalRetrospective_throwsWhenNotMeetingMember() { // given Long meetingId = 1L; - Long retrospectiveId = 100L; Long userId = 999L; try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { @@ -1496,11 +1502,11 @@ void deletePersonalRetrospective_throwsWhenNotMeetingMember() { // when & then assertThatThrownBy(() -> - personalRetrospectiveService.deletePersonalRetrospective(meetingId, retrospectiveId)) + personalRetrospectiveService.deletePersonalRetrospective(meetingId)) .isInstanceOf(MeetingException.class) .hasFieldOrPropertyWithValue("errorCode", MeetingErrorCode.NOT_MEETING_MEMBER); - verify(retrospectiveValidator, never()).getRetrospective(any(), any()); + verify(retrospectiveValidator, never()).getRetrospectiveByMeetingAndUser(any(), any()); } } @@ -1509,7 +1515,6 @@ void deletePersonalRetrospective_throwsWhenNotMeetingMember() { void deletePersonalRetrospective_throwsWhenRetrospectiveNotFound() { // given Long meetingId = 1L; - Long retrospectiveId = 999L; Long userId = 3L; try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { @@ -1517,12 +1522,12 @@ void deletePersonalRetrospective_throwsWhenRetrospectiveNotFound() { doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - when(retrospectiveValidator.getRetrospective(retrospectiveId, userId)) + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)) .thenThrow(new RetrospectiveException(RetrospectiveErrorCode.RETROSPECTIVE_NOT_FOUND)); // when & then assertThatThrownBy(() -> - personalRetrospectiveService.deletePersonalRetrospective(meetingId, retrospectiveId)) + personalRetrospectiveService.deletePersonalRetrospective(meetingId)) .isInstanceOf(RetrospectiveException.class) .hasFieldOrPropertyWithValue("errorCode", RetrospectiveErrorCode.RETROSPECTIVE_NOT_FOUND); } @@ -1533,7 +1538,6 @@ void deletePersonalRetrospective_throwsWhenRetrospectiveNotFound() { void deletePersonalRetrospective_throwsWhenUnauthenticated() { // given Long meetingId = 1L; - Long retrospectiveId = 100L; try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { securityUtilMock.when(SecurityUtil::getCurrentUserId) @@ -1541,7 +1545,7 @@ void deletePersonalRetrospective_throwsWhenUnauthenticated() { // when & then assertThatThrownBy(() -> - personalRetrospectiveService.deletePersonalRetrospective(meetingId, retrospectiveId)) + personalRetrospectiveService.deletePersonalRetrospective(meetingId)) .isInstanceOf(GlobalException.class) .hasFieldOrPropertyWithValue("errorCode", GlobalErrorCode.UNAUTHORIZED); @@ -1596,13 +1600,20 @@ void getPersonalRetrospective_success() { List.of(new PersonalRetrospectiveDetailResponse.FreeText("자유 서술 제목", "자유 서술 내용")) ); + Meeting meeting = Meeting.builder().id(meetingId).build(); + User user = User.builder().id(userId).build(); + PersonalMeetingRetrospective retrospective = PersonalMeetingRetrospective.builder() + .id(retrospectiveId) + .meeting(meeting) + .user(user) + .build(); + try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { securityUtilMock.when(SecurityUtil::getCurrentUserId).thenReturn(userId); doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - doNothing().when(retrospectiveValidator).validateRetrospective(retrospectiveId); - doNothing().when(retrospectiveValidator).validateRetrospectiveByUser(retrospectiveId, userId); + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)).thenReturn(retrospective); when(changedThoughtRepository.findByPersonalMeetingRetrospective(retrospectiveId)) .thenReturn(changedThoughts); when(othersPerspectiveRepository.findByPersonalMeetingRetrospective(retrospectiveId)) @@ -1614,7 +1625,7 @@ void getPersonalRetrospective_success() { // when PersonalRetrospectiveDetailResponse response = - personalRetrospectiveService.getPersonalRetrospective(meetingId, retrospectiveId); + personalRetrospectiveService.getPersonalRetrospective(meetingId); // then assertThat(response.retrospectiveId()).isEqualTo(retrospectiveId); @@ -1624,8 +1635,7 @@ void getPersonalRetrospective_success() { verify(meetingValidator).validateMeeting(meetingId); verify(meetingValidator).validateMeetingMember(meetingId, userId); - verify(retrospectiveValidator).validateRetrospective(retrospectiveId); - verify(retrospectiveValidator).validateRetrospectiveByUser(retrospectiveId, userId); + verify(retrospectiveValidator).getRetrospectiveByMeetingAndUser(meetingId, userId); verify(changedThoughtRepository).findByPersonalMeetingRetrospective(retrospectiveId); verify(othersPerspectiveRepository).findByPersonalMeetingRetrospective(retrospectiveId); verify(freeTextRepository).findByPersonalMeetingRetrospective_Id(retrospectiveId); @@ -1652,13 +1662,20 @@ void getPersonalRetrospective_withEmptyContent_success() { List.of() ); + Meeting meeting = Meeting.builder().id(meetingId).build(); + User user = User.builder().id(userId).build(); + PersonalMeetingRetrospective retrospective = PersonalMeetingRetrospective.builder() + .id(retrospectiveId) + .meeting(meeting) + .user(user) + .build(); + try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { securityUtilMock.when(SecurityUtil::getCurrentUserId).thenReturn(userId); doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - doNothing().when(retrospectiveValidator).validateRetrospective(retrospectiveId); - doNothing().when(retrospectiveValidator).validateRetrospectiveByUser(retrospectiveId, userId); + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)).thenReturn(retrospective); when(changedThoughtRepository.findByPersonalMeetingRetrospective(retrospectiveId)) .thenReturn(changedThoughts); when(othersPerspectiveRepository.findByPersonalMeetingRetrospective(retrospectiveId)) @@ -1670,7 +1687,7 @@ void getPersonalRetrospective_withEmptyContent_success() { // when PersonalRetrospectiveDetailResponse response = - personalRetrospectiveService.getPersonalRetrospective(meetingId, retrospectiveId); + personalRetrospectiveService.getPersonalRetrospective(meetingId); // then assertThat(response.retrospective().changedThoughts()).isEmpty(); @@ -1684,7 +1701,6 @@ void getPersonalRetrospective_withEmptyContent_success() { void getPersonalRetrospective_throwsWhenMeetingNotFound() { // given Long meetingId = 999L; - Long retrospectiveId = 100L; Long userId = 3L; try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { @@ -1695,7 +1711,7 @@ void getPersonalRetrospective_throwsWhenMeetingNotFound() { // when & then assertThatThrownBy(() -> - personalRetrospectiveService.getPersonalRetrospective(meetingId, retrospectiveId)) + personalRetrospectiveService.getPersonalRetrospective(meetingId)) .isInstanceOf(MeetingException.class) .hasFieldOrPropertyWithValue("errorCode", MeetingErrorCode.MEETING_NOT_FOUND); @@ -1708,7 +1724,6 @@ void getPersonalRetrospective_throwsWhenMeetingNotFound() { void getPersonalRetrospective_throwsWhenNotMeetingMember() { // given Long meetingId = 1L; - Long retrospectiveId = 100L; Long userId = 999L; try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { @@ -1720,7 +1735,7 @@ void getPersonalRetrospective_throwsWhenNotMeetingMember() { // when & then assertThatThrownBy(() -> - personalRetrospectiveService.getPersonalRetrospective(meetingId, retrospectiveId)) + personalRetrospectiveService.getPersonalRetrospective(meetingId)) .isInstanceOf(MeetingException.class) .hasFieldOrPropertyWithValue("errorCode", MeetingErrorCode.NOT_MEETING_MEMBER); @@ -1733,7 +1748,6 @@ void getPersonalRetrospective_throwsWhenNotMeetingMember() { void getPersonalRetrospective_throwsWhenRetrospectiveNotFound() { // given Long meetingId = 1L; - Long retrospectiveId = 999L; Long userId = 3L; try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { @@ -1741,12 +1755,12 @@ void getPersonalRetrospective_throwsWhenRetrospectiveNotFound() { doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - doThrow(new RetrospectiveException(RetrospectiveErrorCode.RETROSPECTIVE_NOT_FOUND)) - .when(retrospectiveValidator).validateRetrospective(retrospectiveId); + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)) + .thenThrow(new RetrospectiveException(RetrospectiveErrorCode.RETROSPECTIVE_NOT_FOUND)); // when & then assertThatThrownBy(() -> - personalRetrospectiveService.getPersonalRetrospective(meetingId, retrospectiveId)) + personalRetrospectiveService.getPersonalRetrospective(meetingId)) .isInstanceOf(RetrospectiveException.class) .hasFieldOrPropertyWithValue("errorCode", RetrospectiveErrorCode.RETROSPECTIVE_NOT_FOUND); @@ -1759,7 +1773,6 @@ void getPersonalRetrospective_throwsWhenRetrospectiveNotFound() { void getPersonalRetrospective_throwsWhenUnauthenticated() { // given Long meetingId = 1L; - Long retrospectiveId = 100L; try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { securityUtilMock.when(SecurityUtil::getCurrentUserId) @@ -1767,7 +1780,7 @@ void getPersonalRetrospective_throwsWhenUnauthenticated() { // when & then assertThatThrownBy(() -> - personalRetrospectiveService.getPersonalRetrospective(meetingId, retrospectiveId)) + personalRetrospectiveService.getPersonalRetrospective(meetingId)) .isInstanceOf(GlobalException.class) .hasFieldOrPropertyWithValue("errorCode", GlobalErrorCode.UNAUTHORIZED); @@ -1819,13 +1832,20 @@ void getPersonalRetrospective_withMultipleOthersPerspectives_success() { List.of() ); + Meeting meeting = Meeting.builder().id(meetingId).build(); + User user = User.builder().id(userId).build(); + PersonalMeetingRetrospective retrospective = PersonalMeetingRetrospective.builder() + .id(retrospectiveId) + .meeting(meeting) + .user(user) + .build(); + try (MockedStatic securityUtilMock = mockStatic(SecurityUtil.class)) { securityUtilMock.when(SecurityUtil::getCurrentUserId).thenReturn(userId); doNothing().when(meetingValidator).validateMeeting(meetingId); doNothing().when(meetingValidator).validateMeetingMember(meetingId, userId); - doNothing().when(retrospectiveValidator).validateRetrospective(retrospectiveId); - doNothing().when(retrospectiveValidator).validateRetrospectiveByUser(retrospectiveId, userId); + when(retrospectiveValidator.getRetrospectiveByMeetingAndUser(meetingId, userId)).thenReturn(retrospective); when(changedThoughtRepository.findByPersonalMeetingRetrospective(retrospectiveId)) .thenReturn(changedThoughts); when(othersPerspectiveRepository.findByPersonalMeetingRetrospective(retrospectiveId)) @@ -1837,7 +1857,7 @@ void getPersonalRetrospective_withMultipleOthersPerspectives_success() { // when PersonalRetrospectiveDetailResponse response = - personalRetrospectiveService.getPersonalRetrospective(meetingId, retrospectiveId); + personalRetrospectiveService.getPersonalRetrospective(meetingId); // then assertThat(response.retrospective().othersPerspectives()).hasSize(2);