From e93307519a3227c1e05e79d48e09fab71c6fbd76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Tue, 28 Nov 2023 00:01:25 +0900 Subject: [PATCH 01/14] =?UTF-8?q?refactor:=20=EC=8B=A0=EA=B3=A0=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=B0=98=ED=99=98=20DTO=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/presentation/AdminController.java | 22 ++++++---- .../presentation/dto/GroupReportHTTP.java | 38 +++++++++++++++++ .../presentation/dto/GroupReportList.java | 13 ------ .../report/presentation/dto/ReportList.java | 18 -------- .../presentation/dto/ReportListHTTP.java | 17 ++++++++ .../server/report/service/ReportService.java | 6 +-- .../report/service/dto/ReportListDto.java | 14 +++++++ .../presentation/AdminControllerTest.java | 41 ++++++++++--------- .../fixture/dto/GroupReportListFixture.java | 13 ------ .../report/service/ReportServiceTest.java | 4 +- 10 files changed, 109 insertions(+), 77 deletions(-) create mode 100644 src/main/java/coffeemeet/server/report/presentation/dto/GroupReportHTTP.java delete mode 100644 src/main/java/coffeemeet/server/report/presentation/dto/GroupReportList.java delete mode 100644 src/main/java/coffeemeet/server/report/presentation/dto/ReportList.java create mode 100644 src/main/java/coffeemeet/server/report/presentation/dto/ReportListHTTP.java create mode 100644 src/main/java/coffeemeet/server/report/service/dto/ReportListDto.java delete mode 100644 src/test/java/coffeemeet/server/common/fixture/dto/GroupReportListFixture.java diff --git a/src/main/java/coffeemeet/server/admin/presentation/AdminController.java b/src/main/java/coffeemeet/server/admin/presentation/AdminController.java index e1c38e35..4842c458 100644 --- a/src/main/java/coffeemeet/server/admin/presentation/AdminController.java +++ b/src/main/java/coffeemeet/server/admin/presentation/AdminController.java @@ -5,6 +5,7 @@ import coffeemeet.server.admin.presentation.dto.AdminCustomPage; import coffeemeet.server.admin.presentation.dto.AdminCustomSlice; import coffeemeet.server.admin.presentation.dto.AdminLoginHTTP; +import coffeemeet.server.report.presentation.dto.GroupReportHTTP; import coffeemeet.server.admin.presentation.dto.ReportDeletionHTTP; import coffeemeet.server.admin.presentation.dto.UserPunishmentHTTP; import coffeemeet.server.admin.service.AdminService; @@ -18,13 +19,13 @@ import coffeemeet.server.inquiry.service.dto.InquirySearchResponse; import coffeemeet.server.inquiry.service.dto.InquirySearchResponse.InquirySummary; import coffeemeet.server.report.presentation.dto.FindGroupReports; -import coffeemeet.server.report.presentation.dto.GroupReportList; import coffeemeet.server.report.presentation.dto.ReportDetailHTTP; -import coffeemeet.server.report.presentation.dto.ReportList; +import coffeemeet.server.report.presentation.dto.ReportListHTTP; +import coffeemeet.server.report.presentation.dto.ReportListHTTP.Response; import coffeemeet.server.report.service.ReportService; import coffeemeet.server.report.service.dto.GroupReportDto; import coffeemeet.server.report.service.dto.ReportDetailDto; -import coffeemeet.server.report.service.dto.ReportDto; +import coffeemeet.server.report.service.dto.ReportListDto; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import jakarta.validation.Valid; @@ -129,7 +130,7 @@ public ResponseEntity dismissReport( } @GetMapping("/reports") - public ResponseEntity> findAllReports( + public ResponseEntity> findAllReports( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @RequestParam(defaultValue = "0") Long lastReportId, @RequestParam(defaultValue = "10") int pageSize @@ -137,21 +138,24 @@ public ResponseEntity> findAllReports( if (adminId == null) { throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); } - ReportList allReports = reportService.findAllReports(lastReportId, pageSize); - return ResponseEntity.ok(AdminCustomSlice.of(allReports.contents(), allReports.hasNext())); + ReportListDto reportListDto = reportService.findAllReports(lastReportId, pageSize); + List responses = reportListDto.contents().stream() + .map(Response::from) + .toList(); + return ResponseEntity.ok(AdminCustomSlice.of(responses, reportListDto.hasNext())); } @GetMapping("/reports/group") - public ResponseEntity findReportByTargetIdAndChattingRoomId( + public ResponseEntity findReportByTargetIdAndChattingRoomId( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @ModelAttribute FindGroupReports findGroupReports ) { if (adminId == null) { throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); } - List response = reportService.findReportByTargetIdAndChattingRoomId( + List responses = reportService.findReportByTargetIdAndChattingRoomId( findGroupReports.targetedId(), findGroupReports.chattingRoomId()); - return ResponseEntity.ok(GroupReportList.from(response)); + return ResponseEntity.ok(GroupReportHTTP.Response.from(responses)); } @GetMapping("/reports/detail/{reportId}") diff --git a/src/main/java/coffeemeet/server/report/presentation/dto/GroupReportHTTP.java b/src/main/java/coffeemeet/server/report/presentation/dto/GroupReportHTTP.java new file mode 100644 index 00000000..ead3537f --- /dev/null +++ b/src/main/java/coffeemeet/server/report/presentation/dto/GroupReportHTTP.java @@ -0,0 +1,38 @@ +package coffeemeet.server.report.presentation.dto; + +import static lombok.AccessLevel.PRIVATE; + +import coffeemeet.server.report.service.dto.GroupReportDto; +import java.time.LocalDateTime; +import java.util.List; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = PRIVATE) +public final class GroupReportHTTP { + + public record GroupReport( + String reporterNickname, + Long reportId, + LocalDateTime createdAt + ) { + + public static GroupReport from(GroupReportDto response) { + return new GroupReport( + response.reporterNickname(), + response.reportId(), + response.createdAt() + ); + } + } + + public record Response(List groupReports) { + + public static Response from(List responses) { + List groupReportList = responses.stream() + .map(GroupReport::from) + .toList(); + return new Response(groupReportList); + } + } + +} diff --git a/src/main/java/coffeemeet/server/report/presentation/dto/GroupReportList.java b/src/main/java/coffeemeet/server/report/presentation/dto/GroupReportList.java deleted file mode 100644 index 164138bc..00000000 --- a/src/main/java/coffeemeet/server/report/presentation/dto/GroupReportList.java +++ /dev/null @@ -1,13 +0,0 @@ -package coffeemeet.server.report.presentation.dto; - -import coffeemeet.server.report.service.dto.GroupReportDto; -import java.util.List; - -public record GroupReportList(List reports) { - - public static GroupReportList from(List response) { - return new GroupReportList(response); - } - -} - diff --git a/src/main/java/coffeemeet/server/report/presentation/dto/ReportList.java b/src/main/java/coffeemeet/server/report/presentation/dto/ReportList.java deleted file mode 100644 index a417e2f6..00000000 --- a/src/main/java/coffeemeet/server/report/presentation/dto/ReportList.java +++ /dev/null @@ -1,18 +0,0 @@ -package coffeemeet.server.report.presentation.dto; - -import coffeemeet.server.report.service.dto.ReportDto; -import java.util.List; - -public record ReportList( - List contents, - boolean hasNext -) { - - public static ReportList of(List contents, boolean hasNext) { - return new ReportList( - contents, - hasNext - ); - } - -} diff --git a/src/main/java/coffeemeet/server/report/presentation/dto/ReportListHTTP.java b/src/main/java/coffeemeet/server/report/presentation/dto/ReportListHTTP.java new file mode 100644 index 00000000..11a43d7e --- /dev/null +++ b/src/main/java/coffeemeet/server/report/presentation/dto/ReportListHTTP.java @@ -0,0 +1,17 @@ +package coffeemeet.server.report.presentation.dto; + +import coffeemeet.server.report.service.dto.ReportDto; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ReportListHTTP { + + public record Response(ReportDto content) { + + public static Response from(ReportDto content) { + return new Response(content); + } + } + +} diff --git a/src/main/java/coffeemeet/server/report/service/ReportService.java b/src/main/java/coffeemeet/server/report/service/ReportService.java index 6ee5ee68..10df744e 100644 --- a/src/main/java/coffeemeet/server/report/service/ReportService.java +++ b/src/main/java/coffeemeet/server/report/service/ReportService.java @@ -9,10 +9,10 @@ import coffeemeet.server.report.domain.Report; import coffeemeet.server.report.implement.ReportCommand; import coffeemeet.server.report.implement.ReportQuery; -import coffeemeet.server.report.presentation.dto.ReportList; import coffeemeet.server.report.service.dto.GroupReportDto; import coffeemeet.server.report.service.dto.ReportDetailDto; import coffeemeet.server.report.service.dto.ReportDto; +import coffeemeet.server.report.service.dto.ReportListDto; import coffeemeet.server.user.domain.User; import coffeemeet.server.user.implement.UserQuery; import java.util.List; @@ -60,7 +60,7 @@ public ReportDetailDto findReportById(Long reportId) { return ReportDetailDto.of(report, reporter, targetUser); } - public ReportList findAllReports(Long lastReportId, int pageSize) { + public ReportListDto findAllReports(Long lastReportId, int pageSize) { List reports = reportQuery.getAllReports(lastReportId, pageSize); boolean hasNext = reports.size() >= pageSize; @@ -74,7 +74,7 @@ public ReportList findAllReports(Long lastReportId, int pageSize) { return ReportDto.of(targetUser, chattingRoom); }) .toList(); - return ReportList.of(responses, hasNext); + return ReportListDto.of(responses, hasNext); } public List findReportByTargetIdAndChattingRoomId(long targetId, diff --git a/src/main/java/coffeemeet/server/report/service/dto/ReportListDto.java b/src/main/java/coffeemeet/server/report/service/dto/ReportListDto.java new file mode 100644 index 00000000..f22c6654 --- /dev/null +++ b/src/main/java/coffeemeet/server/report/service/dto/ReportListDto.java @@ -0,0 +1,14 @@ +package coffeemeet.server.report.service.dto; + +import java.util.List; + +public record ReportListDto( + List contents, + boolean hasNext +) { + + public static ReportListDto of(List contents, boolean hasNext) { + return new ReportListDto(contents, hasNext); + } + +} diff --git a/src/test/java/coffeemeet/server/admin/presentation/AdminControllerTest.java b/src/test/java/coffeemeet/server/admin/presentation/AdminControllerTest.java index 8b13c7c8..1230bf8e 100644 --- a/src/test/java/coffeemeet/server/admin/presentation/AdminControllerTest.java +++ b/src/test/java/coffeemeet/server/admin/presentation/AdminControllerTest.java @@ -37,7 +37,6 @@ import coffeemeet.server.certification.service.dto.PendingCertificationPageDto; import coffeemeet.server.common.config.ControllerTestConfig; import coffeemeet.server.common.fixture.dto.GroupReportDtoFixture; -import coffeemeet.server.common.fixture.dto.GroupReportListFixture; import coffeemeet.server.common.fixture.dto.ReportDetailDtoFixture; import coffeemeet.server.common.fixture.dto.ReportDetailHTTPFixture; import coffeemeet.server.common.fixture.dto.ReportDtoFixture; @@ -48,13 +47,15 @@ import coffeemeet.server.inquiry.service.dto.InquiryDetailDto; import coffeemeet.server.inquiry.service.dto.InquirySearchResponse; import coffeemeet.server.inquiry.service.dto.InquirySearchResponse.InquirySummary; -import coffeemeet.server.report.presentation.dto.GroupReportList; +import coffeemeet.server.report.presentation.dto.GroupReportHTTP; +import coffeemeet.server.report.presentation.dto.ReportListHTTP; +import coffeemeet.server.report.presentation.dto.ReportListHTTP.Response; import coffeemeet.server.report.presentation.dto.ReportDetailHTTP; -import coffeemeet.server.report.presentation.dto.ReportList; import coffeemeet.server.report.service.ReportService; import coffeemeet.server.report.service.dto.GroupReportDto; import coffeemeet.server.report.service.dto.ReportDetailDto; import coffeemeet.server.report.service.dto.ReportDto; +import coffeemeet.server.report.service.dto.ReportListDto; import com.epages.restdocs.apispec.Schema; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -247,12 +248,14 @@ void findAllReportsTest() throws Exception { List reportResponses = List.of(response1, response2); boolean hasNext = true; - ReportList reportList = ReportList.of(reportResponses, hasNext); + ReportListDto reportListDto = ReportListDto.of(reportResponses, hasNext); + List responses = reportListDto.contents().stream() + .map(Response::from) + .toList(); + AdminCustomPage result = new AdminCustomPage<>(responses, + reportListDto.hasNext()); - AdminCustomPage result = new AdminCustomPage<>(reportList.contents(), - reportList.hasNext()); - - given(reportService.findAllReports(lastReportId, pageSize)).willReturn(reportList); + given(reportService.findAllReports(lastReportId, pageSize)).willReturn(reportListDto); // when, then mockMvc.perform(get("/api/v1/admins/reports") @@ -269,17 +272,17 @@ void findAllReportsTest() throws Exception { headerWithName("JSESSION").description("세션") ), responseFields( - fieldWithPath("contents").description("List of report details"), + fieldWithPath("contents").description("신고 조회 내역 리스트"), fieldWithPath("hasNext").type(JsonFieldType.BOOLEAN).description("다음 페이지 존재 여부"), - fieldWithPath("contents.[].targetedNickname").type(JsonFieldType.STRING) + fieldWithPath("contents.[].content.targetedNickname").type(JsonFieldType.STRING) .description("신고 대상 닉네임"), - fieldWithPath("contents.[].chattingRoomName").type(JsonFieldType.STRING) + fieldWithPath("contents.[].content.chattingRoomName").type(JsonFieldType.STRING) .description("신고 대상 채팅방 이름"), - fieldWithPath("contents.[].targetedId").type(JsonFieldType.NUMBER) + fieldWithPath("contents.[].content.targetedId").type(JsonFieldType.NUMBER) .description("신고 대상 아이디"), - fieldWithPath("contents.[].chattingRoomId").type(JsonFieldType.NUMBER) + fieldWithPath("contents.[].content.chattingRoomId").type(JsonFieldType.NUMBER) .description("신고 대상 채팅방 이름"), - fieldWithPath("contents.[].createdAt").type(JsonFieldType.STRING) + fieldWithPath("contents.[].content.createdAt").type(JsonFieldType.STRING) .description("신고 생성 날짜") ) )) @@ -293,7 +296,7 @@ void findReportByTargetIdAndChattingRoomIdTest() throws Exception { // given List response = List.of(GroupReportDtoFixture.targetReportDto(), GroupReportDtoFixture.targetReportDto()); - GroupReportList resultResponse = GroupReportListFixture.groupReportListResponse(response); + GroupReportHTTP.Response result = GroupReportHTTP.Response.from(response); given(reportService.findReportByTargetIdAndChattingRoomId(anyLong(), anyLong())).willReturn( response); @@ -318,16 +321,16 @@ void findReportByTargetIdAndChattingRoomIdTest() throws Exception { headerWithName("JSESSION").description("세션") ), responseFields( - fieldWithPath("reports.[].reporterNickname").type(JsonFieldType.STRING) + fieldWithPath("groupReports.[].reporterNickname").type(JsonFieldType.STRING) .description("신고자 닉네임"), - fieldWithPath("reports.[].reportId").type(JsonFieldType.NUMBER) + fieldWithPath("groupReports.[].reportId").type(JsonFieldType.NUMBER) .description("신고자 닉네임"), - fieldWithPath("reports.[].createdAt").type(JsonFieldType.STRING) + fieldWithPath("groupReports.[].createdAt").type(JsonFieldType.STRING) .description("신고 생성 날짜") ) )) .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(resultResponse))); + .andExpect(content().json(objectMapper.writeValueAsString(result))); } @Test diff --git a/src/test/java/coffeemeet/server/common/fixture/dto/GroupReportListFixture.java b/src/test/java/coffeemeet/server/common/fixture/dto/GroupReportListFixture.java deleted file mode 100644 index 2d87de53..00000000 --- a/src/test/java/coffeemeet/server/common/fixture/dto/GroupReportListFixture.java +++ /dev/null @@ -1,13 +0,0 @@ -package coffeemeet.server.common.fixture.dto; - -import coffeemeet.server.report.presentation.dto.GroupReportList; -import coffeemeet.server.report.service.dto.GroupReportDto; -import java.util.List; - -public class GroupReportListFixture { - - public static GroupReportList groupReportListResponse(List response) { - return new GroupReportList(response); - } - -} diff --git a/src/test/java/coffeemeet/server/report/service/ReportServiceTest.java b/src/test/java/coffeemeet/server/report/service/ReportServiceTest.java index 5ec220dd..0da35cdf 100644 --- a/src/test/java/coffeemeet/server/report/service/ReportServiceTest.java +++ b/src/test/java/coffeemeet/server/report/service/ReportServiceTest.java @@ -16,9 +16,9 @@ import coffeemeet.server.report.domain.Report; import coffeemeet.server.report.implement.ReportCommand; import coffeemeet.server.report.implement.ReportQuery; -import coffeemeet.server.report.presentation.dto.ReportList; import coffeemeet.server.report.service.dto.GroupReportDto; import coffeemeet.server.report.service.dto.ReportDetailDto; +import coffeemeet.server.report.service.dto.ReportListDto; import coffeemeet.server.user.domain.User; import coffeemeet.server.user.implement.UserQuery; import java.util.List; @@ -124,7 +124,7 @@ void findAllReportsTest() { given(chattingRoomQuery.getUserByIdSet(chattingRoomIds)).willReturn(Set.of(chattingRoom)); // when - ReportList responses = reportService.findAllReports(lastReportId, pageSize); + ReportListDto responses = reportService.findAllReports(lastReportId, pageSize); // then assertAll( From fea5beb89049e508ac59f35f772d32badf4deaf4 Mon Sep 17 00:00:00 2001 From: yumyeonghan Date: Tue, 28 Nov 2023 18:41:43 +0900 Subject: [PATCH 02/14] =?UTF-8?q?feat:=20existsBy=20=EC=9E=91=EC=84=B1=20?= =?UTF-8?q?=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 채팅방 유무 조회 로직 작성 --- .../current/implement/ChattingRoomQuery.java | 8 ++- .../implement/ChattingRoomQueryTest.java | 49 +++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/main/java/coffeemeet/server/chatting/current/implement/ChattingRoomQuery.java b/src/main/java/coffeemeet/server/chatting/current/implement/ChattingRoomQuery.java index 2d6cb1f5..86e9d05f 100644 --- a/src/main/java/coffeemeet/server/chatting/current/implement/ChattingRoomQuery.java +++ b/src/main/java/coffeemeet/server/chatting/current/implement/ChattingRoomQuery.java @@ -29,7 +29,7 @@ public ChattingRoom getChattingRoomById(Long roomId) { )); } - public void existsById(Long roomId) { + public void verifyChatRoomExistence(Long roomId) { if (!chattingRoomRepository.existsById(roomId)) { throw new NotFoundException( CHATTING_ROOM_NOT_FOUND, @@ -38,8 +38,12 @@ public void existsById(Long roomId) { } } - public Set getUserByIdSet(Set chattingRoomIds) { + public Set getChattingRoomsSetBy(Set chattingRoomIds) { return new HashSet<>(chattingRoomRepository.findByIdIn(chattingRoomIds)); } + public boolean existsBy(Long roomId) { + return chattingRoomRepository.existsById(roomId); + } + } diff --git a/src/test/java/coffeemeet/server/chatting/current/implement/ChattingRoomQueryTest.java b/src/test/java/coffeemeet/server/chatting/current/implement/ChattingRoomQueryTest.java index 16c328d9..1a6e920e 100644 --- a/src/test/java/coffeemeet/server/chatting/current/implement/ChattingRoomQueryTest.java +++ b/src/test/java/coffeemeet/server/chatting/current/implement/ChattingRoomQueryTest.java @@ -1,12 +1,18 @@ package coffeemeet.server.chatting.current.implement; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anySet; import static org.mockito.BDDMockito.given; import coffeemeet.server.chatting.current.domain.ChattingRoom; import coffeemeet.server.chatting.current.infrastructure.ChattingRoomRepository; +import coffeemeet.server.common.execption.NotFoundException; import coffeemeet.server.common.fixture.entity.ChattingFixture; import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -38,4 +44,47 @@ void getChattingRoomByIdTest() { assertThat(foundChattingRoom).isEqualTo(chattingRoom); } + @DisplayName("채팅방이 존재하지 않으면 예외가 발생할 수 있다.") + @Test + void verifyChatRoomExistenceTest() { + // given + Long roomId = 1L; + given(chattingRoomRepository.existsById(roomId)).willReturn(false); + + // when, then + assertThatThrownBy(() -> chattingRoomQuery.verifyChatRoomExistence(roomId)) + .isInstanceOf(NotFoundException.class); + } + + @DisplayName("채팅방 아이디 셋으로 채팅방을 셋을 조회할 수 있다.") + @Test + void getChattingRoomsSetByIdSetTest() { + // given + int size = 4; + Set chattingRooms = ChattingFixture.chattingRoom(size); + Set chattingRoomIdsSet = chattingRooms.stream().map(chattingRoom -> chattingRoom.getId()) + .collect(Collectors.toSet()); + given(chattingRoomRepository.findByIdIn(anySet())).willReturn(chattingRooms); + + // when + Set response = chattingRoomQuery.getChattingRoomsSetBy(chattingRoomIdsSet); + + // then + assertThat(response).isEqualTo(chattingRooms); + } + + @DisplayName("채팅방 존재를 확인할 수 있다.") + @Test + void existsByRoomIdTest() { + // given + Long roomId = 1L; + given(chattingRoomRepository.existsById(any())).willReturn(true); + + // when + boolean response = chattingRoomQuery.existsBy(roomId); + + // then + assertThat(response).isTrue(); + } + } From 0bd48fecf578ac01213a7ac76746aaedc11d7055 Mon Sep 17 00:00:00 2001 From: yumyeonghan Date: Tue, 28 Nov 2023 18:42:28 +0900 Subject: [PATCH 03/14] =?UTF-8?q?feat:=20checkChattingRoomStatus=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 채팅방 상태 조회 로직 작성 --- .../current/service/ChattingRoomService.java | 4 ++++ .../service/ChattingRoomServiceTest.java | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/main/java/coffeemeet/server/chatting/current/service/ChattingRoomService.java b/src/main/java/coffeemeet/server/chatting/current/service/ChattingRoomService.java index 6bb9005a..6e9add89 100644 --- a/src/main/java/coffeemeet/server/chatting/current/service/ChattingRoomService.java +++ b/src/main/java/coffeemeet/server/chatting/current/service/ChattingRoomService.java @@ -5,6 +5,7 @@ import coffeemeet.server.chatting.current.implement.ChattingMessageQuery; import coffeemeet.server.chatting.current.implement.ChattingRoomCommand; import coffeemeet.server.chatting.current.implement.ChattingRoomQuery; +import coffeemeet.server.chatting.current.service.dto.ChatRoomStatusDto; import coffeemeet.server.chatting.current.service.dto.ChattingDto; import coffeemeet.server.chatting.current.service.dto.ChattingDto.Response; import coffeemeet.server.chatting.history.domain.ChattingMessageHistory; @@ -83,4 +84,7 @@ private void updateUserStatusToIdle(List users) { users.forEach(User::setIdleStatus); } + public ChatRoomStatusDto checkChattingRoomStatus(Long roomId) { + return ChatRoomStatusDto.from(chattingRoomQuery.existsBy(roomId)); + } } diff --git a/src/test/java/coffeemeet/server/chatting/current/service/ChattingRoomServiceTest.java b/src/test/java/coffeemeet/server/chatting/current/service/ChattingRoomServiceTest.java index c89296e4..7b49d2df 100644 --- a/src/test/java/coffeemeet/server/chatting/current/service/ChattingRoomServiceTest.java +++ b/src/test/java/coffeemeet/server/chatting/current/service/ChattingRoomServiceTest.java @@ -13,6 +13,7 @@ import coffeemeet.server.chatting.current.implement.ChattingMessageQuery; import coffeemeet.server.chatting.current.implement.ChattingRoomCommand; import coffeemeet.server.chatting.current.implement.ChattingRoomQuery; +import coffeemeet.server.chatting.current.service.dto.ChatRoomStatusDto; import coffeemeet.server.chatting.current.service.dto.ChattingDto.Response; import coffeemeet.server.chatting.history.domain.ChattingRoomHistory; import coffeemeet.server.chatting.history.implement.ChattingMessageHistoryCommand; @@ -127,4 +128,20 @@ void deleteChattingRoomTest() { then(fcmNotificationSender).should(only()).sendMultiNotifications(anySet(), any()); } + @DisplayName("채팅방의 유무 상태를 조회할 수 있다.") + @Test + void checkChattingRoomStatusTest() { + // given + Long roomId = 1L; + ChatRoomStatusDto chatRoomStatusDto = ChattingFixture.chatRoomStatusDto(); + + given(chattingRoomQuery.existsBy(any())).willReturn(chatRoomStatusDto.isExisted()); + + // when + ChatRoomStatusDto response = chattingRoomService.checkChattingRoomStatus(roomId); + + // then + assertThat(response).isEqualTo(chatRoomStatusDto); + } + } From 5cdabe30dd35197e4a91c3153205833e4a7f2cd5 Mon Sep 17 00:00:00 2001 From: yumyeonghan Date: Tue, 28 Nov 2023 18:43:09 +0900 Subject: [PATCH 04/14] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20?= =?UTF-8?q?=EC=9C=A0=EB=AC=B4=20=EC=A1=B0=ED=9A=8C=20API=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/ChattingRoomController.java | 8 +++++++ .../presentation/dto/ChatRoomStatusHTTP.java | 21 +++++++++++++++++++ .../service/dto/ChatRoomStatusDto.java | 9 ++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/main/java/coffeemeet/server/chatting/current/presentation/dto/ChatRoomStatusHTTP.java create mode 100644 src/main/java/coffeemeet/server/chatting/current/service/dto/ChatRoomStatusDto.java diff --git a/src/main/java/coffeemeet/server/chatting/current/presentation/ChattingRoomController.java b/src/main/java/coffeemeet/server/chatting/current/presentation/ChattingRoomController.java index 3761557a..49970e3a 100644 --- a/src/main/java/coffeemeet/server/chatting/current/presentation/ChattingRoomController.java +++ b/src/main/java/coffeemeet/server/chatting/current/presentation/ChattingRoomController.java @@ -1,7 +1,9 @@ package coffeemeet.server.chatting.current.presentation; +import coffeemeet.server.chatting.current.presentation.dto.ChatRoomStatusHTTP; import coffeemeet.server.chatting.current.presentation.dto.ChatsHTTP; import coffeemeet.server.chatting.current.service.ChattingRoomService; +import coffeemeet.server.chatting.current.service.dto.ChatRoomStatusDto; import coffeemeet.server.chatting.current.service.dto.ChattingDto.Response; import java.util.List; import lombok.RequiredArgsConstructor; @@ -35,4 +37,10 @@ public ResponseEntity exitChattingRoom(@PathVariable Long roomId) { return ResponseEntity.ok().build(); } + @GetMapping("/{roomId}/exist") + public ResponseEntity checkChattingRoom(@PathVariable Long roomId) { + ChatRoomStatusDto chatRoomStatusDto = chattingRoomService.checkChattingRoomStatus(roomId); + return ResponseEntity.ok(ChatRoomStatusHTTP.Response.from(chatRoomStatusDto)); + } + } diff --git a/src/main/java/coffeemeet/server/chatting/current/presentation/dto/ChatRoomStatusHTTP.java b/src/main/java/coffeemeet/server/chatting/current/presentation/dto/ChatRoomStatusHTTP.java new file mode 100644 index 00000000..83ab9b08 --- /dev/null +++ b/src/main/java/coffeemeet/server/chatting/current/presentation/dto/ChatRoomStatusHTTP.java @@ -0,0 +1,21 @@ +package coffeemeet.server.chatting.current.presentation.dto; + +import static lombok.AccessLevel.PRIVATE; + +import coffeemeet.server.chatting.current.service.dto.ChatRoomStatusDto; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = PRIVATE) +public final class ChatRoomStatusHTTP { + + public record Response( + boolean isExisted + ) { + + public static ChatRoomStatusHTTP.Response from(ChatRoomStatusDto chatRoomStatusDto) { + return new Response(chatRoomStatusDto.isExisted()); + } + + } + +} diff --git a/src/main/java/coffeemeet/server/chatting/current/service/dto/ChatRoomStatusDto.java b/src/main/java/coffeemeet/server/chatting/current/service/dto/ChatRoomStatusDto.java new file mode 100644 index 00000000..bd0d307e --- /dev/null +++ b/src/main/java/coffeemeet/server/chatting/current/service/dto/ChatRoomStatusDto.java @@ -0,0 +1,9 @@ +package coffeemeet.server.chatting.current.service.dto; + +public record ChatRoomStatusDto(boolean isExisted) { + + public static ChatRoomStatusDto from(boolean isExisted) { + return new ChatRoomStatusDto(isExisted); + } + +} From 96ef7548b4ecc32180011375648f888f954a22ee Mon Sep 17 00:00:00 2001 From: yumyeonghan Date: Tue, 28 Nov 2023 18:43:26 +0900 Subject: [PATCH 05/14] =?UTF-8?q?test:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20?= =?UTF-8?q?=EC=9C=A0=EB=AC=B4=20=EC=A1=B0=ED=9A=8C=20API=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ChattingRoomControllerTest.java | 31 +++++++++++++++++++ .../fixture/entity/ChattingFixture.java | 12 +++++++ 2 files changed, 43 insertions(+) diff --git a/src/test/java/coffeemeet/server/chatting/current/presentation/ChattingRoomControllerTest.java b/src/test/java/coffeemeet/server/chatting/current/presentation/ChattingRoomControllerTest.java index ae6a1db7..9fdb3d02 100644 --- a/src/test/java/coffeemeet/server/chatting/current/presentation/ChattingRoomControllerTest.java +++ b/src/test/java/coffeemeet/server/chatting/current/presentation/ChattingRoomControllerTest.java @@ -18,9 +18,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import coffeemeet.server.chatting.current.presentation.dto.ChatRoomStatusHTTP; import coffeemeet.server.chatting.current.presentation.dto.ChatsHTTP; import coffeemeet.server.chatting.current.presentation.dto.ChatsHTTP.Chat; import coffeemeet.server.chatting.current.service.ChattingRoomService; +import coffeemeet.server.chatting.current.service.dto.ChatRoomStatusDto; import coffeemeet.server.chatting.current.service.dto.ChattingDto.Response; import coffeemeet.server.common.config.ControllerTestConfig; import coffeemeet.server.common.fixture.entity.ChattingFixture; @@ -111,4 +113,33 @@ void exitChattingRoomTest() throws Exception { .andExpect(status().isOk()); } + @DisplayName("채팅방의 상태를 체크할 수 있다.") + @Test + void checkChattingRoomTest() throws Exception { + // given + Long userId = 1L; + Long roomId = 1L; + ChatRoomStatusDto chatRoomStatusDto = ChattingFixture.chatRoomStatusDto(); + ChatRoomStatusHTTP.Response response = ChattingFixture.chatRoomStatusHTTPResponse( + chatRoomStatusDto); + + given(jwtTokenProvider.extractUserId(TOKEN)).willReturn(userId); + given(chattingRoomService.checkChattingRoomStatus(roomId)).willReturn(chatRoomStatusDto); + + // when, then + mockMvc.perform(get("/api/v1/chatting/rooms/{roomId}/exist", roomId) + .header("Authorization", TOKEN) + ) + .andDo(document("check-chatting-room-status", + resourceDetails().tag("채팅방").description("채팅방 상태 확인"), + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + requestHeaders( + headerWithName("Authorization").description("토큰") + ) + ) + ) + .andExpect(content().string(objectMapper.writeValueAsString(response))); + } + } diff --git a/src/test/java/coffeemeet/server/common/fixture/entity/ChattingFixture.java b/src/test/java/coffeemeet/server/common/fixture/entity/ChattingFixture.java index 45c64cab..1b6b4879 100644 --- a/src/test/java/coffeemeet/server/common/fixture/entity/ChattingFixture.java +++ b/src/test/java/coffeemeet/server/common/fixture/entity/ChattingFixture.java @@ -5,8 +5,10 @@ import coffeemeet.server.chatting.current.domain.ChattingMessage; import coffeemeet.server.chatting.current.domain.ChattingRoom; import coffeemeet.server.chatting.current.domain.ChattingSession; +import coffeemeet.server.chatting.current.presentation.dto.ChatRoomStatusHTTP; import coffeemeet.server.chatting.current.presentation.dto.ChatsHTTP; import coffeemeet.server.chatting.current.presentation.dto.ChatsHTTP.Chat; +import coffeemeet.server.chatting.current.service.dto.ChatRoomStatusDto; import coffeemeet.server.chatting.current.service.dto.ChattingDto; import coffeemeet.server.chatting.history.domain.ChattingMessageHistory; import coffeemeet.server.chatting.history.domain.ChattingRoomHistory; @@ -128,4 +130,14 @@ public static ChattingSession chattingSession() { return Instancio.create(ChattingSession.class); } + public static ChatRoomStatusDto chatRoomStatusDto() { + return Instancio.of(ChatRoomStatusDto.class) + .create(); + } + + public static ChatRoomStatusHTTP.Response chatRoomStatusHTTPResponse( + ChatRoomStatusDto chatRoomStatusDto) { + return ChatRoomStatusHTTP.Response.from(chatRoomStatusDto); + } + } From 691da66b7695ef15161f7e1cc0a56ea5d5225baa Mon Sep 17 00:00:00 2001 From: yumyeonghan Date: Tue, 28 Nov 2023 18:43:46 +0900 Subject: [PATCH 06/14] refactor: import optimize --- .../server/common/implement/FCMNotificationSender.java | 4 ++-- .../java/coffeemeet/server/report/service/ReportService.java | 4 ++-- .../coffeemeet/server/report/service/ReportServiceTest.java | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/coffeemeet/server/common/implement/FCMNotificationSender.java b/src/main/java/coffeemeet/server/common/implement/FCMNotificationSender.java index 157cf3cd..caba71b6 100644 --- a/src/main/java/coffeemeet/server/common/implement/FCMNotificationSender.java +++ b/src/main/java/coffeemeet/server/common/implement/FCMNotificationSender.java @@ -47,7 +47,7 @@ public void sendNotification(NotificationInfo notificationInfo, String content) public void sendMultiNotifications(Set notificationInfos, String content) { Set tokens = convertNotificationInfoToToken(notificationInfos); - if(tokens.isEmpty()) { + if (tokens.isEmpty()) { return; } @@ -65,7 +65,7 @@ public void sendMultiNotifications(Set notificationInfos, Stri public void sendMultiNotificationsWithData(Set notificationInfos, String content, String key, String value) { Set tokens = convertNotificationInfoToToken(notificationInfos); - if(tokens.isEmpty()) { + if (tokens.isEmpty()) { return; } diff --git a/src/main/java/coffeemeet/server/report/service/ReportService.java b/src/main/java/coffeemeet/server/report/service/ReportService.java index 921637c7..cc285ac6 100644 --- a/src/main/java/coffeemeet/server/report/service/ReportService.java +++ b/src/main/java/coffeemeet/server/report/service/ReportService.java @@ -91,7 +91,7 @@ private void checkChattingRoomExists(long reporterId, long chattingRoomId) { boolean isChattingHistoryExists = false; try { - chattingRoomQuery.existsById(chattingRoomId); + chattingRoomQuery.verifyChatRoomExistence(chattingRoomId); isChattingRoomExists = true; } catch (NotFoundException e) { isChattingHistoryExists = userChattingHistoryQuery.existsByUserId(reporterId); @@ -108,7 +108,7 @@ private Map getChattingRooms(List allReports) { Set chattingRoomIds = allReports.stream() .map(Report::getChattingRoomId) .collect(Collectors.toSet()); - Set chattingRooms = chattingRoomQuery.getUserByIdSet(chattingRoomIds); + Set chattingRooms = chattingRoomQuery.getChattingRoomsSetBy(chattingRoomIds); return chattingRooms.stream() .collect(Collectors.toMap(ChattingRoom::getId, Function.identity())); } diff --git a/src/test/java/coffeemeet/server/report/service/ReportServiceTest.java b/src/test/java/coffeemeet/server/report/service/ReportServiceTest.java index 5ec220dd..f498f7c9 100644 --- a/src/test/java/coffeemeet/server/report/service/ReportServiceTest.java +++ b/src/test/java/coffeemeet/server/report/service/ReportServiceTest.java @@ -57,7 +57,7 @@ void reportUserTest() { Long reporterId = report.getReporterId(); willDoNothing().given(reportQuery).hasDuplicatedReport(anyLong(), anyLong(), anyLong()); - willDoNothing().given(chattingRoomQuery).existsById(anyLong()); + willDoNothing().given(chattingRoomQuery).verifyChatRoomExistence(anyLong()); willDoNothing().given(reportCommand).createReport(any(Report.class)); // when @@ -121,7 +121,8 @@ void findAllReportsTest() { given(userQuery.getUsersByIdSet(userIds)).willReturn(Set.of(targetUser)); Set chattingRoomIds = Set.of(chattingRoomId); - given(chattingRoomQuery.getUserByIdSet(chattingRoomIds)).willReturn(Set.of(chattingRoom)); + given(chattingRoomQuery.getChattingRoomsSetBy(chattingRoomIds)).willReturn( + Set.of(chattingRoom)); // when ReportList responses = reportService.findAllReports(lastReportId, pageSize); From eebf7245178935f3e2429ce03aeb0e24aa07fce1 Mon Sep 17 00:00:00 2001 From: yumyeonghan Date: Thu, 30 Nov 2023 01:33:46 +0900 Subject: [PATCH 07/14] =?UTF-8?q?refactor:=20=ED=94=84=EB=A1=9C=ED=95=84?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=EC=8B=9C,=20=ED=98=84=EC=9E=AC=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=EA=B0=80=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=EA=B0=80=20=EC=95=84=EB=8B=90?= =?UTF-8?q?=EB=95=8C=EB=A7=8C=20=EC=82=AD=EC=A0=9C=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/coffeemeet/server/user/service/UserService.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/coffeemeet/server/user/service/UserService.java b/src/main/java/coffeemeet/server/user/service/UserService.java index 023bbcdd..8bb97de9 100644 --- a/src/main/java/coffeemeet/server/user/service/UserService.java +++ b/src/main/java/coffeemeet/server/user/service/UserService.java @@ -2,6 +2,7 @@ import static coffeemeet.server.common.domain.KeyType.PROFILE_IMAGE; import static coffeemeet.server.common.execption.GlobalErrorCode.BAD_REQUEST_ERROR; +import static coffeemeet.server.oauth.utils.constant.OAuthConstant.DEFAULT_IMAGE_URL; import coffeemeet.server.auth.domain.AuthTokens; import coffeemeet.server.auth.domain.AuthTokensGenerator; @@ -170,9 +171,11 @@ private UserStatusDto handleReportedUser(User user) { } private void deleteCurrentProfileImage(String profileImageUrl) { - String currentKey = mediaManager.extractKey(profileImageUrl, - PROFILE_IMAGE); - mediaManager.delete(currentKey); + if (!profileImageUrl.equals(DEFAULT_IMAGE_URL)) { + String currentKey = mediaManager.extractKey(profileImageUrl, + PROFILE_IMAGE); + mediaManager.delete(currentKey); + } } } From 4acbc0b0f2b9022a60e6a423809d3252df745a08 Mon Sep 17 00:00:00 2001 From: sangminnim Date: Thu, 30 Nov 2023 05:23:32 +0900 Subject: [PATCH 08/14] =?UTF-8?q?refactor:=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=EB=B3=80=EA=B2=BD=20=EC=8B=9C=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../advice/GlobalExceptionHandler.java | 8 ++++++++ .../java/coffeemeet/server/user/domain/User.java | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/coffeemeet/server/common/presentation/advice/GlobalExceptionHandler.java b/src/main/java/coffeemeet/server/common/presentation/advice/GlobalExceptionHandler.java index 0d6b0554..edbde9f4 100644 --- a/src/main/java/coffeemeet/server/common/presentation/advice/GlobalExceptionHandler.java +++ b/src/main/java/coffeemeet/server/common/presentation/advice/GlobalExceptionHandler.java @@ -1,5 +1,6 @@ package coffeemeet.server.common.presentation.advice; +import coffeemeet.server.common.execption.BadRequestException; import coffeemeet.server.common.execption.DataLengthExceededException; import coffeemeet.server.common.execption.GlobalErrorCode; import coffeemeet.server.common.execption.InvalidAuthException; @@ -59,6 +60,13 @@ public ResponseEntity handleException(MissMatchException exceptio .body(ErrorResponse.of(exception.getErrorCode())); } + @ExceptionHandler(BadRequestException.class) + public ResponseEntity handleException(BadRequestException exception) { + log.info(exception.getMessage(), exception); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(ErrorResponse.of(exception.getErrorCode())); + } + @ExceptionHandler(NotFoundException.class) public ResponseEntity handleException(NotFoundException exception) { log.info(exception.getMessage(), exception); diff --git a/src/main/java/coffeemeet/server/user/domain/User.java b/src/main/java/coffeemeet/server/user/domain/User.java index 6b11f048..b20af9cb 100644 --- a/src/main/java/coffeemeet/server/user/domain/User.java +++ b/src/main/java/coffeemeet/server/user/domain/User.java @@ -1,5 +1,6 @@ package coffeemeet.server.user.domain; +import static coffeemeet.server.common.execption.GlobalErrorCode.BAD_REQUEST_ERROR; import static coffeemeet.server.user.domain.UserStatus.CHATTING_CONNECTED; import static coffeemeet.server.user.domain.UserStatus.CHATTING_UNCONNECTED; import static coffeemeet.server.user.domain.UserStatus.IDLE; @@ -8,6 +9,7 @@ import coffeemeet.server.chatting.current.domain.ChattingRoom; import coffeemeet.server.common.domain.AdvancedBaseEntity; +import coffeemeet.server.common.execption.BadRequestException; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; @@ -35,6 +37,8 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class User extends AdvancedBaseEntity { + public static final String INVALID_USER_STATUS = "올바르지 않은 유저 상태입니다."; + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -92,6 +96,9 @@ public void updateNotificationInfo(@NonNull NotificationInfo newNotificationInfo } public void completeMatching(ChattingRoom chattingRoom) { + if (this.userStatus != MATCHING) { + throw new BadRequestException(BAD_REQUEST_ERROR, INVALID_USER_STATUS); + } this.userStatus = CHATTING_UNCONNECTED; this.chattingRoom = chattingRoom; } @@ -101,10 +108,16 @@ public void deleteChattingRoom() { } public void enterChattingRoom() { + if (this.userStatus != CHATTING_UNCONNECTED) { + throw new BadRequestException(BAD_REQUEST_ERROR, INVALID_USER_STATUS); + } this.userStatus = CHATTING_CONNECTED; } public void exitChattingRoom() { + if (this.userStatus != CHATTING_CONNECTED) { + throw new BadRequestException(BAD_REQUEST_ERROR, INVALID_USER_STATUS); + } this.userStatus = CHATTING_UNCONNECTED; } @@ -118,6 +131,9 @@ public void punished() { } public void matching() { + if (this.userStatus != IDLE) { + throw new BadRequestException(BAD_REQUEST_ERROR, INVALID_USER_STATUS); + } this.userStatus = MATCHING; } From 599a9a734ac14f1a066b1b444992add9a9d19849 Mon Sep 17 00:00:00 2001 From: sangminnim Date: Thu, 30 Nov 2023 05:29:58 +0900 Subject: [PATCH 09/14] =?UTF-8?q?test:=20=EC=9C=A0=EC=A0=80=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EB=B3=80=EA=B2=BD=20=EC=8B=9C=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coffeemeet/server/user/implement/UserCommandTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/coffeemeet/server/user/implement/UserCommandTest.java b/src/test/java/coffeemeet/server/user/implement/UserCommandTest.java index 59926192..809ddd65 100644 --- a/src/test/java/coffeemeet/server/user/implement/UserCommandTest.java +++ b/src/test/java/coffeemeet/server/user/implement/UserCommandTest.java @@ -103,7 +103,7 @@ void assignUsersToChattingRoomTest() { // given Set userIds = Set.of(1L, 2L); ChattingRoom chattingRoom = new ChattingRoom(); - Set users = Set.of(user(), user()); + Set users = Set.of(user(MATCHING), user(MATCHING)); given(userQuery.getUsersByIdSet(userIds)).willReturn(users); // when @@ -147,7 +147,7 @@ void unsubscribeNotification() { @DisplayName("유저 상태를 채팅방 연결로 변경할 수 있다.") void enterToChattingRoomTest() { // given - User user = user(); + User user = user(CHATTING_UNCONNECTED); given(userQuery.getUserById(user.getId())).willReturn(user); @@ -162,7 +162,7 @@ void enterToChattingRoomTest() { @DisplayName("유저 상태를 채팅방 연결 해제로 변경할 수 있다.") void exitChattingRoomTest() { // given - User user = user(); + User user = user(CHATTING_CONNECTED); given(userQuery.getUserById(user.getId())).willReturn(user); @@ -193,7 +193,7 @@ void setToIdleTest() { @DisplayName("유저 상태를 매칭 중으로 변경할 수 있다.") void setToMatchingTest() { // given - User user = user(); + User user = user(IDLE); given(userQuery.getUserById(user.getId())).willReturn(user); From 341e4b8fa9d29e78a49b51f70a94f0f2cb03111d Mon Sep 17 00:00:00 2001 From: sangminnim Date: Thu, 30 Nov 2023 06:30:24 +0900 Subject: [PATCH 10/14] =?UTF-8?q?refactor:=20=EC=96=B4=EB=93=9C=EB=AF=BC?= =?UTF-8?q?=20=EC=84=B8=EC=85=98=20=EA=B2=80=EC=A6=9D=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/presentation/AdminController.java | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/main/java/coffeemeet/server/admin/presentation/AdminController.java b/src/main/java/coffeemeet/server/admin/presentation/AdminController.java index 4842c458..2d6a5ff1 100644 --- a/src/main/java/coffeemeet/server/admin/presentation/AdminController.java +++ b/src/main/java/coffeemeet/server/admin/presentation/AdminController.java @@ -86,9 +86,9 @@ public ResponseEntity logout( public ResponseEntity approveCertification( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @PathVariable Long certificationId) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } adminService.approveCertification(certificationId); return ResponseEntity.ok().build(); } @@ -97,9 +97,9 @@ public ResponseEntity approveCertification( public ResponseEntity rejectCertification( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @PathVariable Long certificationId) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } adminService.rejectCertification(certificationId); return ResponseEntity.ok().build(); } @@ -110,9 +110,9 @@ public ResponseEntity assignReportPenalty( @PathVariable Long targetedId, @Valid @RequestBody UserPunishmentHTTP.Request request ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } adminService.punishUser(targetedId, request.reportIds()); return ResponseEntity.ok().build(); } @@ -122,9 +122,9 @@ public ResponseEntity dismissReport( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @Valid @RequestBody ReportDeletionHTTP.Request request ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } adminService.dismissReport(request.reportIds()); return ResponseEntity.ok().build(); } @@ -135,9 +135,9 @@ public ResponseEntity> findAllReports( @RequestParam(defaultValue = "0") Long lastReportId, @RequestParam(defaultValue = "10") int pageSize ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } ReportListDto reportListDto = reportService.findAllReports(lastReportId, pageSize); List responses = reportListDto.contents().stream() .map(Response::from) @@ -150,9 +150,9 @@ public ResponseEntity findReportByTargetIdAndChattingR @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @ModelAttribute FindGroupReports findGroupReports ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } List responses = reportService.findReportByTargetIdAndChattingRoomId( findGroupReports.targetedId(), findGroupReports.chattingRoomId()); return ResponseEntity.ok(GroupReportHTTP.Response.from(responses)); @@ -163,9 +163,9 @@ public ResponseEntity findReport( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @PathVariable Long reportId ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } ReportDetailDto response = reportService.findReportById(reportId); return ResponseEntity.ok(ReportDetailHTTP.Response.from(response)); } @@ -175,9 +175,9 @@ public ResponseEntity> searchInquiries( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @RequestParam(defaultValue = "0") Long lastInquiryId, @RequestParam(defaultValue = "10") int pageSize) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } InquirySearchResponse inquiries = inquiryService.searchInquiries(lastInquiryId, pageSize); return ResponseEntity.ok(AdminCustomSlice.of(inquiries.contents(), inquiries.hasNext())); } @@ -187,9 +187,9 @@ public ResponseEntity viewInquiry( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @PathVariable Long inquiryId ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } InquiryDetailDto response = inquiryService.findInquiryBy(inquiryId); return ResponseEntity.ok(InquiryDetailHTTP.Response.from(response)); } @@ -198,9 +198,9 @@ public ResponseEntity viewInquiry( public ResponseEntity checkInquiry( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @PathVariable Long inquiryId) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } adminService.checkInquiry(inquiryId); return ResponseEntity.ok().build(); } @@ -212,9 +212,9 @@ public ResponseEntity> getPendingCertifica @RequestParam(defaultValue = "0") int offset, @RequestParam(defaultValue = "10") int size ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } int pageNumber = offset / size; Pageable pageable = PageRequest.of(pageNumber, size); From 4159335194809b614fda699250033234e7f268ad Mon Sep 17 00:00:00 2001 From: sangminnim Date: Thu, 30 Nov 2023 14:02:41 +0900 Subject: [PATCH 11/14] =?UTF-8?q?style:=20=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/admin/presentation/AdminController.java | 5 +---- .../server/admin/presentation/AdminControllerTest.java | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/coffeemeet/server/admin/presentation/AdminController.java b/src/main/java/coffeemeet/server/admin/presentation/AdminController.java index 2d6a5ff1..dd6fdb7f 100644 --- a/src/main/java/coffeemeet/server/admin/presentation/AdminController.java +++ b/src/main/java/coffeemeet/server/admin/presentation/AdminController.java @@ -1,24 +1,21 @@ package coffeemeet.server.admin.presentation; -import static coffeemeet.server.admin.exception.AdminErrorCode.NOT_AUTHORIZED; - import coffeemeet.server.admin.presentation.dto.AdminCustomPage; import coffeemeet.server.admin.presentation.dto.AdminCustomSlice; import coffeemeet.server.admin.presentation.dto.AdminLoginHTTP; -import coffeemeet.server.report.presentation.dto.GroupReportHTTP; import coffeemeet.server.admin.presentation.dto.ReportDeletionHTTP; import coffeemeet.server.admin.presentation.dto.UserPunishmentHTTP; import coffeemeet.server.admin.service.AdminService; import coffeemeet.server.certification.service.CertificationService; import coffeemeet.server.certification.service.dto.PendingCertification; import coffeemeet.server.certification.service.dto.PendingCertificationPageDto; -import coffeemeet.server.common.execption.InvalidAuthException; import coffeemeet.server.inquiry.presentation.dto.InquiryDetailHTTP; import coffeemeet.server.inquiry.service.InquiryService; import coffeemeet.server.inquiry.service.dto.InquiryDetailDto; import coffeemeet.server.inquiry.service.dto.InquirySearchResponse; import coffeemeet.server.inquiry.service.dto.InquirySearchResponse.InquirySummary; import coffeemeet.server.report.presentation.dto.FindGroupReports; +import coffeemeet.server.report.presentation.dto.GroupReportHTTP; import coffeemeet.server.report.presentation.dto.ReportDetailHTTP; import coffeemeet.server.report.presentation.dto.ReportListHTTP; import coffeemeet.server.report.presentation.dto.ReportListHTTP.Response; diff --git a/src/test/java/coffeemeet/server/admin/presentation/AdminControllerTest.java b/src/test/java/coffeemeet/server/admin/presentation/AdminControllerTest.java index 18ae3bd9..aad7dbfe 100644 --- a/src/test/java/coffeemeet/server/admin/presentation/AdminControllerTest.java +++ b/src/test/java/coffeemeet/server/admin/presentation/AdminControllerTest.java @@ -48,9 +48,9 @@ import coffeemeet.server.inquiry.service.dto.InquirySearchResponse; import coffeemeet.server.inquiry.service.dto.InquirySearchResponse.InquirySummary; import coffeemeet.server.report.presentation.dto.GroupReportHTTP; +import coffeemeet.server.report.presentation.dto.ReportDetailHTTP; import coffeemeet.server.report.presentation.dto.ReportListHTTP; import coffeemeet.server.report.presentation.dto.ReportListHTTP.Response; -import coffeemeet.server.report.presentation.dto.ReportDetailHTTP; import coffeemeet.server.report.service.ReportService; import coffeemeet.server.report.service.dto.GroupReportDto; import coffeemeet.server.report.service.dto.ReportDetailDto; From da370d0ab347114b1a3b9757c39713712f90a62a Mon Sep 17 00:00:00 2001 From: sangminnim Date: Thu, 30 Nov 2023 14:43:18 +0900 Subject: [PATCH 12/14] =?UTF-8?q?test:=20Fixture=20=EC=88=98=EC=A0=95,=20U?= =?UTF-8?q?ser=20=EC=83=81=ED=83=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../concurrency/ChattingMessageServiceConcurrencyTest.java | 4 +++- .../coffeemeet/server/common/fixture/entity/UserFixture.java | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/coffeemeet/server/chatting/concurrency/ChattingMessageServiceConcurrencyTest.java b/src/test/java/coffeemeet/server/chatting/concurrency/ChattingMessageServiceConcurrencyTest.java index 3eb37cd4..701bc1ba 100644 --- a/src/test/java/coffeemeet/server/chatting/concurrency/ChattingMessageServiceConcurrencyTest.java +++ b/src/test/java/coffeemeet/server/chatting/concurrency/ChattingMessageServiceConcurrencyTest.java @@ -1,5 +1,7 @@ package coffeemeet.server.chatting.concurrency; +import static coffeemeet.server.user.domain.UserStatus.CHATTING_UNCONNECTED; +import static coffeemeet.server.user.domain.UserStatus.MATCHING; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.willDoNothing; @@ -57,7 +59,7 @@ void tearDown() { void chattingConcurrencyTest() throws InterruptedException { // given ChattingRoom room = chattingRoomRepository.save(ChattingFixture.chattingRoom()); - User user = userRepository.save(UserFixture.user()); + User user = userRepository.save(UserFixture.user(CHATTING_UNCONNECTED)); String sessionId = "sessionId"; chattingMessageService.storeSocketSession(sessionId, String.valueOf(user.getId())); diff --git a/src/test/java/coffeemeet/server/common/fixture/entity/UserFixture.java b/src/test/java/coffeemeet/server/common/fixture/entity/UserFixture.java index 2304c022..1e79d1cb 100644 --- a/src/test/java/coffeemeet/server/common/fixture/entity/UserFixture.java +++ b/src/test/java/coffeemeet/server/common/fixture/entity/UserFixture.java @@ -29,6 +29,7 @@ public static User user(UserStatus userStatus) { .set(field(User::getUserStatus), userStatus) .ignore(field(User::isDeleted)) .ignore(field(User::isBlacklisted)) + .ignore(field(User::getChattingRoom)) .create(); } From a77029ff28ac7fbf00612c5b970e33feaef991ca Mon Sep 17 00:00:00 2001 From: sangminnim Date: Thu, 30 Nov 2023 14:50:13 +0900 Subject: [PATCH 13/14] =?UTF-8?q?test:=20=EB=A9=94=EC=9D=B8=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/coffeemeet/server/user/service/UserServiceTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/coffeemeet/server/user/service/UserServiceTest.java b/src/test/java/coffeemeet/server/user/service/UserServiceTest.java index 1eb2e6e8..49b1468b 100644 --- a/src/test/java/coffeemeet/server/user/service/UserServiceTest.java +++ b/src/test/java/coffeemeet/server/user/service/UserServiceTest.java @@ -4,6 +4,7 @@ import static coffeemeet.server.common.fixture.dto.AuthTokensFixture.authTokens; import static coffeemeet.server.common.fixture.dto.OAuthUserInfoDtoFixture.response; import static coffeemeet.server.common.fixture.entity.CertificationFixture.certification; +import static coffeemeet.server.common.fixture.entity.ChattingFixture.chattingRoom; import static coffeemeet.server.common.fixture.entity.UserFixture.keywords; import static coffeemeet.server.common.fixture.entity.UserFixture.user; import static coffeemeet.server.user.domain.OAuthProvider.KAKAO; @@ -28,6 +29,7 @@ import coffeemeet.server.auth.domain.AuthTokensGenerator; import coffeemeet.server.certification.domain.Certification; import coffeemeet.server.certification.implement.CertificationQuery; +import coffeemeet.server.chatting.current.domain.ChattingRoom; import coffeemeet.server.common.fixture.dto.SignupHTTPFixture; import coffeemeet.server.common.fixture.entity.UserFixture; import coffeemeet.server.common.implement.MediaManager; @@ -369,7 +371,8 @@ void getUserStatusMatchingTest() { void getUserStatusChattingUnConnectingTest() { // given Long userId = 1L; - User user = UserFixture.user(UserStatus.CHATTING_UNCONNECTED); + User user = UserFixture.user(UserStatus.MATCHING); + user.completeMatching(chattingRoom()); Certification certification = certification(); given(userQuery.getUserById(anyLong())).willReturn(user); From 19f79ab3a2ae9a882d34024379a2a9d1aa93a9de Mon Sep 17 00:00:00 2001 From: sangminnim Date: Thu, 30 Nov 2023 23:38:48 +0900 Subject: [PATCH 14/14] =?UTF-8?q?feat:=20jacoco=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ lombok.config | 1 + 2 files changed, 65 insertions(+) create mode 100644 lombok.config diff --git a/build.gradle b/build.gradle index 7af50df5..30ef9f1b 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,7 @@ plugins { id 'io.spring.dependency-management' version '1.1.3' id 'com.epages.restdocs-api-spec' version "${restdocsApiSpecVersion}" id 'org.hidetake.swagger.generator' version '2.18.2' + id 'jacoco' } group = 'coffee-meet' @@ -21,6 +22,68 @@ java { sourceCompatibility = '17' } +jacoco { + toolVersion = "0.8.8" +} + +jacocoTestReport { + reports { + xml.required = false + csv.required = false + } + + def Qdomains = [] + for (qPattern in '**/QA'..'**/QZ') { + Qdomains.add(qPattern + '*') + } + + afterEvaluate { + classDirectories.setFrom(files(classDirectories.files.collect { + fileTree(dir: it, excludes: [ + '**/common/config/**', + '**/common/presentation/advice/**', + '**/common/presentation/interceptor/**', + '**/common/presentation/resolver/**', + '**/common/domain/**', + '**/common/annotation/**', + '**/exception/**', + '**/dto/**', + '**/oauth/config/**' + ] + Qdomains) + })) + } + + finalizedBy 'jacocoTestCoverageVerification' +} + +jacocoTestCoverageVerification { + violationRules { + rule { + enabled = true + element = 'CLASS' + + limit { + counter = 'LINE' + value = 'COVEREDRATIO' + //minimum = 0.7 + } + + excludes = [ + '*.common.config.*', + '*.common.presentation.advice.*', + '*.common.presentation.interceptor.*', + '*.common.presentation.resolver.*', + '*.common.domain.*', + '*.common.annotation.*', + '*.exception.*', + '*.oauth.config.*', + '*.dto.*', + '*.*Application' + ] + } + } +} + configurations { compileOnly { extendsFrom annotationProcessor @@ -91,6 +154,7 @@ dependencies { tasks.named('test') { useJUnitPlatform() + finalizedBy jacocoTestReport } swaggerSources { diff --git a/lombok.config b/lombok.config new file mode 100644 index 00000000..7a21e880 --- /dev/null +++ b/lombok.config @@ -0,0 +1 @@ +lombok.addLombokGeneratedAnnotation = true