Skip to content

Commit

Permalink
팔로우 취소 시 알림 히스토리 삭제 (#286)
Browse files Browse the repository at this point in the history
* fix: 팔로우 취소 시 알림 히스토리 삭제

* remove: .gitkeep 파일 삭제

* fix: notification 조회 시 NotificationType도 받도록 수정
  • Loading branch information
kdomo authored Feb 8, 2024
1 parent 53b1204 commit 56531b6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}

Expand All @@ -69,6 +71,13 @@ public void deleteFollow(FollowDeleteRequest request) {
.findBySourceIdAndTargetId(currentMember.getId(), targetMember.getId())
.orElseThrow(() -> new CustomException(ErrorCode.FOLLOW_NOT_EXIST));

Optional<Notification> optionalNotification =
notificationRepository.findBySourceMemberIdAndTargetMemberIdAndNotificationType(
currentMember.getId(), targetMember.getId(), NotificationType.FOLLOW);
if (optionalNotification.isPresent()) {
Notification notification = optionalNotification.get();
notificationRepository.delete(notification);
}
memberRelationRepository.delete(memberRelation);
}

Expand Down
Empty file.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<Notification, Long> {}
public interface NotificationRepository extends JpaRepository<Notification, Long> {
Optional<Notification> findBySourceMemberIdAndTargetMemberIdAndNotificationType(
Long sourceId, Long targetId, NotificationType notificationType);
}
Empty file.

0 comments on commit 56531b6

Please sign in to comment.