Skip to content

Commit

Permalink
fix : 공지 삭제 시 읽음 정보 제거 추가 (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
rladmstn authored Nov 26, 2024
1 parent 67945ec commit c64c82c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<StudyGroupService> studyGroupServiceProvider;
private final NotificationSettingRepository notificationSettingRepository;
private final NotificationService notificationService;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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<NoticeRead, Long> {
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,6 +80,8 @@ class StudyGroupServiceTest {
@Mock
private ProblemRepository problemRepository;
@Mock
private NoticeReadRepository noticeReadRepository;
@Mock
private UserRepository userRepository;
@Mock
private NotificationRepository notificationRepository;
Expand Down

0 comments on commit c64c82c

Please sign in to comment.