diff --git a/src/main/java/com/gamzabat/algohub/feature/group/studygroup/service/StudyGroupService.java b/src/main/java/com/gamzabat/algohub/feature/group/studygroup/service/StudyGroupService.java index 9cb00114..068269bd 100644 --- a/src/main/java/com/gamzabat/algohub/feature/group/studygroup/service/StudyGroupService.java +++ b/src/main/java/com/gamzabat/algohub/feature/group/studygroup/service/StudyGroupService.java @@ -46,6 +46,7 @@ import com.gamzabat.algohub.feature.group.studygroup.repository.StudyGroupRepository; import com.gamzabat.algohub.feature.image.service.ImageService; import com.gamzabat.algohub.feature.notice.repository.NoticeCommentRepository; +import com.gamzabat.algohub.feature.notice.repository.NoticeReadRepository; import com.gamzabat.algohub.feature.notice.repository.NoticeRepository; import com.gamzabat.algohub.feature.notification.domain.NotificationSetting; import com.gamzabat.algohub.feature.notification.enums.NotificationCategory; @@ -79,7 +80,7 @@ public class StudyGroupService { private final NoticeCommentRepository noticeCommentRepository; private final SolutionCommentRepository solutionCommentRepository; private final NotificationRepository notificationRepository; - + private final NoticeReadRepository noticeReadRepository; private final ObjectProvider studyGroupServiceProvider; private final NotificationSettingRepository notificationSettingRepository; private final NotificationService notificationService; @@ -178,6 +179,7 @@ private void deleteAllAboutGroup(StudyGroup group) { notificationSettingRepository.deleteAllByStudyGroup(group); notificationRepository.deleteAllByStudyGroup(group); noticeCommentRepository.deleteAllByStudyGroup(group); + noticeReadRepository.deleteAllByStudyGroup(group); noticeRepository.deleteAllByStudyGroup(group); solutionCommentRepository.deleteAllByStudyGroup(group); solutionRepository.deleteAllByStudyGroup(group); @@ -241,6 +243,7 @@ public void deleteMemberFromStudyGroup(User user, GroupMember groupMember, Study .ifPresent(bookmarkedStudyGroupRepository::delete); rankingRepository.deleteByMember(groupMember); notificationSettingRepository.deleteByMember(groupMember); + noticeReadRepository.deleteAllByStudyGroupAndUser(studyGroup, user); notificationRepository.deleteAllByUserAndStudyGroup(user, studyGroup); groupMemberRepository.delete(groupMember); log.info("success to delete group member"); diff --git a/src/main/java/com/gamzabat/algohub/feature/notice/repository/NoticeReadRepository.java b/src/main/java/com/gamzabat/algohub/feature/notice/repository/NoticeReadRepository.java index 7161a670..91361769 100644 --- a/src/main/java/com/gamzabat/algohub/feature/notice/repository/NoticeReadRepository.java +++ b/src/main/java/com/gamzabat/algohub/feature/notice/repository/NoticeReadRepository.java @@ -1,11 +1,26 @@ package com.gamzabat.algohub.feature.notice.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import com.gamzabat.algohub.feature.group.studygroup.domain.StudyGroup; import com.gamzabat.algohub.feature.notice.domain.Notice; import com.gamzabat.algohub.feature.notice.domain.NoticeRead; import com.gamzabat.algohub.feature.user.domain.User; public interface NoticeReadRepository extends JpaRepository { boolean existsByNoticeAndUser(Notice notice, User user); + + @Modifying + @Query("delete from NoticeRead nr where nr.notice = :notice") + void deleteAllByNotice(Notice notice); + + @Modifying + @Query("delete from NoticeRead nr where nr.notice.studyGroup = :group") + void deleteAllByStudyGroup(StudyGroup group); + + @Modifying + @Query("delete from NoticeRead nr where nr.notice.studyGroup = :group and nr.user = :user") + void deleteAllByStudyGroupAndUser(StudyGroup group, User user); } diff --git a/src/main/java/com/gamzabat/algohub/feature/notice/service/NoticeService.java b/src/main/java/com/gamzabat/algohub/feature/notice/service/NoticeService.java index 12e70aff..9923239c 100644 --- a/src/main/java/com/gamzabat/algohub/feature/notice/service/NoticeService.java +++ b/src/main/java/com/gamzabat/algohub/feature/notice/service/NoticeService.java @@ -121,6 +121,7 @@ public void deleteNotice(User user, Long noticeId) { throw new UserValidationException("공지를 삭제할 수 있는 권한이 없습니다"); noticeCommentRepository.deleteAllCommentByNotice(notice); + noticeReadRepository.deleteAllByNotice(notice); noticeRepository.delete(notice); log.info("success to delete notice. userId: {}, noticeId: {}", user.getId(), noticeId); diff --git a/src/test/java/com/gamzabat/algohub/service/StudyGroupServiceTest.java b/src/test/java/com/gamzabat/algohub/service/StudyGroupServiceTest.java index 843cf264..559e0501 100644 --- a/src/test/java/com/gamzabat/algohub/service/StudyGroupServiceTest.java +++ b/src/test/java/com/gamzabat/algohub/service/StudyGroupServiceTest.java @@ -49,6 +49,7 @@ import com.gamzabat.algohub.feature.group.studygroup.service.StudyGroupService; import com.gamzabat.algohub.feature.image.service.ImageService; import com.gamzabat.algohub.feature.notice.repository.NoticeCommentRepository; +import com.gamzabat.algohub.feature.notice.repository.NoticeReadRepository; import com.gamzabat.algohub.feature.notice.repository.NoticeRepository; import com.gamzabat.algohub.feature.notification.domain.NotificationSetting; import com.gamzabat.algohub.feature.notification.repository.NotificationRepository; @@ -79,6 +80,8 @@ class StudyGroupServiceTest { @Mock private ProblemRepository problemRepository; @Mock + private NoticeReadRepository noticeReadRepository; + @Mock private UserRepository userRepository; @Mock private NotificationRepository notificationRepository;