Skip to content

Commit

Permalink
Merge pull request #34 from Modagbul/feat/fire
Browse files Browse the repository at this point in the history
feat : 불던지기 관련 API
  • Loading branch information
minsu20 authored Oct 17, 2023
2 parents 0ee6809 + 25fbfb6 commit ef8fbb3
Show file tree
Hide file tree
Showing 58 changed files with 1,146 additions and 31 deletions.
16 changes: 16 additions & 0 deletions src/docs/asciidoc/Fire-API.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


[[Fire-API]]
= Fire API

[[Fire-불던지기]]
=== 불 던지기
operation::fire-controller-test/불_던지기[snippets='http-request,path-parameters,request-fields,http-response,response-fields']

---
[[Fire-불던질사람조회]]
=== 불 던질 사람 조회
operation::fire-controller-test/불_던질_사람_조회[snippets='http-request,path-parameters,request-fields,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 @@ -22,6 +22,8 @@ include::MissionArchive-API.adoc[]

include::MissionBoard-API.adoc[]

include::Fire-API.adoc[]

include::Board-API.adoc[]

include::BoardComment_API.adoc[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public class BoardBlocks {

private Boolean isRead;

private Boolean writerIsDeleted;

@QueryProjection
public BoardBlocks(Long boardId, String writerNickName, Boolean writerIsLeader, String writerProfileImage, String title, String content, Integer commentNum) {
public BoardBlocks(Long boardId, String writerNickName, Boolean writerIsLeader, String writerProfileImage, String title, String content, Integer commentNum, Boolean writerIsDeleted) {
this.boardId = boardId;
this.writerNickName = writerNickName;
this.writerIsLeader = writerIsLeader;
Expand All @@ -36,9 +38,18 @@ public BoardBlocks(Long boardId, String writerNickName, Boolean writerIsLeader,
this.content = content;
this.commentNum = commentNum;
this.isRead = false;
this.writerIsDeleted=writerIsDeleted;
deleteMember();
}

public void readBoard() {
this.isRead = true;
}

public void deleteMember() {
if(Boolean.TRUE.equals(writerIsDeleted)) {
this.writerNickName = "(알 수 없음)";
this.writerProfileImage = "undef";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,17 +25,22 @@ public class CreateBoardUserCase {
private final BoardMapper boardMapper;
private final CreateBoardReadUserCase createBoardReadUserCase;
private final BaseService baseService;
private final SendBoardAlarmUserCase sendBoardAlarmUserCase;

/**
* 게시글 생성
*/
public CreateBoardResponse createBoard(String socialId, Long teamId, CreateBoardRequest createBoardRequest) {
//1, 게시글 생성, 저장
BaseServiceResponse data=baseService.getCommonData(socialId, teamId);
boolean isLeader = checkLeaderUserCase.isTeamLeader(data.getMember(), data.getTeam());
boolean isLeader = checkLeaderUserCase.isTeamLeader(data.getMember(), data.getTeam()); //작성자 리더 여부
Board board=boardSaveService.saveBoard(boardMapper.toBoard(data.getMember(), data.getTeamMember(), data.getTeam(), createBoardRequest, isLeader));

//읽음 처리
//2. 읽음 처리 - 생성한 사람은 무조건 읽음
createBoardReadUserCase.createBoardRead(data.getTeam(), data.getMember(), board);

//3. 알림 보내기 - 공지인 경우
sendBoardAlarmUserCase.sendNewUploadAlarm(data, board);
return new CreateBoardResponse(board.getBoardId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.moing.backend.domain.board.application.service;

import com.moing.backend.domain.board.domain.entity.Board;
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.request.MultiRequest;
import com.moing.backend.global.config.fcm.service.FcmService;
import com.moing.backend.global.response.BaseServiceResponse;
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
@RequiredArgsConstructor
@Transactional
public class SendBoardAlarmUserCase {

private final TeamMemberGetService teamMemberGetService;
private final FcmService fcmService;

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

if (board.isNotice() && member.isNewUploadPush()) {
String title = team.getName() + " " + UPLOAD_NOTICE_NEW_TITLE.getTitle();
String message = board.getTitle();
Optional<List<String>> fcmTokens = teamMemberGetService.getFcmTokensExceptMe(team.getTeamId(), member.getMemberId());
if (fcmTokens.isPresent() && !fcmTokens.get().isEmpty()) {
MultiRequest toMultiRequest = new MultiRequest(fcmTokens.get(), title, message);
fcmService.sendMultipleDevices(toMultiRequest);
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import static com.moing.backend.domain.board.domain.entity.QBoard.board;
import static com.moing.backend.domain.boardRead.domain.entity.QBoardRead.boardRead;

public class BoardCustomRepositoryImpl implements BoardCustomRepository {
public class BoardCustomRepositoryImpl implements BoardCustomRepository {
private final JPAQueryFactory queryFactory;

public BoardCustomRepositoryImpl(EntityManager em) {
Expand Down Expand Up @@ -51,7 +51,8 @@ public GetAllBoardResponse findBoardAll(Long teamId, Long memberId) {
b.getWriterProfileImage(),
b.getTitle(),
b.getContent(),
b.getCommentNum()
b.getCommentNum(),
b.getTeamMember().isDeleted()
);
if (isRead) {
boardBlocks.readBoard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ public class CommentBlocks {
private String writerProfileImage;

private Boolean isWriter;

private Boolean writerIsDeleted;

public void deleteMember(){
this.writerNickName="(알 수 없음)";
this.writerProfileImage="undef";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.moing.backend.domain.boardComment.domain.repository;

import com.moing.backend.domain.board.domain.entity.Board;
import com.moing.backend.domain.boardComment.application.dto.response.CommentBlocks;
import com.moing.backend.domain.boardComment.application.dto.response.GetBoardCommentResponse;
import com.moing.backend.domain.boardComment.application.service.GetBoardCommentUserCase;
import com.moing.backend.domain.boardComment.domain.entity.BoardComment;
import com.moing.backend.domain.boardComment.domain.entity.QBoardComment;
import com.moing.backend.domain.teamMember.domain.entity.QTeamMember;
import com.moing.backend.domain.teamMember.domain.entity.TeamMember;
import com.querydsl.core.types.ExpressionUtils;
Expand All @@ -17,7 +13,6 @@
import java.util.List;

import static com.moing.backend.domain.boardComment.domain.entity.QBoardComment.boardComment;
import static com.moing.backend.domain.teamMember.domain.entity.QTeamMember.teamMember;

public class BoardCommentCustomRepositoryImpl implements BoardCommentCustomRepository{

Expand All @@ -42,11 +37,15 @@ public GetBoardCommentResponse findBoardCommentAll(Long boardId, TeamMember team
.from(QTeamMember.teamMember)
.where(QTeamMember.teamMember.eq(teamMember)
.and(QTeamMember.teamMember.eq(boardComment.teamMember)))
.exists(), "isWriter")))
.exists(), "isWriter"),
boardComment.teamMember.isDeleted))
.from(boardComment)
.where(boardComment.board.boardId.eq(boardId))
.orderBy(boardComment.createdDate.asc())
.fetch();

commentBlocks.forEach(CommentBlocks::deleteMember);

return new GetBoardCommentResponse(commentBlocks);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.moing.backend.domain.fire.application.dto.res;

import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public class FireReceiveRes {

private Long receiveMemberId;
private String nickname;
private String fireStatus;

public void updateFireStatus(boolean status) {
if (status)
this.fireStatus = "True";
else this.fireStatus = "False";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.moing.backend.domain.fire.application.dto.res;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class FireThrowRes {

private Long receiveMemberId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.moing.backend.domain.fire.application.mapper;

import com.moing.backend.domain.fire.application.dto.res.FireReceiveRes;
import com.moing.backend.domain.fire.application.dto.res.FireThrowRes;
import com.moing.backend.domain.fire.domain.entity.Fire;
import com.moing.backend.domain.member.domain.entity.Member;

import java.util.ArrayList;
import java.util.List;

public class FireMapper {

public static FireThrowRes mapToFireThrowRes(Fire fire) {
return FireThrowRes.builder()
.receiveMemberId(fire.getReceiveMemberId())
.build();
}

public static List<FireReceiveRes> mapToFireReceiversList(List<Member> members) {
List<FireReceiveRes> fireReceiveResList = new ArrayList<>();
members.forEach(
member -> fireReceiveResList.add(FireMapper.mapToFireReceiveRes(member))
);
return fireReceiveResList;
}

public static FireReceiveRes mapToFireReceiveRes(Member member) {
return FireReceiveRes.builder()
.receiveMemberId(member.getMemberId())
.nickname(member.getNickName())
.fireStatus("TRUE")
.build();
}
}
Loading

0 comments on commit ef8fbb3

Please sign in to comment.