Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading