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