diff --git a/backend/src/main/java/com/votogether/domain/alarm/dto/event/PostAlarmEvent.java b/backend/src/main/java/com/votogether/domain/alarm/dto/event/PostAlarmEvent.java index 7218bd620..b9a26fc0a 100644 --- a/backend/src/main/java/com/votogether/domain/alarm/dto/event/PostAlarmEvent.java +++ b/backend/src/main/java/com/votogether/domain/alarm/dto/event/PostAlarmEvent.java @@ -5,6 +5,7 @@ public record PostAlarmEvent( Member member, + String commentWriterNickname, Long targetId, AlarmType alarmType, String detail diff --git a/backend/src/main/java/com/votogether/domain/alarm/dto/response/PostAlarmDetailResponse.java b/backend/src/main/java/com/votogether/domain/alarm/dto/response/PostAlarmDetailResponse.java index 412394d9e..1b3e10713 100644 --- a/backend/src/main/java/com/votogether/domain/alarm/dto/response/PostAlarmDetailResponse.java +++ b/backend/src/main/java/com/votogether/domain/alarm/dto/response/PostAlarmDetailResponse.java @@ -15,11 +15,11 @@ public record PostAlarmDetailResponse( String commentWriter ) { - public static PostAlarmDetailResponse of(final Alarm alarm, final String nickname) { + public static PostAlarmDetailResponse of(final Alarm alarm) { return new PostAlarmDetailResponse( alarm.getTargetId(), alarm.getDetail(), - nickname + alarm.getCommentWriterNickname() ); } diff --git a/backend/src/main/java/com/votogether/domain/alarm/dto/response/PostAlarmResponse.java b/backend/src/main/java/com/votogether/domain/alarm/dto/response/PostAlarmResponse.java index 6ac96455d..3e503aec2 100644 --- a/backend/src/main/java/com/votogether/domain/alarm/dto/response/PostAlarmResponse.java +++ b/backend/src/main/java/com/votogether/domain/alarm/dto/response/PostAlarmResponse.java @@ -21,10 +21,10 @@ public record PostAlarmResponse( boolean isChecked ) { - public static PostAlarmResponse of(final Alarm alarm, final String nickname) { + public static PostAlarmResponse of(final Alarm alarm) { return new PostAlarmResponse( alarm.getId(), - PostAlarmDetailResponse.of(alarm, nickname), + PostAlarmDetailResponse.of(alarm), alarm.getCreatedAt(), alarm.isChecked() ); diff --git a/backend/src/main/java/com/votogether/domain/alarm/entity/Alarm.java b/backend/src/main/java/com/votogether/domain/alarm/entity/Alarm.java index eb41b1550..a1c663948 100644 --- a/backend/src/main/java/com/votogether/domain/alarm/entity/Alarm.java +++ b/backend/src/main/java/com/votogether/domain/alarm/entity/Alarm.java @@ -41,6 +41,9 @@ public class Alarm extends BaseEntity { @Column(length = 20, nullable = false) private AlarmType alarmType; + @Column(length = 20, nullable = false) + private String commentWriterNickname; + @Column(nullable = false) private Long targetId; @@ -54,12 +57,14 @@ public class Alarm extends BaseEntity { private Alarm( final Member member, final AlarmType alarmType, + final String commentWriterNickname, final Long targetId, final String detail, final boolean isChecked ) { this.member = member; this.alarmType = alarmType; + this.commentWriterNickname = commentWriterNickname; this.targetId = targetId; this.detail = detail; this.isChecked = isChecked; diff --git a/backend/src/main/java/com/votogether/domain/alarm/service/AlarmEventListener.java b/backend/src/main/java/com/votogether/domain/alarm/service/AlarmEventListener.java index 383ed63aa..8e7ec3fc6 100644 --- a/backend/src/main/java/com/votogether/domain/alarm/service/AlarmEventListener.java +++ b/backend/src/main/java/com/votogether/domain/alarm/service/AlarmEventListener.java @@ -23,6 +23,7 @@ public void handlePostAlarmEvent(final PostAlarmEvent postAlarmEvent) { final Alarm alarm = Alarm.builder() .member(postAlarmEvent.member()) .alarmType(postAlarmEvent.alarmType()) + .commentWriterNickname(postAlarmEvent.commentWriterNickname()) .targetId(postAlarmEvent.targetId()) .detail(postAlarmEvent.detail()) .isChecked(false) diff --git a/backend/src/main/java/com/votogether/domain/alarm/service/AlarmQueryService.java b/backend/src/main/java/com/votogether/domain/alarm/service/AlarmQueryService.java index a5c3fdad5..a9fa1e109 100644 --- a/backend/src/main/java/com/votogether/domain/alarm/service/AlarmQueryService.java +++ b/backend/src/main/java/com/votogether/domain/alarm/service/AlarmQueryService.java @@ -1,11 +1,10 @@ package com.votogether.domain.alarm.service; +import com.votogether.domain.alarm.dto.response.PostAlarmResponse; import com.votogether.domain.alarm.dto.response.ReportActionAlarmResponse; import com.votogether.domain.alarm.dto.response.ReportActionResponse; -import com.votogether.domain.alarm.dto.response.PostAlarmResponse; import com.votogether.domain.alarm.entity.Alarm; import com.votogether.domain.alarm.entity.ReportActionAlarm; -import com.votogether.domain.alarm.entity.vo.AlarmType; import com.votogether.domain.alarm.exception.AlarmExceptionType; import com.votogether.domain.alarm.repository.AlarmRepository; import com.votogether.domain.alarm.repository.ReportActionAlarmRepository; @@ -24,7 +23,6 @@ public class AlarmQueryService { private static final int BASIC_PAGE_SIZE = 10; - private static final String NICKNAME_WHEN_POST_CLOSING = ""; private final AlarmRepository alarmRepository; private final ReportActionAlarmRepository reportActionAlarmRepository; @@ -33,26 +31,11 @@ public List getPostAlarm(final Member member, final int page) final PageRequest pageRequest = PageRequest.of(page, BASIC_PAGE_SIZE); final Slice alarms = alarmRepository.findAllByMemberOrderByCreatedAtDesc(member, pageRequest); - return getPostAlarmResponses(alarms); - } - - private List getPostAlarmResponses(final Slice alarms) { return alarms.stream() - .map(alarm -> { - final String nickname = makeNicknameBy(alarm); - return PostAlarmResponse.of(alarm, nickname); - }) + .map(PostAlarmResponse::of) .toList(); } - private String makeNicknameBy(final Alarm alarm) { - if (alarm.getAlarmType() == AlarmType.POST_DEADLINE) { - return NICKNAME_WHEN_POST_CLOSING; - } - final Member member = alarm.getMember(); - return member.getNickname(); - } - public List getReportActionAlarms(final Member member, final int page) { final PageRequest pageRequest = PageRequest.of(page, BASIC_PAGE_SIZE); final List reportActionAlarms = reportActionAlarmRepository diff --git a/backend/src/main/java/com/votogether/domain/post/service/PostCommandService.java b/backend/src/main/java/com/votogether/domain/post/service/PostCommandService.java index 5765285dd..f30f89b73 100644 --- a/backend/src/main/java/com/votogether/domain/post/service/PostCommandService.java +++ b/backend/src/main/java/com/votogether/domain/post/service/PostCommandService.java @@ -46,6 +46,8 @@ @Service public class PostCommandService { + private static final String NICKNAME_WHEN_POST_CLOSING = ""; + private final ImageUploader imageUploader; private final PostRepository postRepository; private final CategoryRepository categoryRepository; @@ -313,6 +315,7 @@ public void closePostEarly(final Long postId, final Member loginMember) { private void publishAlarmEvent(final Long postId, final Member loginMember, final Post post) { final PostAlarmEvent postAlarmEvent = new PostAlarmEvent( loginMember, + NICKNAME_WHEN_POST_CLOSING, postId, AlarmType.POST_DEADLINE, post.getTitle() diff --git a/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java b/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java index fe00b5e88..2b17a2222 100644 --- a/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java +++ b/backend/src/main/java/com/votogether/domain/post/service/PostCommentService.java @@ -65,6 +65,7 @@ private void publishAlarmEvent(final Member loginMember, final Post post) { } final PostAlarmEvent postAlarmEvent = new PostAlarmEvent( post.getWriter(), + loginMember.getNickname(), post.getId(), AlarmType.COMMENT, post.getTitle() diff --git a/backend/src/test/java/com/votogether/domain/alarm/service/AlarmCommandServiceTest.java b/backend/src/test/java/com/votogether/domain/alarm/service/AlarmCommandServiceTest.java index c8eb2ac71..bc9a253ef 100644 --- a/backend/src/test/java/com/votogether/domain/alarm/service/AlarmCommandServiceTest.java +++ b/backend/src/test/java/com/votogether/domain/alarm/service/AlarmCommandServiceTest.java @@ -40,6 +40,7 @@ void readAlarm() { Alarm alarm = Alarm.builder() .member(member) .alarmType(AlarmType.COMMENT) + .commentWriterNickname("nickname") .targetId(1L) .detail("detail") .isChecked(false) diff --git a/backend/src/test/java/com/votogether/domain/alarm/service/AlarmEventListenerTest.java b/backend/src/test/java/com/votogether/domain/alarm/service/AlarmEventListenerTest.java index 5d271e908..36221b918 100644 --- a/backend/src/test/java/com/votogether/domain/alarm/service/AlarmEventListenerTest.java +++ b/backend/src/test/java/com/votogether/domain/alarm/service/AlarmEventListenerTest.java @@ -32,7 +32,7 @@ class AlarmEventListenerTest extends ServiceTest { void handlePostAlarmEvent() throws Exception { // given Member member = memberTestPersister.builder().save(); - PostAlarmEvent postAlarmEvent = new PostAlarmEvent(member, 1L, AlarmType.COMMENT, "title"); + PostAlarmEvent postAlarmEvent = new PostAlarmEvent(member, "nickname", 1L, AlarmType.COMMENT, "title"); // when alarmEventListener.handlePostAlarmEvent(postAlarmEvent); diff --git a/backend/src/test/java/com/votogether/test/persister/AlarmTestPersister.java b/backend/src/test/java/com/votogether/test/persister/AlarmTestPersister.java index 08a7b6a4a..40a023a42 100644 --- a/backend/src/test/java/com/votogether/test/persister/AlarmTestPersister.java +++ b/backend/src/test/java/com/votogether/test/persister/AlarmTestPersister.java @@ -21,6 +21,7 @@ public final class AlarmBuilder { private Member member; private AlarmType alarmType; + private String commentWriterNickname; private Long targetId; private String detail; private boolean isChecked; @@ -35,6 +36,11 @@ public AlarmBuilder alarmType(AlarmType alarmType) { return this; } + public AlarmBuilder commentWriterNickname(String commentWriterNickname) { + this.commentWriterNickname = commentWriterNickname; + return this; + } + public AlarmBuilder targetId(Long targetId) { this.targetId = targetId; return this; @@ -54,6 +60,7 @@ public Alarm save() { Alarm alarm = Alarm.builder() .member(member == null ? memberTestPersister.builder().save() : member) .alarmType(alarmType == null ? AlarmType.COMMENT : alarmType) + .commentWriterNickname(commentWriterNickname == null ? "nickname" : commentWriterNickname) .targetId(targetId == null ? 1L : targetId) .detail(detail == null ? "detail" : detail) .isChecked(false)