Skip to content

Commit

Permalink
Merge pull request #213 from Modagbul/main
Browse files Browse the repository at this point in the history
[release] MNG-01 , MNG-02
  • Loading branch information
minsu20 authored Jan 31, 2024
2 parents ee36bd2 + 1bfb162 commit bbeb621
Show file tree
Hide file tree
Showing 44 changed files with 564 additions and 415 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.moing.backend.domain.alarm.application;

import com.moing.backend.domain.history.application.mapper.AlarmHistoryMapper;
import com.moing.backend.domain.history.application.service.SaveMultiAlarmHistoryUseCase;
import com.moing.backend.global.config.fcm.dto.event.MultiFcmEvent;
import com.moing.backend.global.config.fcm.dto.request.MultiRequest;
import com.moing.backend.global.config.fcm.service.MultiMessageSender;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;


@Component
@RequiredArgsConstructor
public class MultiAlarmEventUseCase {

private final MultiMessageSender multiMessageSender;
private final SaveMultiAlarmHistoryUseCase saveMultiAlarmHistoryUseCase;

@Async
@EventListener
public void onMultiAlarmEvent(MultiFcmEvent event) {
if (event.getIdAndTokensByPush().isPresent() && !event.getIdAndTokensByPush().get().isEmpty()) {
multiMessageSender.send(new MultiRequest(event.getIdAndTokensByPush().get(), event.getTitle(), event.getBody(), event.getIdInfo(), event.getName(), event.getAlarmType(), event.getPath()));
}
if (event.getIdAndTokensBySave().isPresent() && !event.getIdAndTokensBySave().get().isEmpty()) {
saveMultiAlarmHistoryUseCase.saveAlarmHistories(AlarmHistoryMapper.getMemberIds(event.getIdAndTokensBySave().get()), event.getIdInfo(), event.getTitle(), event.getBody(), event.getName(), event.getAlarmType(), event.getPath());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.moing.backend.domain.alarm.application;

import com.moing.backend.domain.history.application.service.SaveSingleAlarmHistoryUseCase;
import com.moing.backend.global.config.fcm.dto.event.SingleFcmEvent;
import com.moing.backend.global.config.fcm.dto.request.SingleRequest;
import com.moing.backend.global.config.fcm.service.SingleMessageSender;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;


@Component
@RequiredArgsConstructor
public class SingleAlarmEventUseCase {

private final SingleMessageSender singleMessageSender;
private final SaveSingleAlarmHistoryUseCase saveSingleAlarmHistoryUseCase;

@Async
@EventListener
public void onSingleAlarmEvent(SingleFcmEvent event) {
if (event.getMember().isFirePush() && !event.getMember().isSignOut()) { //알림 on, 로그아웃 안함
singleMessageSender.send(new SingleRequest(event.getMember().getFcmToken(), event.getTitle(), event.getBody(), event.getMember().getMemberId(), event.getIdInfo(), event.getName(), event.getAlarmType(), event.getPath()));
}
saveSingleAlarmHistoryUseCase.saveAlarmHistory(event.getMember().getMemberId(), event.getIdInfo(), event.getTitle(), event.getBody(), event.getName(), event.getAlarmType(), event.getPath());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public Member getUserData(String identityToken) {
String socialId = oidcTokenJws.getBody().getSubject();
String email = (String) oidcTokenJws.getBody().get("email");

return memberMapper.createAppleMember(socialId, email);
return MemberMapper.createAppleMember(socialId, email);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
@RequiredArgsConstructor
public class GoogleSignInUseCase implements SignInProvider {

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

Expand All @@ -32,7 +31,7 @@ public Member getUserData(String accessToken) {
if (googleUserResponse != null) {
googleTokenUseCase.verifyAccessToken(googleUserResponse.getAud());
googleUserResponse.adaptResponse();
return memberMapper.createGoogleMember(googleUserResponse);
return MemberMapper.createGoogleMember(googleUserResponse);
}
throw new TokenInvalidException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
public class KakaoSignInUseCase implements SignInProvider {

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

public Member getUserData(String accessToken) {
Expand All @@ -35,6 +34,6 @@ public Member getUserData(String accessToken) {
.block();
kakaoUserResponse.adaptResponse();

return memberMapper.createKakaoMember(kakaoUserResponse);
return MemberMapper.createKakaoMember(kakaoUserResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
public class BlockCreateUseCase {

private final MemberGetService memberGetService;
private final BoardGetService boardGetService;
private final MissionArchiveQueryService missionArchiveQueryService;

private final BlockSaveService blockSaveService;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
public class BlockDeleteUseCase {

private final MemberGetService memberGetService;
private final BoardGetService boardGetService;
private final MissionArchiveQueryService missionArchiveQueryService;

private final BlockDeleteService blockDeleteService;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package com.moing.backend.domain.block.application.service;

import com.moing.backend.domain.block.application.mapper.BlockMapper;
import com.moing.backend.domain.block.domain.service.BlockDeleteService;
import com.moing.backend.domain.block.domain.service.BlockQueryService;
import com.moing.backend.domain.block.domain.service.BlockSaveService;
import com.moing.backend.domain.board.domain.service.BoardGetService;
import com.moing.backend.domain.member.domain.service.MemberGetService;
import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService;
import com.moing.backend.domain.report.application.dto.BlockMemberRes;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -18,9 +13,6 @@
public class BlockReadUseCase {

private final MemberGetService memberGetService;
private final BoardGetService boardGetService;
private final MissionArchiveQueryService missionArchiveQueryService;

private final BlockQueryService blockQueryService;

/**
Expand All @@ -31,10 +23,10 @@ public List<Long> getMyBlockList(String socialId) {

return blockQueryService.getBlockLists(memberId);
}
public List<BlockMemberRes> getMyBlockInfoList(String socialId) {
Long memberId = memberGetService.getMemberBySocialId(socialId).getMemberId();
public List<BlockMemberRes> getMyBlockInfoList(String socialId) {
Long memberId = memberGetService.getMemberBySocialId(socialId).getMemberId();

return blockQueryService.getBlockInfoLists(memberId);
}
return blockQueryService.getBlockInfoLists(memberId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@RequiredArgsConstructor
public class BoardMapper {

public Board toBoard(TeamMember teamMember, Team team, CreateBoardRequest createBoardRequest, boolean isLeader) {
public static Board toBoard(TeamMember teamMember, Team team, CreateBoardRequest createBoardRequest, boolean isLeader) {
Board board = Board.builder()
.title(createBoardRequest.getTitle())
.content(createBoardRequest.getContent())
Expand All @@ -31,7 +31,7 @@ public Board toBoard(TeamMember teamMember, Team team, CreateBoardRequest create
return board;
}

public GetBoardDetailResponse toBoardDetail(Board board, boolean isWriter, boolean writerIsDeleted) {
public static GetBoardDetailResponse toBoardDetail(Board board, boolean isWriter, boolean writerIsDeleted) {
String nickName = writerIsDeleted ? "(알 수 없음)" : board.getTeamMember().getMember().getNickName();
String writerProfileImage = writerIsDeleted ? null : board.getTeamMember().getMember().getProfileImage();
Long writerId = writerIsDeleted ? 0L : board.getTeamMember().getMember().getMemberId();
Expand All @@ -49,7 +49,7 @@ public GetBoardDetailResponse toBoardDetail(Board board, boolean isWriter, boole
.build();
}

public String getFormattedDate(LocalDateTime localDateTime) {
public static String getFormattedDate(LocalDateTime localDateTime) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm");
return localDateTime.format(formatter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class CreateBoardUseCase {

private final BoardSaveService boardSaveService;
private final CheckLeaderUseCase checkLeaderUseCase;
private final BoardMapper boardMapper;
private final CreateBoardReadUseCase createBoardReadUseCase;
private final BaseService baseService;
private final SendBoardAlarmUseCase sendBoardAlarmUseCase;
Expand All @@ -39,7 +38,7 @@ public CreateBoardResponse createBoard(String socialId, Long teamId, CreateBoard
//1, 게시글 생성, 저장
BaseServiceResponse data=baseService.getCommonData(socialId, teamId);
boolean isLeader = checkLeaderUseCase.isTeamLeader(data.getMember(), data.getTeam()); //작성자 리더 여부
Board board=boardSaveService.saveBoard(boardMapper.toBoard(data.getTeamMember(), data.getTeam(), createBoardRequest, isLeader));
Board board=boardSaveService.saveBoard(BoardMapper.toBoard(data.getTeamMember(), data.getTeam(), createBoardRequest, isLeader));

//2. 읽음 처리 - 생성한 사람은 무조건 읽음
createBoardReadUseCase.createBoardRead(data.getTeam(), data.getMember(), board);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class GetBoardUseCase {


private final BaseBoardService baseBoardService;
private final BoardMapper boardMapper;
private final MemberGetService memberGetService;
private final CreateBoardReadUseCase createBoardReadUseCase;
private final BoardGetService boardGetService;
Expand All @@ -34,7 +33,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(), data.getBoard().getTeamMember().isDeleted());
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
Expand Up @@ -10,7 +10,7 @@
@Component
@RequiredArgsConstructor
public class BoardCommentMapper {
public BoardComment toBoardComment(TeamMember teamMember, Board board, CreateBoardCommentRequest createBoardCommentRequest, boolean isLeader) {
public static BoardComment toBoardComment(TeamMember teamMember, Board board, CreateBoardCommentRequest createBoardCommentRequest, boolean isLeader) {
BoardComment boardComment= BoardComment.builder()
.content(createBoardCommentRequest.getContent())
.isLeader(isLeader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
public class CreateBoardCommentUseCase {

private final BoardCommentSaveService boardCommentSaveService;
private final BoardCommentMapper boardCommentMapper;
private final BaseBoardService baseBoardService;
private final CheckLeaderUseCase checkLeaderUseCase;

Expand All @@ -30,7 +29,7 @@ public CreateBoardCommentResponse createBoardComment(String socialId, Long teamI
// 1. 게시글 댓글 생성
BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId);
boolean isLeader = checkLeaderUseCase.isTeamLeader(data.getMember(), data.getTeam());
BoardComment boardComment = boardCommentSaveService.saveBoardComment(boardCommentMapper.toBoardComment(data.getTeamMember(), data.getBoard(), createBoardCommentRequest, isLeader));
BoardComment boardComment = boardCommentSaveService.saveBoardComment(BoardCommentMapper.toBoardComment(data.getTeamMember(), data.getBoard(), createBoardCommentRequest, isLeader));
// 2. 게시글 댓글 개수 증가
data.getBoard().incrComNum();
return new CreateBoardCommentResponse(boardComment.getBoardCommentId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Component
public class BoardReadMapper {
public BoardRead toBoardRead(Team team, Member member){
public static BoardRead toBoardRead(Team team, Member member){
BoardRead boardRead=new BoardRead();
boardRead.updateTeam(team);
boardRead.updateMember(member);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
@RequiredArgsConstructor
public class CreateBoardReadUseCase {

private final BoardReadMapper boardReadMapper;
private final BoardReadSaveService boardReadSaveService;

public void createBoardRead(Team team, Member member, Board board){
BoardRead boardRead = boardReadMapper.toBoardRead(team, member);
BoardRead boardRead = BoardReadMapper.toBoardRead(team, member);
boardReadSaveService.saveBoardRead(board, boardRead);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@

public interface BoardReadRepository extends JpaRepository<BoardRead, Long> {

@Lock(LockModeType.PESSIMISTIC_WRITE)
List<BoardRead> findBoardReadByBoardAndMemberAndTeam(Board board, Member member, Team team);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ public class BoardReadSaveService {


public void saveBoardRead(Board board, BoardRead boardRead) {
synchronized (this) {
List<BoardRead> existingBoardReads = boardReadRepository.findBoardReadByBoardAndMemberAndTeam(board, boardRead.getMember(), boardRead.getTeam());
List<BoardRead> existingBoardReads = boardReadRepository.findBoardReadByBoardAndMemberAndTeam(board, boardRead.getMember(), boardRead.getTeam());

if (existingBoardReads.isEmpty()) {
boardRead.updateBoard(board);
boardReadRepository.save(boardRead);
}
if (existingBoardReads.isEmpty()) {
boardRead.updateBoard(board);
boardReadRepository.save(boardRead);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import com.moing.backend.domain.mission.domain.entity.Mission;
import com.moing.backend.domain.mission.domain.entity.constant.MissionType;
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.SingleFcmEvent;
import com.moing.backend.global.config.fcm.service.FcmService;
import lombok.RequiredArgsConstructor;
import net.minidev.json.JSONObject;
import org.springframework.context.ApplicationEventPublisher;
Expand All @@ -24,9 +22,7 @@
@RequiredArgsConstructor
public class FireThrowAlarmUseCase {

private final FcmService fcmService;
private final ApplicationEventPublisher eventPublisher;
private final TeamMemberGetService teamMemberGetService;

public void sendFireThrowAlarm(Member throwMember, Member receiveMember, Team team, Mission mission) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@RequiredArgsConstructor
public class AlarmHistoryMapper {

public AlarmHistory toAlarmHistory(AlarmType type, String path, String idInfo, Long receiverId, String title, String body, String name){
public static AlarmHistory toAlarmHistory(AlarmType type, String path, String idInfo, Long receiverId, String title, String body, String name){
return AlarmHistory.builder()
.type(type)
.path(path)
Expand Down Expand Up @@ -50,7 +50,7 @@ public static List<Long> getMemberIds(List<MemberIdAndToken> memberIdAndTokens)
.collect(Collectors.toList());
}

public List<AlarmHistory> getAlarmHistories(String idInfo, List<Long> memberIds, String title, String body, String teamName, AlarmType alarmType, String path) {
public static List<AlarmHistory> getAlarmHistories(String idInfo, List<Long> memberIds, String title, String body, String teamName, AlarmType alarmType, String path) {
return memberIds.stream()
.map(memberId -> toAlarmHistory(alarmType, path, idInfo, memberId, title, body, teamName))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
@RequiredArgsConstructor
public class SaveMultiAlarmHistoryUseCase {

private final AlarmHistoryMapper alarmHistoryMapper;
private final AlarmHistorySaveService alarmHistorySaveService;

@Async
public void saveAlarmHistories(List<Long> memberIds, String idInfo, String title, String body, String name, AlarmType alarmType, String path) {
List<AlarmHistory> alarmHistories = alarmHistoryMapper.getAlarmHistories(idInfo, memberIds, title, body, name, alarmType, path);
List<AlarmHistory> alarmHistories = AlarmHistoryMapper.getAlarmHistories(idInfo, memberIds, title, body, name, alarmType, path);
alarmHistorySaveService.saveAlarmHistories(alarmHistories);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
@RequiredArgsConstructor
public class SaveSingleAlarmHistoryUseCase {

private final AlarmHistoryMapper alarmHistoryMapper;
private final AlarmHistorySaveService alarmHistorySaveService;

@Async
public void saveAlarmHistory(Long memberId, String idInfo, String title, String body, String name, AlarmType alarmType, String path) {
AlarmHistory alarmHistory = alarmHistoryMapper.toAlarmHistory(alarmType, path, idInfo, memberId, title, body, name);
AlarmHistory alarmHistory = AlarmHistoryMapper.toAlarmHistory(alarmType, path, idInfo, memberId, title, body, name);
alarmHistorySaveService.saveAlarmHistory(alarmHistory);
}
}
Loading

0 comments on commit bbeb621

Please sign in to comment.