From 56531b670c956c9ec7db491f882ac27de34bd807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EB=AA=A8?= Date: Thu, 8 Feb 2024 18:18:04 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8C=94=EB=A1=9C=EC=9A=B0=20=EC=B7=A8?= =?UTF-8?q?=EC=86=8C=20=EC=8B=9C=20=EC=95=8C=EB=A6=BC=20=ED=9E=88=EC=8A=A4?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=20=EC=82=AD=EC=A0=9C=20(#286)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 팔로우 취소 시 알림 히스토리 삭제 * remove: .gitkeep 파일 삭제 * fix: notification 조회 시 NotificationType도 받도록 수정 --- .../follow/application/FollowService.java | 19 +++++++++++---- .../domain/notification/api/.gitkeep | 0 .../application/NotificationService.java | 24 ------------------- .../dao/NotificationRepository.java | 7 +++++- .../domain/notification/dto/.gitkeep | 0 5 files changed, 20 insertions(+), 30 deletions(-) delete mode 100644 src/main/java/com/depromeet/domain/notification/api/.gitkeep delete mode 100644 src/main/java/com/depromeet/domain/notification/application/NotificationService.java delete mode 100644 src/main/java/com/depromeet/domain/notification/dto/.gitkeep diff --git a/src/main/java/com/depromeet/domain/follow/application/FollowService.java b/src/main/java/com/depromeet/domain/follow/application/FollowService.java index e14232137..34c488f91 100644 --- a/src/main/java/com/depromeet/domain/follow/application/FollowService.java +++ b/src/main/java/com/depromeet/domain/follow/application/FollowService.java @@ -11,7 +11,8 @@ import com.depromeet.domain.mission.domain.Mission; import com.depromeet.domain.missionRecord.domain.ImageUploadStatus; import com.depromeet.domain.missionRecord.domain.MissionRecord; -import com.depromeet.domain.notification.application.NotificationService; +import com.depromeet.domain.notification.dao.NotificationRepository; +import com.depromeet.domain.notification.domain.Notification; import com.depromeet.domain.notification.domain.NotificationType; import com.depromeet.global.config.fcm.FcmService; import com.depromeet.global.error.exception.CustomException; @@ -27,7 +28,7 @@ @RequiredArgsConstructor @Transactional public class FollowService { - private final NotificationService notificationService; + private final NotificationRepository notificationRepository; private final MemberUtil memberUtil; private final MemberRepository memberRepository; private final MemberRelationRepository memberRelationRepository; @@ -54,9 +55,10 @@ public void createFollow(FollowCreateRequest request) { targetMember.getFcmInfo().getFcmToken(), PUSH_SERVICE_TITLE, String.format(PUSH_SERVICE_CONTENT, currentMember.getProfile().getNickname())); - notificationService.createNotification( - NotificationType.FOLLOW, currentMember, targetMember); - + Notification notification = + Notification.createNotification( + NotificationType.FOLLOW, currentMember, targetMember); + notificationRepository.save(notification); memberRelationRepository.save(memberRelation); } @@ -69,6 +71,13 @@ public void deleteFollow(FollowDeleteRequest request) { .findBySourceIdAndTargetId(currentMember.getId(), targetMember.getId()) .orElseThrow(() -> new CustomException(ErrorCode.FOLLOW_NOT_EXIST)); + Optional optionalNotification = + notificationRepository.findBySourceMemberIdAndTargetMemberIdAndNotificationType( + currentMember.getId(), targetMember.getId(), NotificationType.FOLLOW); + if (optionalNotification.isPresent()) { + Notification notification = optionalNotification.get(); + notificationRepository.delete(notification); + } memberRelationRepository.delete(memberRelation); } diff --git a/src/main/java/com/depromeet/domain/notification/api/.gitkeep b/src/main/java/com/depromeet/domain/notification/api/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/main/java/com/depromeet/domain/notification/application/NotificationService.java b/src/main/java/com/depromeet/domain/notification/application/NotificationService.java deleted file mode 100644 index e3bc361fd..000000000 --- a/src/main/java/com/depromeet/domain/notification/application/NotificationService.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.depromeet.domain.notification.application; - -import com.depromeet.domain.member.domain.Member; -import com.depromeet.domain.notification.dao.NotificationRepository; -import com.depromeet.domain.notification.domain.Notification; -import com.depromeet.domain.notification.domain.NotificationType; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@RequiredArgsConstructor -@Transactional -public class NotificationService { - - private final NotificationRepository notificationRepository; - - public void createNotification( - NotificationType notificationType, Member currentMember, Member targetMember) { - Notification notification = - Notification.createNotification(notificationType, currentMember, targetMember); - notificationRepository.save(notification); - } -} diff --git a/src/main/java/com/depromeet/domain/notification/dao/NotificationRepository.java b/src/main/java/com/depromeet/domain/notification/dao/NotificationRepository.java index 1cd6cb78b..0b70f4801 100644 --- a/src/main/java/com/depromeet/domain/notification/dao/NotificationRepository.java +++ b/src/main/java/com/depromeet/domain/notification/dao/NotificationRepository.java @@ -1,6 +1,11 @@ package com.depromeet.domain.notification.dao; import com.depromeet.domain.notification.domain.Notification; +import com.depromeet.domain.notification.domain.NotificationType; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -public interface NotificationRepository extends JpaRepository {} +public interface NotificationRepository extends JpaRepository { + Optional findBySourceMemberIdAndTargetMemberIdAndNotificationType( + Long sourceId, Long targetId, NotificationType notificationType); +} diff --git a/src/main/java/com/depromeet/domain/notification/dto/.gitkeep b/src/main/java/com/depromeet/domain/notification/dto/.gitkeep deleted file mode 100644 index e69de29bb..000000000