From 3a8a47f1561e37053cae9624acbe5dacd3113dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=95=84=EC=97=B0?= <110026001+ay-eonii@users.noreply.github.com> Date: Thu, 22 Aug 2024 21:16:06 +0900 Subject: [PATCH] =?UTF-8?q?Develop=20backend=20=EC=9E=91=EC=97=85=20?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=EB=B0=98=EC=98=81=20(#479)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 해주세요 조회 내림차순 조회 * feat: 찜한 모임 조회 내림차순 * feat: 모임 조회 내림차순 * feat: 알림 조회 내림차순 * test: 테스트 수정 * feat: 모집중인 모임만 조회 * fix: 같은 다락방 참여자에게만 모임 생성 알림이 전송되도록 수정 * fix: 부모 댓글 조회 오타 수정 * chore: 배포 서버 설정 * fix: 다락방 멤버의 멤버아이디를 가져오도록 변경 --------- Co-authored-by: MingyeomKim --- .../chamyo/repository/ChamyoRepository.java | 2 +- .../comment/repository/CommentRepository.java | 2 +- .../backend/moim/repository/MoimRepository.java | 9 ++++++--- .../mouda/backend/moim/service/MoimService.java | 16 ++++++++++++---- .../repository/MemberNotificationRepository.java | 2 +- .../service/NotificationService.java | 2 +- .../please/repository/PleaseRepository.java | 4 +--- .../backend/please/service/PleaseService.java | 2 +- .../backend/zzim/repository/ZzimRepository.java | 2 +- .../service/NotificationServiceTest.java | 4 ++-- .../please/service/PleaseServiceTest.java | 3 +-- 11 files changed, 28 insertions(+), 20 deletions(-) diff --git a/backend/src/main/java/mouda/backend/chamyo/repository/ChamyoRepository.java b/backend/src/main/java/mouda/backend/chamyo/repository/ChamyoRepository.java index 356b36ed4..4665d6e8e 100644 --- a/backend/src/main/java/mouda/backend/chamyo/repository/ChamyoRepository.java +++ b/backend/src/main/java/mouda/backend/chamyo/repository/ChamyoRepository.java @@ -20,7 +20,7 @@ public interface ChamyoRepository extends JpaRepository { boolean existsByMoimIdAndDarakbangMemberId(Long moimId, Long darakbangMemberId); - List findAllByDarakbangMemberId(Long darakbangMemberId); + List findAllByDarakbangMemberIdOrderByIdDesc(Long darakbangMemberId); void deleteAllByMoimId(Long moimId); diff --git a/backend/src/main/java/mouda/backend/comment/repository/CommentRepository.java b/backend/src/main/java/mouda/backend/comment/repository/CommentRepository.java index 53e0f8f11..30df35616 100644 --- a/backend/src/main/java/mouda/backend/comment/repository/CommentRepository.java +++ b/backend/src/main/java/mouda/backend/comment/repository/CommentRepository.java @@ -10,7 +10,7 @@ public interface CommentRepository extends JpaRepository { - @Query("SELECT c.darakbangMember.memberId FROM Comment c WHERE c.parentId = :parentId") + @Query("SELECT c.darakbangMember.memberId FROM Comment c WHERE c.id = :parentId") Long findMemberIdByParentId(@Param("parentId") long parentId); List findAllByMoimIdOrderByCreatedAt(long id); diff --git a/backend/src/main/java/mouda/backend/moim/repository/MoimRepository.java b/backend/src/main/java/mouda/backend/moim/repository/MoimRepository.java index bfe6b8cfe..9952459d6 100644 --- a/backend/src/main/java/mouda/backend/moim/repository/MoimRepository.java +++ b/backend/src/main/java/mouda/backend/moim/repository/MoimRepository.java @@ -20,7 +20,10 @@ public interface MoimRepository extends JpaRepository { @Modifying int updateMoimStatusById(@Param("id") Long moimId, @Param("status") MoimStatus status); - List findAllByDarakbangId(Long darakbangId); - - boolean existsByIdAndDarakbangId(Long moimId, Long darakbangId); + @Query(""" + SELECT m From Moim m + WHERE m.darakbangId = :darakbangId AND m.moimStatus = 'MOIMING' + ORDER BY m.id DESC + """) + List findAllByDarakbangIdOrderByIdDesc(@Param("darakbangId") Long darakbangId); } diff --git a/backend/src/main/java/mouda/backend/moim/service/MoimService.java b/backend/src/main/java/mouda/backend/moim/service/MoimService.java index d9ef622a8..502f0ed59 100644 --- a/backend/src/main/java/mouda/backend/moim/service/MoimService.java +++ b/backend/src/main/java/mouda/backend/moim/service/MoimService.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Stream; import org.springframework.beans.factory.annotation.Value; @@ -22,6 +23,7 @@ import mouda.backend.comment.exception.CommentException; import mouda.backend.comment.repository.CommentRepository; import mouda.backend.darakbangmember.domain.DarakbangMember; +import mouda.backend.darakbangmember.repository.repository.DarakbangMemberRepository; import mouda.backend.moim.domain.FilterType; import mouda.backend.moim.domain.Moim; import mouda.backend.moim.domain.MoimStatus; @@ -44,6 +46,7 @@ @RequiredArgsConstructor public class MoimService { + private final DarakbangMemberRepository darakbangMemberRepository; @Value("${url.base}") private String baseUrl; @@ -72,13 +75,17 @@ public Moim createMoim(Long darakbangId, DarakbangMember darakbangMember, MoimCr .targetUrl(baseUrl + String.format(moimUrl, darakbangId, moim.getId())) .build(); - notificationService.notifyToAllExceptMember(notification, darakbangMember.getMemberId(), darakbangId); + List darakbangMembersExceptMe = darakbangMemberRepository.findAllByDarakbangId(darakbangId).stream() + .filter(member -> !Objects.equals(member.getId(), darakbangMember.getId())) + .map(DarakbangMember::getMemberId) + .toList(); + notificationService.notifyToMembers(notification, darakbangMembersExceptMe, darakbangId); return moim; } @Transactional(readOnly = true) public MoimFindAllResponses findAllMoim(Long darakbangId, DarakbangMember darakbangMember) { - List moims = moimRepository.findAllByDarakbangId(darakbangId); + List moims = moimRepository.findAllByDarakbangIdOrderByIdDesc(darakbangId); return new MoimFindAllResponses( moims.stream() .map(moim -> { @@ -301,7 +308,8 @@ private void validateCanEditMoim(Moim moim, DarakbangMember darakbangMember) { } public MoimFindAllResponses findAllMyMoim(DarakbangMember darakbangMember, FilterType filter) { - Stream chamyoStream = chamyoRepository.findAllByDarakbangMemberId(darakbangMember.getId()).stream(); + Stream chamyoStream = chamyoRepository.findAllByDarakbangMemberIdOrderByIdDesc(darakbangMember.getId()) + .stream(); if (filter == FilterType.PAST) { chamyoStream = chamyoStream.filter(chamyo -> chamyo.getMoim().isPastMoim()); @@ -324,7 +332,7 @@ public MoimFindAllResponses findAllMyMoim(DarakbangMember darakbangMember, Filte } public MoimFindAllResponses findZzimedMoim(DarakbangMember darakbangMember) { - List zzims = zzimRepository.findAllByDarakbangMemberId(darakbangMember.getId()); + List zzims = zzimRepository.findAllByDarakbangMemberIdOrderByIdDesc(darakbangMember.getId()); List responses = zzims.stream() .map(zzim -> { diff --git a/backend/src/main/java/mouda/backend/notification/repository/MemberNotificationRepository.java b/backend/src/main/java/mouda/backend/notification/repository/MemberNotificationRepository.java index 0383e000c..da0e4d321 100644 --- a/backend/src/main/java/mouda/backend/notification/repository/MemberNotificationRepository.java +++ b/backend/src/main/java/mouda/backend/notification/repository/MemberNotificationRepository.java @@ -8,5 +8,5 @@ public interface MemberNotificationRepository extends JpaRepository { - List findAllByMemberIdAndDarakbangId(Long memberId, Long darakbangId); + List findAllByMemberIdAndDarakbangIdOrderByIdDesc(Long memberId, Long darakbangId); } diff --git a/backend/src/main/java/mouda/backend/notification/service/NotificationService.java b/backend/src/main/java/mouda/backend/notification/service/NotificationService.java index 1ac5c81fa..99262adaa 100644 --- a/backend/src/main/java/mouda/backend/notification/service/NotificationService.java +++ b/backend/src/main/java/mouda/backend/notification/service/NotificationService.java @@ -156,7 +156,7 @@ private List> chunkFcmTokensForMulticast(List tokens) { } public NotificationFindAllResponses findAllMyNotifications(Member member, Long darakbangId) { - List responses = memberNotificationRepository.findAllByMemberIdAndDarakbangId( + List responses = memberNotificationRepository.findAllByMemberIdAndDarakbangIdOrderByIdDesc( member.getId(), darakbangId) .stream() .map(MemberNotification::getMoudaNotification) diff --git a/backend/src/main/java/mouda/backend/please/repository/PleaseRepository.java b/backend/src/main/java/mouda/backend/please/repository/PleaseRepository.java index 3e68911e8..ae475ba95 100644 --- a/backend/src/main/java/mouda/backend/please/repository/PleaseRepository.java +++ b/backend/src/main/java/mouda/backend/please/repository/PleaseRepository.java @@ -8,7 +8,5 @@ public interface PleaseRepository extends JpaRepository { - List findAllByDarakbangId(Long darakbangId); - - boolean existsByIdAndDarakbangId(Long pleaseId, Long darakbangId); + List findAllByDarakbangIdOrderByIdDesc(Long darakbangId); } diff --git a/backend/src/main/java/mouda/backend/please/service/PleaseService.java b/backend/src/main/java/mouda/backend/please/service/PleaseService.java index ba4a358d9..60e500ecd 100644 --- a/backend/src/main/java/mouda/backend/please/service/PleaseService.java +++ b/backend/src/main/java/mouda/backend/please/service/PleaseService.java @@ -46,7 +46,7 @@ public void deletePlease(Long darakbangId, Long pleaseId, DarakbangMember darakb } public PleaseFindAllResponses findAllPlease(Long darakbangId, DarakbangMember darakbangMember) { - List pleases = pleaseRepository.findAllByDarakbangId(darakbangId); + List pleases = pleaseRepository.findAllByDarakbangIdOrderByIdDesc(darakbangId); return new PleaseFindAllResponses( pleases.stream() diff --git a/backend/src/main/java/mouda/backend/zzim/repository/ZzimRepository.java b/backend/src/main/java/mouda/backend/zzim/repository/ZzimRepository.java index 41e2ce371..81c779693 100644 --- a/backend/src/main/java/mouda/backend/zzim/repository/ZzimRepository.java +++ b/backend/src/main/java/mouda/backend/zzim/repository/ZzimRepository.java @@ -15,5 +15,5 @@ public interface ZzimRepository extends JpaRepository { void deleteAllByMoimId(Long moimId); - List findAllByDarakbangMemberId(Long darakbangMemberId); + List findAllByDarakbangMemberIdOrderByIdDesc(Long darakbangMemberId); } diff --git a/backend/src/test/java/mouda/backend/notification/service/NotificationServiceTest.java b/backend/src/test/java/mouda/backend/notification/service/NotificationServiceTest.java index e516839d4..94a8f97d0 100644 --- a/backend/src/test/java/mouda/backend/notification/service/NotificationServiceTest.java +++ b/backend/src/test/java/mouda/backend/notification/service/NotificationServiceTest.java @@ -96,9 +96,9 @@ void findAllMyNotifications() { assertThat(responses).satisfies(res -> { assertThat(res).hasSize(2); assertThat(res).extracting(NotificationFindAllResponse::message) - .containsExactly(type1.createMessage("테스트모임"), type2.createMessage("상돌")); + .containsExactly(type2.createMessage("상돌"), type1.createMessage("테스트모임")); assertThat(res).extracting(NotificationFindAllResponse::type) - .containsExactly(type1.toString(), type2.toString()); + .containsExactly(type2.toString(), type1.toString()); }); } } diff --git a/backend/src/test/java/mouda/backend/please/service/PleaseServiceTest.java b/backend/src/test/java/mouda/backend/please/service/PleaseServiceTest.java index 3a4cab658..84b65ce54 100644 --- a/backend/src/test/java/mouda/backend/please/service/PleaseServiceTest.java +++ b/backend/src/test/java/mouda/backend/please/service/PleaseServiceTest.java @@ -126,8 +126,7 @@ void findAllPlease() { PleaseFindAllResponses pleaseFindAllResponses = pleaseService.findAllPlease( darakbang.getId(), darakbangHogee); - assertThat(pleaseFindAllResponses.pleases().get(0).isInterested()).isTrue(); - assertThat(pleaseFindAllResponses.pleases().get(1).isInterested()).isFalse(); + assertThat(pleaseFindAllResponses.pleases()).extracting("isInterested").containsExactly(false, true); } } }