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 @@ -29,7 +29,7 @@ public Notification create(Notification notification) {
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void createAll(List<Notification> notifications) {
List<Notification> existsNotifications = notificationQueryRepository.existsDedupKeyByNotifications(notifications);
List<Notification> existsNotifications = notificationQueryRepository.findNotificationsByDedupKey(notifications);
Set<String> existingPairs = getExistingPairs(existsNotifications);
List<Notification> toSave = getNotificationsNotDuplicated(notifications, existingPairs);
if (!toSave.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public record NotificationRowDto(
String title,
String content,
String imageUrl,
boolean isValid,
boolean isRead,
LocalDateTime eventAt
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public interface NotificationQueryRepository {
Optional<TargetUserDto> findUserByPostId(Long postId);
Optional<TargetPostDto> findPostById(Long postId);
boolean existsByDedupKey(Long ReceiverId, String dedupKey);
List<Notification> existsDedupKeyByNotifications(List<Notification> notifications);
List<Notification> findNotificationsByDedupKey(List<Notification> notifications);
List<TargetUserDto> findVoteUsersByPostId(Long postId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public Slice<NotificationDto> findNotifications(Long userId, Long cursor, Pageab
notification.title,
notification.content,
notification.imageUrl,
notification.isValid,
notification.isRead,
notification.eventAt
)
Expand Down Expand Up @@ -138,7 +139,7 @@ public boolean existsByDedupKey(Long receiverId, String dedupkey) {
).fetchFirst();
return one != null;
}
public List<Notification> existsDedupKeyByNotifications(List<Notification> notifications) {
public List<Notification> findNotificationsByDedupKey(List<Notification> notifications) {
BooleanBuilder builder = new BooleanBuilder();
for (Notification n : notifications) {
builder.or(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public boolean existsByDedupKey(Long ReceiverId, String dedupKey) {
}

@Override
public List<Notification> existsDedupKeyByNotifications(List<Notification> notifications) {
return notificationQueryDslRepository.existsDedupKeyByNotifications(notifications);
public List<Notification> findNotificationsByDedupKey(List<Notification> notifications) {
return notificationQueryDslRepository.findNotificationsByDedupKey(notifications);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public record NotificationResponse (
String content,
String imageUrl,
List<Target> targets,
boolean isValid,
boolean isRead,
LocalDateTime eventAt
)implements CursorDto{
Expand All @@ -28,6 +29,7 @@ public static NotificationResponse of (NotificationDto notificationDto){
notificationDto.notificationRowDto().content(),
notificationDto.notificationRowDto().imageUrl(),
List.copyOf(notificationDto.targets().stream().map(t -> Target.of(t.id(), t.type())).toList()),
notificationDto.notificationRowDto().isValid(),
notificationDto.notificationRowDto().isRead(),
notificationDto.notificationRowDto().eventAt()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
import com.chooz.notification.domain.NotificationType;
import com.chooz.notification.domain.Target;
import com.chooz.notification.domain.TargetType;
import com.chooz.notification.persistence.NotificationJpaRepository;
import com.chooz.notification.presentation.dto.NotificationPresentResponse;
import com.chooz.notification.presentation.dto.NotificationResponse;
import com.chooz.support.IntegrationTest;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.transaction.AfterTransaction;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -28,6 +31,14 @@ class NotificationQueryServiceTest extends IntegrationTest {
@Autowired
NotificationCommandService notificationCommandService;

@Autowired
NotificationJpaRepository notificationJpaRepository;

@AfterTransaction
void clean() {
notificationJpaRepository.deleteAll();
}

@Test
@DisplayName("알림 조회")
void notifications() throws Exception {
Expand Down Expand Up @@ -65,7 +76,16 @@ void notifications() throws Exception {

//then
assertAll(
() -> assertThat(notifications.size()).isNotZero()
() -> assertThat(notifications.size()).isOne(),
() -> assertThat(notifications.getFirst().content()).isEqualTo(content),
() -> assertThat(notifications.getFirst().title()).isEqualTo(title),
() -> assertThat(notifications.getFirst().profileUrl()).isEqualTo(profileUrl),
() -> assertThat(notifications.getFirst().imageUrl()).isEqualTo(imageUrl),
() -> assertThat(notifications.getFirst().eventAt().truncatedTo(ChronoUnit.MICROS))
.isEqualTo(eventAt.truncatedTo(ChronoUnit.MICROS)),
() -> assertThat(notifications.getFirst().isRead()).isEqualTo(false),
() -> assertThat(notifications.getFirst().isValid()).isEqualTo(true)

);
}
@Test
Expand Down Expand Up @@ -98,7 +118,6 @@ void present() throws Exception {
//when
notificationCommandService.create(notification);
NotificationPresentResponse notificationPresentResponse = notificationQueryService.present(receiverId);

//then
assertAll(
() -> assertThat(notificationPresentResponse.present()).isTrue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void findNotifications() throws Exception {
"지금 바로 확인해보세요.",
"https://cdn.chooz.site/images/20865b3c-4e2c-454a-81a1-9ca31bbaf77d",
List.of(Target.of(1L, TargetType.POST)),
true,
false,
LocalDateTime.now()
)
Expand Down Expand Up @@ -88,6 +89,8 @@ void findNotifications() throws Exception {
.type(JsonFieldType.NUMBER).description("알림 타겟 ID"),
fieldWithPath("data[].targets[].type")
.type(JsonFieldType.STRING).description("알림 타겟 유형"),
fieldWithPath("data[].isValid")
.type(JsonFieldType.BOOLEAN).description("유효 알림 여부"),
fieldWithPath("data[].isRead")
.type(JsonFieldType.BOOLEAN).description("읽음 여부"),
fieldWithPath("data[].eventAt")
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/chooz/support/IntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.chooz.support;

import jakarta.transaction.Transactional;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Profile;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

@ActiveProfiles("test")
@Transactional
Expand Down
Loading