Skip to content

Commit

Permalink
Merge pull request #56 from KOA-TF/feature/fcm-save
Browse files Browse the repository at this point in the history
Feature/alarm
  • Loading branch information
Jeongh00 authored Dec 6, 2023
2 parents ce0edc7 + e66d19d commit a95889e
Show file tree
Hide file tree
Showing 16 changed files with 597 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package com.koa.apimodule.command.api;

import com.koa.commonmodule.common.ApplicationResponse;
import com.koa.coremodule.fcm.application.dto.AlarmLists;
import com.koa.coremodule.fcm.application.service.AlarmUseCase;
import com.koa.coremodule.fcm.domain.entity.Alarm;
import com.koa.coremodule.fcm.domain.entity.AlarmType;
import com.koa.coremodule.fcm.domain.repository.AlarmRepository;
import com.koa.coremodule.member.domain.entity.Authority;
import com.koa.coremodule.member.domain.entity.Member;
import com.koa.coremodule.member.domain.repository.MemberRepository;
import com.koa.coremodule.notice.application.dto.fcm.RegisterTokenRequest;
import com.koa.coremodule.notice.application.dto.fcm.SendNotificationRequest;
import com.koa.coremodule.notice.domain.entity.Curriculum;
import com.koa.coremodule.notice.domain.entity.Notice;
import com.koa.coremodule.notice.domain.entity.NoticeTeam;
import com.koa.coremodule.notice.domain.repository.CurriculumRepository;
import com.koa.coremodule.notice.domain.repository.NoticeRepository;
import com.koa.coremodule.notice.domain.repository.NoticeTeamRepository;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/alarm")
public class AlarmController {

private final AlarmUseCase alarmUseCase;

private final MemberRepository memberRepository;
private final NoticeTeamRepository noticeTeamRepository;
private final CurriculumRepository curriculumRepository;
private final NoticeRepository noticeRepository;
private final AlarmRepository alarmRepository;

@PostConstruct
public void test() {
final Member member = Member.builder()
.authority(Authority.MEMBER)
.email("[email protected]")
.password("001215")
.name("안정후")
.build();
memberRepository.save(member);
final Curriculum curriculum = Curriculum.builder()
.curriculumName("기업프로젝트")
.build();
curriculumRepository.save(curriculum);
final NoticeTeam noticeTeam = NoticeTeam.builder()
.teamName("경영총괄팀")
.build();
noticeTeamRepository.save(noticeTeam);
final Notice notice = Notice.builder()
.member(member)
.title("sampletitle")
.content("samplecontent")
.curriculum(curriculum)
.build();
noticeRepository.save(notice);
final Notice notice2 = Notice.builder()
.member(member)
.title("sampletitle22")
.content("samplecontent22")
.curriculum(curriculum)
.build();
noticeRepository.save(notice2);
final Alarm alarm = Alarm.builder().type(AlarmType.NOTICE).title("공지알림").content("notice content").build();
alarmRepository.save(alarm);
final Alarm alar2 = Alarm.builder().type(AlarmType.COMMENT).title("댓글알림").content("comment content").build();
alarmRepository.save(alar2);
}


/**
* 토큰 등록
*/
@PostMapping("/register")
public ApplicationResponse<Void> registerToken(@RequestBody RegisterTokenRequest request) {

alarmUseCase.registerFcmToken(request.fcmToken());
return ApplicationResponse.ok(null, "성공적으로 토큰이 등록되었습니다.");
}

/**
* 메세지 전달 ( 공지 알림 )
*/
@PostMapping("/send/notice")
public ApplicationResponse<Void> sendNoticeNotification(@RequestBody SendNotificationRequest request) {

alarmUseCase.sendNoticeNotification(request);
return ApplicationResponse.ok(null, "성공적으로 공지 알림을 보냈습니다.");
}

/**
* 메세지 전달 ( 댓글 알림 )
*/
@PostMapping("/send/comment")
public ApplicationResponse<Void> sendCommentNotification(@RequestBody SendNotificationRequest request) {

alarmUseCase.sendCommentNotification(request);
return ApplicationResponse.ok(null, "성공적으로 댓글 알림을 보냈습니다.");
}

/**
* 메세지 전달 ( 대댓글 알림 )
*/
@PostMapping("/send/recomment")
public ApplicationResponse<Void> sendReCommentNotification(@RequestBody SendNotificationRequest request) {

alarmUseCase.sendReCommentNotification(request);
return ApplicationResponse.ok(null, "성공적으로 대댓글 알림을 보냈습니다.");
}


/**
* 알림 목록 조회 ( 조회 여부까지 포함 )
*/
@GetMapping("/lists")
public ApplicationResponse<List<AlarmLists>> getAlarmLists() {

List<AlarmLists> lists = alarmUseCase.getAlarmLists();
return ApplicationResponse.ok(lists, "성공적으로 알림 목록을 조회했습니다.");
}

/**
* 링크 누를 시 api 호출 필요 ( 조회 여부 판단 )
*/
@PostMapping("/view")
public ApplicationResponse<Void> saveAlarmView(Long alarmId) {

alarmUseCase.saveAlarmView(alarmId);
return ApplicationResponse.ok(null, "성공적으로 조회 기록을 적재하였습니다.");
}

/**
* 알림 삭제
*/
@DeleteMapping("/delete")
public ApplicationResponse<Void> deleteAlarm(Long alarmId) {

alarmUseCase.deleteAlarm(alarmId);
return ApplicationResponse.ok(null, "성공적으로 알림을 삭제했습니다.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.koa.coremodule.auth.application.service.AuthUseCase;
import com.koa.coremodule.auth.application.service.LogoutUseCase;
import com.koa.coremodule.member.domain.entity.Authority;
import com.koa.coremodule.notice.application.service.NoticeFcmUseCase;
import com.koa.coremodule.fcm.application.service.AlarmUseCase;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
Expand All @@ -20,7 +20,7 @@ public class AuthController {

private final AuthUseCase authUseCase;
private final LogoutUseCase logoutUseCase;
private final NoticeFcmUseCase noticeFcmUseCase;
private final AlarmUseCase alarmUseCase;

@GetMapping("/login/{authority}")
public ApplicationResponse<AuthResponse> authLogin(@PathVariable Authority authority, @RequestParam String email, @RequestParam String password){
Expand All @@ -39,7 +39,7 @@ public ApplicationResponse<Void> logout(@RequestHeader(AuthConsts.REFRESH_TOKEN_
logoutUseCase.logoutAccessUser(refreshToken);

// 로그아웃 시 토큰 제거
noticeFcmUseCase.deleteFcmToken();
alarmUseCase.deleteFcmToken();

return ApplicationResponse.ok(null);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public enum Error {
VOTE_ITEM_NOT_FOUND("투표 항목이 존재하지 않습니다.", 400),
VOTE_ITEM_RECORD_NOT_FOUND("투표 항목 참여자가 존재하지 않습니다.", 400),

// ALARM
ALARM_NOT_FOUND("알림이 존재하지 않습니다.", 400),

// MEMBER
MEMBER_NOT_FOUND("사용자를 찾을 수 없습니다.", 2000),
WRONG_PASSWORD("비밀번호가 틀렸습니다.", 2001),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.koa.coremodule.fcm.application.dto;

import lombok.Builder;
import lombok.Data;
import lombok.extern.jackson.Jacksonized;

import java.time.LocalDateTime;

@Data
@Builder
@Jacksonized
public class AlarmLists {

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

}
Loading

0 comments on commit a95889e

Please sign in to comment.