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
@@ -1,5 +1,6 @@
package kr.co.conceptbe.notification.app;

import javax.management.Notification;
import kr.co.conceptbe.auth.presentation.dto.AuthCredentials;
import kr.co.conceptbe.idea.domain.Idea;
import kr.co.conceptbe.idea.domain.event.CreatedIdeaEvent;
Expand Down Expand Up @@ -47,8 +48,20 @@ public void createNotificationByCreateIdeaEvent(CreatedIdeaEvent createdIdeaEven
Idea idea = createdIdeaEvent.idea();
List<IdeaNotificationSetting> notificationSettings = notificationSettingRepository.findAll();

List<IdeaNotification> ideaNotifications = notificationTrigger.getNotificationByCreatedIdeaEvent(idea, notificationSettings);
List<IdeaNotification> ideaNotifications = notificationTrigger.getNotificationByCreatedIdeaEvent(idea,
notificationSettings);
notificationRepository.saveAll(ideaNotifications);
}

@Transactional
public void readNotification(AuthCredentials auth, Long notificationId) {
Long memberId = auth.id();
IdeaNotification notification = notificationRepository.findByMemberIdAndId(memberId, notificationId)
.orElseThrow(
() -> new IllegalArgumentException("Not Found Notification ID : " + notificationId)
);
notification.read(memberId);
notificationRepository.save(notification);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class IdeaNotification extends BaseTimeEntity {
@Column(nullable = false)
private String cooperationWay;

@Column(nullable = false)
private boolean isAlreadyRead;

public static IdeaNotification withIdea(Idea idea, IdeaNotificationSetting notificationSetting) {
Long receiverId = notificationSetting.getMemberId();
String title = idea.getTitle();
Expand All @@ -63,7 +66,8 @@ public static IdeaNotification withIdea(Idea idea, IdeaNotificationSetting notif
idea.getId(),
joinBadges(branchBadges, Function.identity()),
joinBadges(purposes, purpose -> purpose.getPurpose().getName()),
cooperationWay
cooperationWay,
false
);
}

Expand Down Expand Up @@ -100,4 +104,11 @@ private List<String> splitBadges(String badges) {
return new ArrayList<>(List.of(badgesEach));
}

public void read(Long memberId) {
if (!memberId.equals(this.memberId)) {
throw new IllegalArgumentException("다른 계정의 알림을 읽을 수 없습니다.");
}
isAlreadyRead = true;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.co.conceptbe.notification.domain.repository;

import java.util.Optional;
import kr.co.conceptbe.notification.domain.IdeaNotification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -16,4 +17,6 @@ public interface NotificationRepository extends JpaRepository<IdeaNotification,
""", nativeQuery = true)
List<IdeaNotification> findAllNotifications(Long memberId, Long cursorId, Long limit);

Optional<IdeaNotification> findByMemberIdAndId(Long memberId, Long notificationId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -24,13 +26,24 @@ public class NotificationController implements NotificationSwagger {

@GetMapping
public ResponseEntity<List<NotificationResponse>> getNotifications(
@Parameter(hidden = true) @Auth AuthCredentials auth,
@Auth AuthCredentials auth,
@RequestParam(required = false, defaultValue = "" + Long.MAX_VALUE) Long cursorId
) {
Long limit = 10L;
List<NotificationResponse> responses = notificationService.findAllNotifications(auth, cursorId, limit);
List<NotificationResponse> responses = notificationService.findAllNotifications(auth, cursorId,
limit);

return ResponseEntity.ok(responses);
}

@PutMapping("/{notificationId}/read")
public ResponseEntity<Void> readNotification(
@Auth AuthCredentials auth,
@PathVariable Long notificationId
) {
notificationService.readNotification(auth, notificationId);

return ResponseEntity.ok().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ ResponseEntity<List<NotificationResponse>> getNotifications(
Long cursorId
);

ResponseEntity<Void> readNotification(
@Parameter(hidden = true) AuthCredentials auth,
Long notificationId
);

}
Loading