Skip to content

Commit

Permalink
Merge branch 'feature/alarm-update' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Jan 18, 2024
2 parents dd6fcee + ede70af commit 00beaf8
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import com.koa.coremodule.fcm.application.dto.AlarmLists;
import com.koa.coremodule.fcm.application.service.AlarmUseCase;
import com.koa.coremodule.notice.application.dto.fcm.RegisterTokenRequest;
import com.koa.coremodule.notice.application.dto.fcm.SendNotificationRequest;
import com.koa.coremodule.notice.application.dto.fcm.SendCommentNotificationRequest;
import com.koa.coremodule.notice.application.dto.fcm.SendNoticeNotificationRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -33,7 +34,7 @@ public ApplicationResponse<Void> registerToken(@RequestBody RegisterTokenRequest
* 메세지 전달 ( 공지 알림 )
*/
@PostMapping("/send/notice")
public ApplicationResponse<Void> sendNoticeNotification(@RequestBody SendNotificationRequest request) {
public ApplicationResponse<Void> sendNoticeNotification(@RequestBody SendNoticeNotificationRequest request) {

alarmUseCase.sendNoticeNotification(request);
return ApplicationResponse.ok(null, "성공적으로 공지 알림을 보냈습니다.");
Expand All @@ -43,7 +44,7 @@ public ApplicationResponse<Void> sendNoticeNotification(@RequestBody SendNotific
* 메세지 전달 ( 댓글 알림 )
*/
@PostMapping("/send/comment")
public ApplicationResponse<Void> sendCommentNotification(@RequestBody SendNotificationRequest request) {
public ApplicationResponse<Void> sendCommentNotification(@RequestBody SendCommentNotificationRequest request) {

alarmUseCase.sendCommentNotification(request);
return ApplicationResponse.ok(null, "성공적으로 댓글 알림을 보냈습니다.");
Expand All @@ -53,7 +54,7 @@ public ApplicationResponse<Void> sendCommentNotification(@RequestBody SendNotifi
* 메세지 전달 ( 대댓글 알림 )
*/
@PostMapping("/send/recomment")
public ApplicationResponse<Void> sendReCommentNotification(@RequestBody SendNotificationRequest request) {
public ApplicationResponse<Void> sendReCommentNotification(@RequestBody SendCommentNotificationRequest request) {

alarmUseCase.sendReCommentNotification(request);
return ApplicationResponse.ok(null, "성공적으로 대댓글 알림을 보냈습니다.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
public class AlarmLists {

private Long alarmId;
private Long noticeId;
private Long commentId;
private String title;
private String content;
private LocalDateTime date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.google.firebase.messaging.FirebaseMessagingException;
import com.google.firebase.messaging.Message;
import com.google.firebase.messaging.Notification;
import com.koa.coremodule.comment.domain.entity.Comment;
import com.koa.coremodule.comment.domain.service.CommentQueryService;
import com.koa.coremodule.fcm.application.dto.AlarmLists;
import com.koa.coremodule.fcm.domain.entity.Alarm;
import com.koa.coremodule.fcm.domain.entity.AlarmType;
Expand All @@ -12,7 +14,8 @@
import com.koa.coremodule.fcm.domain.service.AlarmSaveService;
import com.koa.coremodule.member.domain.entity.Member;
import com.koa.coremodule.member.domain.utils.MemberUtils;
import com.koa.coremodule.notice.application.dto.fcm.SendNotificationRequest;
import com.koa.coremodule.notice.application.dto.fcm.SendCommentNotificationRequest;
import com.koa.coremodule.notice.application.dto.fcm.SendNoticeNotificationRequest;
import com.koa.coremodule.notice.domain.entity.Notice;
import com.koa.coremodule.notice.domain.entity.ViewType;
import com.koa.coremodule.notice.domain.service.NoticeQueryService;
Expand All @@ -35,6 +38,7 @@ public class AlarmUseCase {
private final AlarmSaveService alarmSaveService;
private final AlarmQueryService alarmQueryService;
private final NoticeQueryService noticeQueryService;
private final CommentQueryService commentQueryService;

private final static String NOTICE_TITLE = "새로운 공지를 확인하세요";
private final static String COMMENT_TITLE = "새로운 댓글이 달렸어요";
Expand All @@ -48,7 +52,7 @@ public void registerFcmToken(String token) {
log.info("회원의 fcm 토큰이 등록되었습니다.");
}

public void sendNoticeNotification(SendNotificationRequest request) {
public void sendNoticeNotification(SendNoticeNotificationRequest request) {

List<Member> members = findAllMember();

Expand Down Expand Up @@ -84,9 +88,11 @@ public void sendNoticeNotification(SendNotificationRequest request) {
}
}

public void sendCommentNotification(SendNotificationRequest request) {
public void sendCommentNotification(SendCommentNotificationRequest request) {

Member member = findNoticeMember(request.noticeId());
Comment comment = commentQueryService.getCommentById(request.commentId());
Notice noticeInfo = comment.getNotice();
Member member = findNoticeMember(noticeInfo.getId());

Notification notification = Notification.builder()
.setTitle(COMMENT_TITLE)
Expand All @@ -102,13 +108,12 @@ public void sendCommentNotification(SendNotificationRequest request) {
try {
firebaseMessaging.send(message);

Notice notice = noticeQueryService.findByNoticeId(request.noticeId());
// 알람 테이블 저장
Alarm alarm = Alarm.builder()
.type(AlarmType.COMMENT)
.title(COMMENT_TITLE)
.content(request.content())
.notice(notice)
.comment(comment)
.build();
alarmSaveService.save(alarm);

Expand All @@ -118,13 +123,16 @@ public void sendCommentNotification(SendNotificationRequest request) {
}
}

public void sendReCommentNotification(SendNotificationRequest request) {
public void sendReCommentNotification(SendCommentNotificationRequest request) {

Member memberRequest = memberUtils.getAccessMember();
List<Member> members = new ArrayList<>();

Member noticeMember = findNoticeMember(request.noticeId());
Member commentMember = findCommentMember(memberRequest.getId());
Comment comment = commentQueryService.getCommentById(request.commentId());
Notice noticeInfo = comment.getNotice();
Member noticeMember = findNoticeMember(noticeInfo.getId());

Comment parentComment = commentQueryService.getCommentById(comment.getParentId());
Member commentMember = findCommentMember(parentComment.getId());
members.add(noticeMember);
members.add(commentMember);

Expand All @@ -143,13 +151,12 @@ public void sendReCommentNotification(SendNotificationRequest request) {
try {
firebaseMessaging.send(message);

Notice notice = noticeQueryService.findByNoticeId(request.noticeId());
// 알람 테이블 저장
Alarm alarm = Alarm.builder()
.type(AlarmType.RECOMMENT)
.title(COMMENT_TITLE)
.content(request.content())
.notice(notice)
.comment(comment)
.build();
alarmSaveService.save(alarm);

Expand Down Expand Up @@ -186,6 +193,12 @@ public List<AlarmLists> getAlarmLists() {
.viewYn(isViewed) // viewYn을 조회 여부에 따라 설정
.build();

if (a.getNotice() != null) {
alarmLists.setNoticeId(a.getNotice().getId());
} else if (a.getComment() != null) {
alarmLists.setCommentId(a.getComment().getId());
}

result.add(alarmLists);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.koa.coremodule.fcm.domain.entity;

import com.koa.commonmodule.domain.BaseEntity;
import com.koa.coremodule.comment.domain.entity.Comment;
import com.koa.coremodule.member.domain.entity.Member;
import com.koa.coremodule.notice.domain.entity.Notice;
import jakarta.persistence.*;
Expand Down Expand Up @@ -30,4 +31,8 @@ public class Alarm extends BaseEntity {
@JoinColumn(name = "notice_id")
private Notice notice;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "comment_id")
private Comment comment;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.koa.coremodule.notice.application.dto.fcm;

public record SendCommentNotificationRequest(String content, Long commentId) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.koa.coremodule.notice.application.dto.fcm;

public record SendNoticeNotificationRequest(String content, Long noticeId) {

}

This file was deleted.

0 comments on commit 00beaf8

Please sign in to comment.