Skip to content

Commit

Permalink
refactor: Read Notification 할 때 예외 추가 및 isAlreadyRead 추가 (#110)
Browse files Browse the repository at this point in the history
Co-authored-by: kpeel <[email protected]>
  • Loading branch information
kpeel5839 and kpeel authored Jan 3, 2025
1 parent f4aeab2 commit 9d248d0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import kr.co.conceptbe.auth.presentation.dto.AuthCredentials;
import kr.co.conceptbe.idea.domain.Idea;
import kr.co.conceptbe.idea.domain.event.CreatedIdeaEvent;
import kr.co.conceptbe.idea.domain.persistence.IdeaRepository;
import kr.co.conceptbe.notification_setting.domain.IdeaNotificationSetting;
import kr.co.conceptbe.notification_setting.domain.repository.NotificationSettingRepository;
import kr.co.conceptbe.member.exception.NotFoundAuthCredentialException;
Expand All @@ -26,6 +27,7 @@ public class NotificationService {
private final NotificationRepository notificationRepository;
private final NotificationSettingRepository notificationSettingRepository;
private final NotificationTrigger notificationTrigger;
private final IdeaRepository ideaRepository;

@Transactional(readOnly = true)
public List<NotificationResponse> findAllNotifications(
Expand Down Expand Up @@ -60,7 +62,7 @@ public void readNotification(AuthCredentials auth, Long notificationId) {
.orElseThrow(
() -> new IllegalArgumentException("Not Found Notification ID : " + notificationId)
);
notification.read(memberId);
notification.read(memberId, ideaRepository::findById);
notificationRepository.save(notification);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public record NotificationResponse(
Long feedId,
String title,
String createAt,
List<String> badges
List<String> badges,
boolean isAlreadyRead
) {

public static NotificationResponse from(IdeaNotification notification) {
Expand All @@ -22,7 +23,8 @@ public static NotificationResponse from(IdeaNotification notification) {
notification.getIdeaId(),
notification.getTitle(),
notification.getCreatedAt().toString(),
ideaBranches
ideaBranches,
notification.isAlreadyRead()
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.co.conceptbe.notification.domain;

import jakarta.persistence.*;
import java.util.Optional;
import kr.co.conceptbe.common.entity.base.BaseTimeEntity;
import kr.co.conceptbe.idea.domain.Idea;
import kr.co.conceptbe.idea.domain.IdeaBranch;
Expand Down Expand Up @@ -104,10 +105,16 @@ private List<String> splitBadges(String badges) {
return new ArrayList<>(List.of(badgesEach));
}

public void read(Long memberId) {
public void read(Long memberId, Function<Long, Optional<Idea>> getIdea) {
if (!memberId.equals(this.memberId)) {
throw new IllegalArgumentException("다른 계정의 알림을 읽을 수 없습니다.");
}

Optional<Idea> idea = getIdea.apply(this.ideaId);
if (idea.isEmpty()) {
throw new IllegalArgumentException("게시글을 찾을 수 없습니다.");
}

isAlreadyRead = true;
}

Expand Down

0 comments on commit 9d248d0

Please sign in to comment.