diff --git a/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java index e5d11c0e..c6e401c0 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java @@ -5,18 +5,8 @@ import com.moing.backend.domain.board.application.mapper.BoardMapper; 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.mapper.BoardReadMapper; import com.moing.backend.domain.boardRead.application.service.CreateBoardReadUserCase; -import com.moing.backend.domain.boardRead.domain.entity.BoardRead; -import com.moing.backend.domain.boardRead.domain.service.BoardReadSaveService; -import com.moing.backend.domain.member.domain.entity.Member; -import com.moing.backend.domain.member.domain.service.MemberGetService; import com.moing.backend.domain.team.application.service.CheckLeaderUserCase; -import com.moing.backend.domain.team.domain.entity.Team; -import com.moing.backend.domain.team.domain.service.TeamGetService; -import com.moing.backend.domain.teamMember.domain.entity.TeamMember; -import com.moing.backend.domain.teamMember.domain.service.TeamMemberGetService; -import com.moing.backend.global.config.security.dto.User; import com.moing.backend.global.response.BaseServiceResponse; import com.moing.backend.global.util.BaseService; import lombok.RequiredArgsConstructor; @@ -35,6 +25,7 @@ public class CreateBoardUserCase { private final BoardMapper boardMapper; private final CreateBoardReadUserCase createBoardReadUserCase; private final BaseService baseService; + private final SendBoardAlarmUserCase sendBoardAlarmUserCase; /** * 게시글 생성 @@ -49,6 +40,7 @@ public CreateBoardResponse createBoard(String socialId, Long teamId, CreateBoard createBoardReadUserCase.createBoardRead(data.getTeam(), data.getMember(), board); //3. 알림 보내기 - 공지인 경우 + sendBoardAlarmUserCase.sendNewUploadAlarm(data, board); return new CreateBoardResponse(board.getBoardId()); } } diff --git a/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java index 387e17da..0274a771 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java @@ -21,8 +21,11 @@ public class DeleteBoardUserCase { * 게시글 삭제 */ public void deleteBoard(String socialId, Long teamId, Long boardId){ + //1. 게시글 조회 BaseBoardServiceResponse data= baseBoardService.getCommonData(socialId,teamId,boardId); + //2. 작성자인 경우 if (data.getTeamMember() == data.getBoard().getTeamMember()) { + //3. 삭제 boardDeleteService.deleteBoard(data.getBoard()); } else throw new NotAuthByBoardException(); } diff --git a/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java index 56430dcc..e72be8e8 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java @@ -31,8 +31,9 @@ public class GetBoardUserCase { * 게시글 상세 조회 */ public GetBoardDetailResponse getBoardDetail(String socialId, Long teamId, Long boardId) { + // 1. 게시글 조회 BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); - //읽음 처리 + // 2. 읽음 처리 createBoardReadUserCase.createBoardRead(data.getTeam(), data.getMember(), data.getBoard()); return boardMapper.toBoardDetail(data.getBoard(), data.getTeamMember() == data.getBoard().getTeamMember()); } diff --git a/src/main/java/com/moing/backend/domain/board/application/service/AlarmBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/SendBoardAlarmUserCase.java similarity index 94% rename from src/main/java/com/moing/backend/domain/board/application/service/AlarmBoardUserCase.java rename to src/main/java/com/moing/backend/domain/board/application/service/SendBoardAlarmUserCase.java index fab65fc7..94efba16 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/AlarmBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/SendBoardAlarmUserCase.java @@ -19,7 +19,7 @@ @Service @RequiredArgsConstructor @Transactional -public class AlarmBoardUserCase { +public class SendBoardAlarmUserCase { private final TeamMemberGetService teamMemberGetService; private final FcmService fcmService; @@ -31,7 +31,7 @@ public void sendNewUploadAlarm(BaseServiceResponse baseServiceResponse, Board bo if (board.isNotice() && member.isNewUploadPush()) { String title = team.getName() + " " + UPLOAD_NOTICE_NEW_TITLE.getTitle(); String message = board.getTitle(); - Optional> fcmTokens = teamMemberGetService.getFcmTokens(team.getTeamId(), member.getMemberId()); + Optional> fcmTokens = teamMemberGetService.getFcmTokensExceptMe(team.getTeamId(), member.getMemberId()); if (fcmTokens.isPresent() && !fcmTokens.get().isEmpty()) { MultiRequest toMultiRequest = new MultiRequest(fcmTokens.get(), title, message); fcmService.sendMultipleDevices(toMultiRequest); diff --git a/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java index 394b34e3..21e20b91 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java @@ -21,8 +21,11 @@ public class UpdateBoardUserCase { * 게시글 수정 */ public UpdateBoardResponse updateBoard(String socialId, Long teamId, Long boardId, UpdateBoardRequest updateBoardRequest){ + // 1. 게시글 조회 BaseBoardServiceResponse data= baseBoardService.getCommonData(socialId, teamId, boardId); + // 2. 게시글 작성자만 if (data.getTeamMember() == data.getBoard().getTeamMember()) { + // 3. 수정 data.getBoard().updateBoard(updateBoardRequest); return new UpdateBoardResponse(data.getBoard().getBoardId()); } else throw new NotAuthByBoardException(); diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java index 759fc5c4..23e1d12b 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java @@ -21,9 +21,14 @@ public class CreateBoardCommentUserCase { private final BoardCommentMapper boardCommentMapper; private final BaseBoardService baseBoardService; + /** + * 게시글 댓글 생성 + */ public CreateBoardCommentResponse createBoardComment(String socialId, Long teamId, Long boardId, CreateBoardCommentRequest createBoardCommentRequest) { + // 1. 게시글 댓글 생성 BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); BoardComment boardComment = boardCommentSaveService.saveBoardComment(boardCommentMapper.toBoardComment(data.getTeamMember(), data.getBoard(), createBoardCommentRequest)); + // 2. 게시글 댓글 개수 증가 data.getBoard().incrComNum(); return new CreateBoardCommentResponse(boardComment.getBoardCommentId()); } diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java index 6201717f..2f0285c3 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java @@ -20,11 +20,19 @@ public class DeleteBoardCommentUserCase { private final BoardCommentDeleteService boardCommentDeleteService; private final BaseBoardService baseBoardService; + /** + * 게시글 댓글 삭제 + */ + public void deleteBoardComment(String socialId, Long teamId, Long boardId, Long boardCommentId){ + // 1. 게시글 댓글 조회 BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); BoardComment boardComment=boardCommentGetService.getBoardComment(boardCommentId); + // 2. 게시글 댓글 작성자만 if (data.getTeamMember() == boardComment.getTeamMember()) { + // 3. 삭제 boardCommentDeleteService.deleteBoardComment(boardComment); + // 4. 댓글 개수 줄이기 data.getBoard().decrComNum(); } else throw new NotAuthByBoardCommentException(); } diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java index df53c6e1..544c5174 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java @@ -17,6 +17,9 @@ public class GetBoardCommentUserCase { private final BoardCommentGetService boardCommentGetService; private final BaseBoardService baseBoardService; + /** + * 게시글 댓글 전체 조회 + */ public GetBoardCommentResponse getBoardCommentAll(String socialId, Long teamId, Long boardId){ BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); return boardCommentGetService.getBoardCommentAll(boardId, data.getTeamMember()); diff --git a/src/main/java/com/moing/backend/domain/team/application/service/SendTeamAlarmUserCase.java b/src/main/java/com/moing/backend/domain/team/application/service/SendTeamAlarmUserCase.java new file mode 100644 index 00000000..e5ef6690 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/team/application/service/SendTeamAlarmUserCase.java @@ -0,0 +1,43 @@ +package com.moing.backend.domain.team.application.service; + +import com.moing.backend.domain.teamMember.domain.service.TeamMemberGetService; +import com.moing.backend.global.config.fcm.dto.request.MultiRequest; +import com.moing.backend.global.config.fcm.service.FcmService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; +import java.util.List; +import java.util.Optional; + +import static com.moing.backend.global.config.fcm.constant.NewUploadTitle.UPLOAD_NOTICE_NEW_TITLE; + +@Service +@Transactional +@RequiredArgsConstructor +public class SendTeamAlarmUserCase { + private final TeamMemberGetService teamMemberGetService; + private final FcmService fcmService; + + public void sendApprovalAlarm(Long teamId) { + //TODO: 승인, 반려 문구 constant로 + String title = "소모임 승인 안내"; + String message = "소모임이 승인되었습니다."; + sendAlarm(teamId, title, message); + } + + public void sendRejectionAlarm(Long teamId) { + String title = "소모임 반려 안내"; + String message = "소모임이 반려되었습니다."; + sendAlarm(teamId, title, message); + } + + private void sendAlarm(Long teamId, String title, String message) { + Optional> fcmTokens = teamMemberGetService.getFcmTokens(teamId); + if(fcmTokens.isPresent() && !fcmTokens.get().isEmpty()) { + MultiRequest toMultiRequest = new MultiRequest(fcmTokens.get(), title, message); + fcmService.sendMultipleDevices(toMultiRequest); + } + } +} + diff --git a/src/main/java/com/moing/backend/domain/team/presentation/AdminTeamController.java b/src/main/java/com/moing/backend/domain/team/presentation/AdminTeamController.java index 3241479e..5ffa70f9 100644 --- a/src/main/java/com/moing/backend/domain/team/presentation/AdminTeamController.java +++ b/src/main/java/com/moing/backend/domain/team/presentation/AdminTeamController.java @@ -1,18 +1,45 @@ package com.moing.backend.domain.team.presentation; -import com.moing.backend.domain.team.application.service.CreateTeamUserCase; +import com.moing.backend.domain.team.application.service.SendTeamAlarmUserCase; +import com.moing.backend.global.response.SuccessResponse; import lombok.AllArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import static com.moing.backend.domain.team.presentation.constant.TeamResponseMessage.*; + @RestController @AllArgsConstructor @RequestMapping("/api/admin/team") public class AdminTeamController { - //TODO 소모임 승인, 반려하기 - private final CreateTeamUserCase createTeamService; + private final SendTeamAlarmUserCase sendTeamAlarmUserCase; + + /** + * 소모임 승인 알림 보내기 + * [POST] api/admin/team/approval/{teamId} + * 작성자 : 김민수 + */ + + @PostMapping("/approval/{teamId}") + public ResponseEntity sendApproveAlarm(@PathVariable Long teamId) { + this.sendTeamAlarmUserCase.sendApprovalAlarm(teamId); + return ResponseEntity.ok(SuccessResponse.create(SEND_APPROVAL_ALARM_SUCCESS.getMessage())); + } + /** + * 소모임 반려 알림 보내기 + * [POST] api/admin/team/rejection/{teamId} + * 작성자: 김민수 + */ + @PostMapping("/rejection/{teamId}") + public ResponseEntity sendRejectionAlarm(@PathVariable Long teamId){ + this.sendTeamAlarmUserCase.sendRejectionAlarm(teamId); + return ResponseEntity.ok(SuccessResponse.create(SEND_REJECTION_ALARM_SUCCESS.getMessage())); + } } diff --git a/src/main/java/com/moing/backend/domain/team/presentation/constant/TeamResponseMessage.java b/src/main/java/com/moing/backend/domain/team/presentation/constant/TeamResponseMessage.java index 45ae0eb5..2b1ccdcb 100644 --- a/src/main/java/com/moing/backend/domain/team/presentation/constant/TeamResponseMessage.java +++ b/src/main/java/com/moing/backend/domain/team/presentation/constant/TeamResponseMessage.java @@ -10,6 +10,8 @@ public enum TeamResponseMessage { GET_TEAM_SUCCESS("홈 화면에서 내 소모임을 모두 조회했습니다."), SIGNIN_TEAM_SUCCESS("소모임에 가입하였습니다"), DISBAND_TEAM_SUCCESS("[소모임장 권한] 소모임을 강제 종료했습니다."), - WITHDRAW_TEAM_SUCCESS("[소모임원 권한] 소모임을 탈퇴하였습니다"); + WITHDRAW_TEAM_SUCCESS("[소모임원 권한] 소모임을 탈퇴하였습니다"), + SEND_APPROVAL_ALARM_SUCCESS("소모임 승인 알림을 보냈습니다."), + SEND_REJECTION_ALARM_SUCCESS("소모임 반려 알림을 보냈습니다."); private final String message; } diff --git a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepository.java b/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepository.java index cc81ff9f..725b70e1 100644 --- a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepository.java @@ -5,5 +5,6 @@ public interface TeamMemberCustomRepository { List findMemberIdsByTeamId(Long teamId); - Optional> findFcmTokensByTeamId(Long teamId, Long userId); + Optional> findFcmTokensByTeamIdAndMemberId(Long teamId, Long memberId); + Optional> findFcmTokensByTeamId(Long teamId); } diff --git a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepositoryImpl.java index 615603e7..40f64eaa 100644 --- a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberCustomRepositoryImpl.java @@ -27,7 +27,7 @@ public List findMemberIdsByTeamId(Long teamId) { } @Override - public Optional> findFcmTokensByTeamId(Long teamId, Long memberId) { + public Optional> findFcmTokensByTeamIdAndMemberId(Long teamId, Long memberId) { return Optional.ofNullable(queryFactory.select(teamMember.member.fcmToken) .from(teamMember) .where(teamMember.team.teamId.eq(teamId)) //해당 소모임에 참여하고 있고 @@ -35,4 +35,13 @@ public Optional> findFcmTokensByTeamId(Long teamId, Long memberId) .where(teamMember.member.memberId.ne(memberId)) //지금 유저가 아닌 경우 .fetch()); } + + @Override + public Optional> findFcmTokensByTeamId(Long teamId) { + return Optional.ofNullable(queryFactory.select(teamMember.member.fcmToken) + .from(teamMember) + .where(teamMember.team.teamId.eq(teamId)) //해당 소모임에 참여하고 있고 + .where(teamMember.member.isNewUploadPush.eq(true)) //알림 설정 on해 있고 + .fetch()); + } } diff --git a/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberGetService.java b/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberGetService.java index a8ba11bc..6ba8f3db 100644 --- a/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberGetService.java +++ b/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberGetService.java @@ -24,8 +24,12 @@ public TeamMember getTeamMember(Member member, Team team){ return teamMemberRepository.findTeamMemberByTeamAndMember(team, member).orElseThrow(()-> new NotFoundByTeamIdException()); } - public Optional> getFcmTokens(Long teamId, Long memberId) { - return teamMemberRepository.findFcmTokensByTeamId(teamId, memberId); + public Optional> getFcmTokensExceptMe(Long teamId, Long memberId) { + return teamMemberRepository.findFcmTokensByTeamIdAndMemberId(teamId, memberId); + } + + public Optional> getFcmTokens(Long teamId) { + return teamMemberRepository.findFcmTokensByTeamId(teamId); } }