Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

댓글 작성 시 알림 추가 기능 버그 수정 #803

Merged
merged 2 commits into from
Oct 19, 2023
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 @@ -5,6 +5,7 @@

public record PostAlarmEvent(
Member member,
String commentWriterNickname,
Long targetId,
AlarmType alarmType,
String detail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -33,26 +31,11 @@ public List<PostAlarmResponse> getPostAlarm(final Member member, final int page)
final PageRequest pageRequest = PageRequest.of(page, BASIC_PAGE_SIZE);
final Slice<Alarm> alarms = alarmRepository.findAllByMemberOrderByCreatedAtDesc(member, pageRequest);

return getPostAlarmResponses(alarms);
}

private List<PostAlarmResponse> getPostAlarmResponses(final Slice<Alarm> 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<ReportActionAlarmResponse> getReportActionAlarms(final Member member, final int page) {
final PageRequest pageRequest = PageRequest.of(page, BASIC_PAGE_SIZE);
final List<ReportActionAlarm> reportActionAlarms = reportActionAlarmRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void readAlarm() {
Alarm alarm = Alarm.builder()
.member(member)
.alarmType(AlarmType.COMMENT)
.commentWriterNickname("nickname")
.targetId(1L)
.detail("detail")
.isChecked(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand Down
Loading