From 9c6f2c971559a7b9fabadd803f74d707ed9d1842 Mon Sep 17 00:00:00 2001 From: ddingmin Date: Tue, 13 Feb 2024 00:23:13 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=ED=95=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EA=B0=80=20=EB=B6=81=EB=A7=88=ED=81=AC?= =?UTF-8?q?=ED=95=9C=20=EB=AA=A8=EC=9E=84=20=EC=A1=B0=ED=9A=8C=20(#204)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 로그인한 유저가 북마크한 모임 조회 * test: 테스트 코드에 로그인 로직 추가 --- .../teumteum/meeting/controller/MeetingController.java | 5 +++-- .../net/teumteum/meeting/domain/MeetingSpecification.java | 4 ++++ .../java/net/teumteum/meeting/service/MeetingService.java | 7 ++++--- .../net/teumteum/integration/MeetingIntegrationTest.java | 8 ++++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/teumteum/meeting/controller/MeetingController.java b/src/main/java/net/teumteum/meeting/controller/MeetingController.java index c3eab0b8..27410d42 100644 --- a/src/main/java/net/teumteum/meeting/controller/MeetingController.java +++ b/src/main/java/net/teumteum/meeting/controller/MeetingController.java @@ -62,10 +62,11 @@ public PageDto getMeetingsByCondition( @RequestParam(value = "topic", required = false) Topic topic, @RequestParam(value = "meetingAreaStreet", required = false) String meetingAreaStreet, @RequestParam(value = "participantUserId", required = false) Long participantUserId, + @RequestParam(value = "isBookmarked", required = false) Boolean isBookmarked, @RequestParam(value = "searchWord", required = false) String searchWord) { - + Long userId = securityService.getCurrentUserId(); return meetingService.getMeetingsBySpecification(pageable, topic, meetingAreaStreet, participantUserId, - searchWord, isOpen); + searchWord, isBookmarked, isOpen, userId); } @PutMapping("/{meetingId}") diff --git a/src/main/java/net/teumteum/meeting/domain/MeetingSpecification.java b/src/main/java/net/teumteum/meeting/domain/MeetingSpecification.java index fc2bc861..a0cb0ff2 100644 --- a/src/main/java/net/teumteum/meeting/domain/MeetingSpecification.java +++ b/src/main/java/net/teumteum/meeting/domain/MeetingSpecification.java @@ -39,4 +39,8 @@ public static Specification withParticipantUserId(Long participantUserI participantUserId); } + public static Specification withBookmarkedUserId(Long userId) { + return (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.join("bookmarkedUserIds"), userId); + } + } diff --git a/src/main/java/net/teumteum/meeting/service/MeetingService.java b/src/main/java/net/teumteum/meeting/service/MeetingService.java index 00f3975e..d87db102 100644 --- a/src/main/java/net/teumteum/meeting/service/MeetingService.java +++ b/src/main/java/net/teumteum/meeting/service/MeetingService.java @@ -94,9 +94,8 @@ public void deleteMeeting(Long meetingId, Long userId) { } @Transactional(readOnly = true) - public PageDto getMeetingsBySpecification(Pageable pageable, Topic topic, - String meetingAreaStreet, - Long participantUserId, String searchWord, boolean isOpen) { + public PageDto getMeetingsBySpecification(Pageable pageable, Topic topic, String meetingAreaStreet, + Long participantUserId, String searchWord, Boolean isBookmarked, boolean isOpen, Long userId) { Specification spec = MeetingSpecification.withIsOpen(isOpen); @@ -110,6 +109,8 @@ public PageDto getMeetingsBySpecification(Pageable pageable, T spec = MeetingSpecification.withSearchWordInTitle(searchWord) .or(MeetingSpecification.withSearchWordInIntroduction(searchWord)) .and(MeetingSpecification.withIsOpen(isOpen)); + } else if (Boolean.TRUE.equals(isBookmarked)) { + spec = spec.and(MeetingSpecification.withBookmarkedUserId(userId)); } var meetings = meetingRepository.findAll(spec, pageable); diff --git a/src/test/java/net/teumteum/integration/MeetingIntegrationTest.java b/src/test/java/net/teumteum/integration/MeetingIntegrationTest.java index bec162c2..dc45f2c3 100644 --- a/src/test/java/net/teumteum/integration/MeetingIntegrationTest.java +++ b/src/test/java/net/teumteum/integration/MeetingIntegrationTest.java @@ -141,6 +141,8 @@ class Find_meeting_list_api { @DisplayName("존재하는 topic이 주어지면 페이지 네이션을 적용해 미팅 목록을 최신순으로 응답한다.") void Return_meeting_list_if_topic_and_page_nation_received() { // given + var user = repository.saveAndGetUser(); + securityContextSetting.set(user.getId()); var size = 2; var openMeetingsByTopic = repository.saveAndGetOpenMeetingsByTopic(size, Topic.스터디); var closeTopicMeetingsByTopic = repository.saveAndGetOpenMeetingsByTopic(size, Topic.고민_나누기); @@ -169,6 +171,8 @@ void Return_meeting_list_if_topic_and_page_nation_received() { @DisplayName("제목이나 설명에 존재하는 검색어가 주어지면 페이지 네이션을 적용해 미팅 목록을 최신순으로 응답한다.") void Return_meeting_list_if_search_word_and_page_nation_received() { // given + var user = repository.saveAndGetUser(); + securityContextSetting.set(user.getId()); var size = 2; var openMeetingsByTitle = repository.saveAndGetOpenMeetingsByTitle(size, "개발자 스터디"); var closeMeetingsByTitle = repository.saveAndGetCloseMeetingsByTitle(size, "개발자 스터디"); @@ -201,6 +205,8 @@ void Return_meeting_list_if_search_word_and_page_nation_received() { @DisplayName("참여자 id가 주어지면 페이지 네이션을 적용해 미팅 목록을 최신순으로 응답한다.") void Return_meeting_list_if_participant_user_id_and_page_nation_received() { // given + var user = repository.saveAndGetUser(); + securityContextSetting.set(user.getId()); var size = 2; var openMeetingsByParticipantUserId = repository.saveAndGetOpenMeetingsByParticipantUserId(size, 2L); var closeMeetingsByParticipantUserId = repository.saveAndGetCloseMeetingsByParticipantUserId(size, 2L); @@ -229,6 +235,8 @@ void Return_meeting_list_if_participant_user_id_and_page_nation_received() { @DisplayName("요청한 size와 page보다 더 많은 데이터가 존재하면, hasNext를 true로 응답한다.") void Return_has_next_true_if_more_data_exists_than_requested_size_and_page() { // given + var user = repository.saveAndGetUser(); + securityContextSetting.set(user.getId()); var size = 10; var openMeetingsByTopic = repository.saveAndGetOpenMeetingsByTopic(size, Topic.스터디);