Skip to content

Commit

Permalink
Merge pull request #116 from Modagbul/feat/alarm_minsu
Browse files Browse the repository at this point in the history
AlarmHistory 생성, 조회
  • Loading branch information
seungueonn authored Dec 6, 2023
2 parents 14ada39 + 7499301 commit 952af40
Show file tree
Hide file tree
Showing 60 changed files with 778 additions and 47 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ dependencies {
//slack
implementation 'com.slack.api:slack-api-client:1.30.0'

//json
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'

}

tasks.named('test') {
Expand Down
31 changes: 31 additions & 0 deletions src/docs/asciidoc/AlarmHistory-API.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[[AlarmHistory-API]]
= AlarmHistory API

[[AlarmHistory-알림-모아보기]]
== AlarmHistory 알림 모아보기
operation::alarm-history-controller-test/get_all_alarm_history[snippets='http-request,http-response,response-fields']

== Type Category
|===
| Category | Description

| `NEW_UPLOAD`
| 신규 업로드 알림

| `FIRE`
| 불던지기 알림

| `REMIND`
| 리마인드 알림

| `APPROVE_TEAM`
| 소모임 승인

| `REJECT_TEAM`
| 소모임 반려

|===

[[AlarmHistory-알림-단건-조회하기]]
== AlarmHistory 알림 단건 조회하기
operation::alarm-history-controller-test/read_alarm_history[snippets='http-request,http-response,response-fields']
2 changes: 2 additions & 0 deletions src/docs/asciidoc/api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ include::Auth-API.adoc[]

include::Mypage-API.adoc[]

include::AlarmHistory-API.adoc[]

include::Team-API.adoc[]

include::Mission-API.adoc[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

@Service("appleSignIn")
@AllArgsConstructor
public class AppleSignInUserCase implements SignInProvider {
public class AppleSignInUseCase implements SignInProvider {

private final AppleTokenUserCase appleTokenUserCase;
private final AppleTokenUseCase appleTokenUseCase;
private final MemberMapper memberMapper;


public Member getUserData(String identityToken) {
Jws<Claims> oidcTokenJws = appleTokenUserCase.sigVerificationAndGetJws(identityToken);
Jws<Claims> oidcTokenJws = appleTokenUseCase.sigVerificationAndGetJws(identityToken);

String socialId = oidcTokenJws.getBody().getSubject();
String email = (String) oidcTokenJws.getBody().get("email");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@Component
@RequiredArgsConstructor
public class AppleTokenUserCase {
public class AppleTokenUseCase {

@Value("${oauth2.apple.clientId}")
private String appId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@Service("appleWithdraw")
@RequiredArgsConstructor
public class AppleWithdrawUserCase implements WithdrawProvider {
public class AppleWithdrawUseCase implements WithdrawProvider {

@Value("${oauth2.apple.keyId}")
private String keyId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.moing.backend.domain.auth.application.service.apple.utils;

import com.moing.backend.global.util.FeignClientConfig;
import com.moing.backend.global.utils.FeignClientConfig;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

@Service("googleSignIn")
@RequiredArgsConstructor
public class GoogleSignInUserCase implements SignInProvider {
public class GoogleSignInUseCase implements SignInProvider {

private final MemberMapper memberMapper;
private final WebClient webClient;
private final GoogleTokenUserCase googleTokenUserCase;
private final GoogleTokenUseCase googleTokenUseCase;

public Member getUserData(String accessToken) {
GoogleUserResponse googleUserResponse = webClient.get()
Expand All @@ -30,7 +30,7 @@ public Member getUserData(String accessToken) {
.block();

if (googleUserResponse != null) {
googleTokenUserCase.verifyAccessToken(googleUserResponse.getAud());
googleTokenUseCase.verifyAccessToken(googleUserResponse.getAud());
googleUserResponse.adaptResponse();
return memberMapper.createGoogleMember(googleUserResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Component
@RequiredArgsConstructor
public class GoogleTokenUserCase {
public class GoogleTokenUseCase {

@Value("${oauth2.google.appId}")
private String appId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Service("googleWithdraw")
@RequiredArgsConstructor
public class GoogleWithdrawUserCase implements WithdrawProvider {
public class GoogleWithdrawUseCase implements WithdrawProvider {

private final GoogleClient googleClient;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.moing.backend.domain.auth.application.service.google.utils;

import com.moing.backend.global.util.FeignClientConfig;
import com.moing.backend.global.utils.FeignClientConfig;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

@Service("kakaoSignIn")
@RequiredArgsConstructor
public class KakaoSignInUserCase implements SignInProvider {
public class KakaoSignInUseCase implements SignInProvider {

private final WebClient webClient;
private final MemberMapper memberMapper;
private final KakaoTokenUserCase kakaoTokenUserCase;
private final KakaoTokenUseCase kakaoTokenUseCase;

public Member getUserData(String accessToken) {

kakaoTokenUserCase.verifyAccessToken(accessToken);
kakaoTokenUseCase.verifyAccessToken(accessToken);


KakaoUserResponse kakaoUserResponse = webClient.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@Component
@RequiredArgsConstructor
public class KakaoTokenUserCase {
public class KakaoTokenUseCase {

@Value("${oauth2.kakao.appId}")
private String appId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Service("kakaoWithdraw")
@RequiredArgsConstructor
public class KakaoWithdrawUserCase implements WithdrawProvider {
public class KakaoWithdrawUseCase implements WithdrawProvider {

private final KakaoClient kakaoClient;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.moing.backend.domain.auth.application.service.kakao.utils;

import com.moing.backend.global.util.FeignClientConfig;
import com.moing.backend.global.utils.FeignClientConfig;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ public Board toBoard(Member member, TeamMember teamMember, Team team, CreateBoar
return board;
}

public GetBoardDetailResponse toBoardDetail(Board board, boolean isWriter) {
public GetBoardDetailResponse toBoardDetail(Board board, boolean isWriter, boolean writerIsDeleted) {
String nickName = writerIsDeleted ? "(알 수 없음)" : board.getWriterNickName();
return GetBoardDetailResponse.builder()
.boardId(board.getBoardId())
.title(board.getTitle())
.content(board.getContent())
.writerNickName(board.getWriterNickName())
.writerNickName(nickName)
.writerIsLeader(board.isLeader())
.writerProfileImage(board.getWriterProfileImage())
.createdDate(getFormattedDate(board.getCreatedDate()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
import com.moing.backend.domain.board.domain.entity.Board;
import com.moing.backend.domain.board.domain.service.BoardSaveService;
import com.moing.backend.domain.boardRead.application.service.CreateBoardReadUseCase;
import com.moing.backend.domain.history.application.mapper.AlarmHistoryMapper;
import com.moing.backend.domain.history.domain.entity.AlarmHistory;
import com.moing.backend.domain.history.domain.entity.AlarmType;
import com.moing.backend.domain.history.domain.entity.PagePath;
import com.moing.backend.domain.history.domain.service.AlarmHistorySaveService;
import com.moing.backend.domain.team.application.service.CheckLeaderUseCase;
import com.moing.backend.global.response.BaseServiceResponse;
import com.moing.backend.global.util.BaseService;
import com.moing.backend.global.utils.BaseService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -41,6 +46,7 @@ public CreateBoardResponse createBoard(String socialId, Long teamId, CreateBoard

//3. 알림 보내기 - 공지인 경우
sendBoardAlarmUseCase.sendNewUploadAlarm(data, board);

return new CreateBoardResponse(board.getBoardId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.moing.backend.domain.board.domain.service.BoardDeleteService;
import com.moing.backend.domain.board.exception.NotAuthByBoardException;
import com.moing.backend.global.response.BaseBoardServiceResponse;
import com.moing.backend.global.util.BaseBoardService;
import com.moing.backend.global.utils.BaseBoardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.member.domain.service.MemberGetService;
import com.moing.backend.global.response.BaseBoardServiceResponse;
import com.moing.backend.global.util.BaseBoardService;
import com.moing.backend.global.utils.BaseBoardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -35,7 +35,7 @@ public GetBoardDetailResponse getBoardDetail(String socialId, Long teamId, Long
BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId);
// 2. 읽음 처리
createBoardReadUseCase.createBoardRead(data.getTeam(), data.getMember(), data.getBoard());
return boardMapper.toBoardDetail(data.getBoard(), data.getTeamMember() == data.getBoard().getTeamMember());
return boardMapper.toBoardDetail(data.getBoard(), data.getTeamMember() == data.getBoard().getTeamMember(), data.getBoard().getTeamMember().isDeleted());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.moing.backend.domain.board.application.service;

import com.moing.backend.domain.board.domain.entity.Board;
import com.moing.backend.domain.history.application.dto.response.MemberIdAndToken;
import com.moing.backend.domain.history.application.mapper.AlarmHistoryMapper;
import com.moing.backend.domain.history.application.service.SaveMultiAlarmHistoryUseCase;
import com.moing.backend.domain.history.domain.entity.AlarmType;
import com.moing.backend.domain.history.domain.entity.PagePath;
import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.team.domain.entity.Team;
import com.moing.backend.domain.teamMember.domain.service.TeamMemberGetService;
import com.moing.backend.global.config.fcm.dto.event.FcmEvent;
import com.moing.backend.global.response.BaseServiceResponse;
import lombok.RequiredArgsConstructor;
import net.minidev.json.JSONObject;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

Expand All @@ -23,19 +29,33 @@ public class SendBoardAlarmUseCase {

private final TeamMemberGetService teamMemberGetService;
private final ApplicationEventPublisher eventPublisher;
private final SaveMultiAlarmHistoryUseCase saveAlarmHistory;
private final AlarmHistoryMapper alarmHistoryMapper;

public void sendNewUploadAlarm(BaseServiceResponse baseServiceResponse, Board board) {
Member member = baseServiceResponse.getMember();
Team team = baseServiceResponse.getTeam();

if (board.isNotice() && member.isNewUploadPush()) {
if (board.isNotice()) {
String title = NEW_NOTICE_UPLOAD_MESSAGE.title(team.getName());
String body = NEW_NOTICE_UPLOAD_MESSAGE.body(board.getTitle());
Optional<List<String>> fcmTokens = teamMemberGetService.getFcmTokensExceptMe(team.getTeamId(), member.getMemberId());
if (fcmTokens.isPresent() && !fcmTokens.get().isEmpty()) {
eventPublisher.publishEvent(new FcmEvent(title, body, fcmTokens.get()));
Optional<List<MemberIdAndToken>> memberIdAndTokens = teamMemberGetService.getMemberInfoExceptMe(team.getTeamId(), member.getMemberId());
if (memberIdAndTokens.isPresent() && !memberIdAndTokens.get().isEmpty()) {
//알림 보내기
List<String> fcmTokens = alarmHistoryMapper.getFcmTokens(memberIdAndTokens);
eventPublisher.publishEvent(new FcmEvent(title, body, fcmTokens));
//알림 저장하기
saveAlarmHistory.saveAlarmHistories(memberIdAndTokens, createIdInfo(team.getTeamId(), board.getBoardId()), title, body, team.getName(), AlarmType.NEW_UPLOAD, PagePath.NOTICE_PATH.getValue());
}
}
}

private String createIdInfo(Long teamId, Long boardId) {
JSONObject jo = new JSONObject();
jo.put("teamId", teamId);
jo.put("boardId", boardId);
return jo.toJSONString();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse;
import com.moing.backend.domain.board.exception.NotAuthByBoardException;
import com.moing.backend.global.response.BaseBoardServiceResponse;
import com.moing.backend.global.util.BaseBoardService;
import com.moing.backend.global.utils.BaseBoardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.moing.backend.domain.team.domain.entity.Team;
import com.moing.backend.domain.teamMember.domain.entity.TeamMember;
import com.moing.backend.global.entity.BaseTimeEntity;
import com.moing.backend.global.util.AesConverter;
import com.moing.backend.global.utils.AesConverter;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.moing.backend.domain.boardComment.domain.service.BoardCommentSaveService;
import com.moing.backend.domain.team.application.service.CheckLeaderUseCase;
import com.moing.backend.global.response.BaseBoardServiceResponse;
import com.moing.backend.global.util.BaseBoardService;
import com.moing.backend.global.utils.BaseBoardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.moing.backend.domain.boardComment.domain.service.BoardCommentGetService;
import com.moing.backend.domain.boardComment.exception.NotAuthByBoardCommentException;
import com.moing.backend.global.response.BaseBoardServiceResponse;
import com.moing.backend.global.util.BaseBoardService;
import com.moing.backend.global.utils.BaseBoardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.moing.backend.domain.boardComment.application.dto.response.GetBoardCommentResponse;
import com.moing.backend.domain.boardComment.domain.service.BoardCommentGetService;
import com.moing.backend.global.response.BaseBoardServiceResponse;
import com.moing.backend.global.util.BaseBoardService;
import com.moing.backend.global.utils.BaseBoardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.moing.backend.domain.board.domain.entity.Board;
import com.moing.backend.domain.teamMember.domain.entity.TeamMember;
import com.moing.backend.global.entity.BaseTimeEntity;
import com.moing.backend.global.util.AesConverter;
import com.moing.backend.global.utils.AesConverter;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand Down
Loading

0 comments on commit 952af40

Please sign in to comment.