Skip to content

Commit

Permalink
Merge pull request #72 from KOA-TF/develop
Browse files Browse the repository at this point in the history
Develop to Main
  • Loading branch information
Jeongh00 authored Jan 25, 2024
2 parents ae6e220 + e44b80f commit 89b4789
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 30 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ jobs:
- name: 저장소 Checkout
uses: actions/checkout@v3

- name: Create JSON file
id: create-json
uses: jsdaniell/[email protected]
with:
name: "kusitms-plus-firebase-adminsdk-krn6f-5ef95443a1.json"
json: ${{ secrets.FIREBASE_JSON }}

- name: Move JSON file to specified directory
run: mv kusitms-plus-firebase-adminsdk-krn6f-5ef95443a1.json ./common-module/src/main/resources/kusitms-plus-firebase-adminsdk-krn6f-5ef95443a1.json
shell: bash

- name: make application yml
run: |
cd ./api-module/src/main/resources
Expand Down Expand Up @@ -55,6 +66,8 @@ jobs:
key: ${{ secrets.PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
touch ./docker-compose.yml
echo "${{ secrets.DOCKER_COMPOSE }}" > ./docker-compose.yml
sudo docker stop $(sudo docker ps -a -q)
sudo docker rm -f $(sudo docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_IMG }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ out/

api-module/src/main/resources/application-prod.yml
api-module/src/main/resources/application-local.yml
common-module/src/main/resources
docker-compose.yml
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 @@ -25,6 +25,7 @@ public enum Error {

// ALARM
ALARM_NOT_FOUND("알림이 존재하지 않습니다.", 400),
DUPLICATE_ALARM("이미 조회 완료된 알림입니다.", 400),

// MEMBER
MEMBER_NOT_FOUND("사용자를 찾을 수 없습니다.", 2000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
@Jacksonized
public class AttendInfo {

private Long curriculumId;
private String curriculumName;
private Boolean isAttended;
private String date;
private String time;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ public static AttendList toResponse(AttendListProjection projection) {
}

public static AttendInfo toInfoResponse(Boolean isAttended, Curriculum curriculum) {

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
String formattedDate = curriculum.getStartTime().format(formatter);

AttendInfo attendInfo = AttendInfo.builder()
.curriculumId(curriculum.getId())
.curriculumName(curriculum.getCurriculumName())
.isAttended(isAttended)
.date(curriculum.getCreatedAt().format(DATE_FORMATTER))
.time(curriculum.getCreatedAt().format(TIME_FORMATTER))
.date(formattedDate)
.build();
return attendInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@RequiredArgsConstructor
public class AttendSaveService {
Expand All @@ -28,7 +30,23 @@ public Attend saveAttend(Long curriculumId, Long memberId) {

Member member = memberQueryService.findMemberById(memberId);
Curriculum curriculum = curriculumQueryService.findCurriculumById(curriculumId);
final Attend attend = Attend.builder().curriculum(curriculum).member(member).status(AttendStatus.출석).build();

LocalDateTime currentTime = LocalDateTime.now();
final Attend attend;

if (currentTime.isAfter(curriculum.getStartTime())) {
attend = Attend.builder()
.curriculum(curriculum)
.member(member)
.status(AttendStatus.지각)
.build();
} else {
attend = Attend.builder()
.curriculum(curriculum)
.member(member)
.status(AttendStatus.출석)
.build();
}

return attendRepository.save(attend);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import lombok.Data;
import lombok.extern.jackson.Jacksonized;

import java.time.LocalDateTime;

@Data
@Builder
@Jacksonized
public class AlarmLists {

private Long alarmId;
private Long noticeId;
private Long commentId;
private String title;
private String content;
private LocalDateTime date;
private String date;
private Boolean viewYn;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import com.google.firebase.messaging.FirebaseMessagingException;
import com.google.firebase.messaging.Message;
import com.google.firebase.messaging.Notification;
import com.koa.commonmodule.exception.Error;
import com.koa.coremodule.attend.domain.exception.AttendException;
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 +16,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 @@ -21,6 +26,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -35,9 +42,12 @@ 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 = "새로운 댓글이 달렸어요";
private static final DateTimeFormatter LAST_DATE_FORMATTER = DateTimeFormatter.ofPattern("yy/MM/dd HH:mm");
private static final DateTimeFormatter NOW_DATE_FORMATTER = DateTimeFormatter.ofPattern("MM/dd HH:mm");

public void registerFcmToken(String token) {

Expand All @@ -48,7 +58,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 +94,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 +114,13 @@ 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)
.notice(noticeInfo)
.comment(comment)
.build();
alarmSaveService.save(alarm);

Expand All @@ -118,13 +130,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 +158,13 @@ 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)
.notice(noticeInfo)
.comment(comment)
.build();
alarmSaveService.save(alarm);

Expand All @@ -172,20 +187,31 @@ public List<AlarmLists> getAlarmLists() {

// 조회 여부 확인
for (AlarmView al : alarmViews) {
if (a.getId().equals(al.getId())) {
if (a.getId().equals(al.getAlarm().getId())) {
isViewed = true;
break;
}
}

DateTimeFormatter selectedFormatter = LocalDate.now().getYear() == a.getCreatedAt().getYear()
? NOW_DATE_FORMATTER
: LAST_DATE_FORMATTER;

AlarmLists alarmLists = AlarmLists.builder()
.alarmId(a.getId())
.title(a.getTitle())
.content(a.getContent())
.date(a.getCreatedAt())
.date(a.getCreatedAt().format(selectedFormatter))
.viewYn(isViewed) // viewYn을 조회 여부에 따라 설정
.build();

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

result.add(alarmLists);
}

Expand All @@ -198,6 +224,11 @@ public void saveAlarmView(Long alarmId) {
Member member = alarmQueryService.findMember(memberRequest.getId());
Alarm alarm = alarmQueryService.findAlarmById(alarmId);

//이미 적재 되어있으면 예외처리
if (alarmQueryService.existsByAlarmIdAndMemberId(alarm.getId(), member.getId())) {
throw new AttendException(Error.DUPLICATE_ALARM);
}

AlarmView alarmView = AlarmView.builder().alarm(alarm).view(ViewType.VIEWED).member(member).build();
alarmSaveService.saveAlarmView(alarmView);
}
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
Expand Up @@ -2,9 +2,14 @@

import com.koa.coremodule.fcm.domain.entity.Alarm;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface AlarmRepository extends JpaRepository<Alarm, Long> {

void deleteAlarmById(Long alarmId);

@Query("SELECT COUNT(a) > 0 FROM AlarmView a WHERE a.alarm.id = :alarmId AND a.member.id = :memberId")
boolean existsByAlarmIdAndMemberId(@Param("alarmId") Long alarmId, @Param("memberId") Long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public Member findNoticeMember(Long noticeId) {
return findMember(memberId);
}

public Boolean existsByAlarmIdAndMemberId(Long alarmId, Long memberId) {

return alarmRepository.existsByAlarmIdAndMemberId(alarmId, memberId);
}

public List<Member> findAllMember() {
return memberRepository.findAll();
}
Expand Down
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 89b4789

Please sign in to comment.