From fe4e18fac94b4fa02999103bb077504b3beb0384 Mon Sep 17 00:00:00 2001 From: minsu20 Date: Tue, 7 May 2024 01:08:23 +0900 Subject: [PATCH 1/4] =?UTF-8?q?MNG-20=20feat:=20BoardComment,=20MissionCom?= =?UTF-8?q?ment=20=EA=B3=B5=ED=86=B5=20=EB=B6=80=EB=B6=84=20=EB=B9=BC?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/CreateCommentRequest.java} | 4 ++-- .../dto/response/CommentBlocks.java | 8 +++---- .../dto/response/CreateCommentResponse.java} | 6 ++--- .../dto/response/GetCommentResponse.java} | 4 ++-- .../domain/comment/domain/entity/Comment.java | 24 +++++++++++++++++++ .../domain/service/CommentDeleteService.java | 5 ++++ .../domain/service/CommentGetService.java | 14 +++++++++++ .../domain/service/CommentSaveService.java | 5 ++++ 8 files changed, 59 insertions(+), 11 deletions(-) rename src/main/java/com/moing/backend/domain/{boardComment/application/dto/request/CreateBoardCommentRequest.java => comment/application/dto/request/CreateCommentRequest.java} (79%) rename src/main/java/com/moing/backend/domain/{boardComment => comment}/application/dto/response/CommentBlocks.java (78%) rename src/main/java/com/moing/backend/domain/{boardComment/application/dto/response/CreateBoardCommentResponse.java => comment/application/dto/response/CreateCommentResponse.java} (53%) rename src/main/java/com/moing/backend/domain/{boardComment/application/dto/response/GetBoardCommentResponse.java => comment/application/dto/response/GetCommentResponse.java} (68%) create mode 100644 src/main/java/com/moing/backend/domain/comment/domain/entity/Comment.java create mode 100644 src/main/java/com/moing/backend/domain/comment/domain/service/CommentDeleteService.java create mode 100644 src/main/java/com/moing/backend/domain/comment/domain/service/CommentGetService.java create mode 100644 src/main/java/com/moing/backend/domain/comment/domain/service/CommentSaveService.java diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/dto/request/CreateBoardCommentRequest.java b/src/main/java/com/moing/backend/domain/comment/application/dto/request/CreateCommentRequest.java similarity index 79% rename from src/main/java/com/moing/backend/domain/boardComment/application/dto/request/CreateBoardCommentRequest.java rename to src/main/java/com/moing/backend/domain/comment/application/dto/request/CreateCommentRequest.java index 9cc0841d..84d79633 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/dto/request/CreateBoardCommentRequest.java +++ b/src/main/java/com/moing/backend/domain/comment/application/dto/request/CreateCommentRequest.java @@ -1,4 +1,4 @@ -package com.moing.backend.domain.boardComment.application.dto.request; +package com.moing.backend.domain.comment.application.dto.request; import lombok.AllArgsConstructor; import lombok.Builder; @@ -12,7 +12,7 @@ @Builder @NoArgsConstructor @Getter -public class CreateBoardCommentRequest { +public class CreateCommentRequest { @NotBlank(message = "content 을 입력해 주세요.") @Size(min = 0, max = 300, message = "댓글 글자수를 초과했습니다.") diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CommentBlocks.java b/src/main/java/com/moing/backend/domain/comment/application/dto/response/CommentBlocks.java similarity index 78% rename from src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CommentBlocks.java rename to src/main/java/com/moing/backend/domain/comment/application/dto/response/CommentBlocks.java index af02defe..40164051 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CommentBlocks.java +++ b/src/main/java/com/moing/backend/domain/comment/application/dto/response/CommentBlocks.java @@ -1,4 +1,4 @@ -package com.moing.backend.domain.boardComment.application.dto.response; +package com.moing.backend.domain.comment.application.dto.response; import com.querydsl.core.annotations.QueryProjection; import lombok.AllArgsConstructor; @@ -13,7 +13,7 @@ @AllArgsConstructor public class CommentBlocks { - private Long boardCommentId; + private Long commentId; private String content; @@ -32,8 +32,8 @@ public class CommentBlocks { private Long makerId; @QueryProjection - public CommentBlocks(Long boardCommentId, String content, String writerNickName, Boolean writerIsLeader, String writerProfileImage, Boolean isWriter, Boolean writerIsDeleted, LocalDateTime createdDate, Long makerId) { - this.boardCommentId = boardCommentId; + public CommentBlocks(Long commentId, String content, String writerNickName, Boolean writerIsLeader, String writerProfileImage, Boolean isWriter, Boolean writerIsDeleted, LocalDateTime createdDate, Long makerId) { + this.commentId = commentId; this.writerNickName = writerNickName; this.writerIsLeader = writerIsLeader; this.writerProfileImage = writerProfileImage; diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CreateBoardCommentResponse.java b/src/main/java/com/moing/backend/domain/comment/application/dto/response/CreateCommentResponse.java similarity index 53% rename from src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CreateBoardCommentResponse.java rename to src/main/java/com/moing/backend/domain/comment/application/dto/response/CreateCommentResponse.java index 8967920c..b392489c 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CreateBoardCommentResponse.java +++ b/src/main/java/com/moing/backend/domain/comment/application/dto/response/CreateCommentResponse.java @@ -1,4 +1,4 @@ -package com.moing.backend.domain.boardComment.application.dto.response; +package com.moing.backend.domain.comment.application.dto.response; import lombok.AllArgsConstructor; import lombok.Builder; @@ -9,6 +9,6 @@ @Builder @NoArgsConstructor @Getter -public class CreateBoardCommentResponse { - private Long boardCommentId; +public class CreateCommentResponse { + private Long commentId; } diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/GetBoardCommentResponse.java b/src/main/java/com/moing/backend/domain/comment/application/dto/response/GetCommentResponse.java similarity index 68% rename from src/main/java/com/moing/backend/domain/boardComment/application/dto/response/GetBoardCommentResponse.java rename to src/main/java/com/moing/backend/domain/comment/application/dto/response/GetCommentResponse.java index 94bbbe1d..06df8937 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/GetBoardCommentResponse.java +++ b/src/main/java/com/moing/backend/domain/comment/application/dto/response/GetCommentResponse.java @@ -1,4 +1,4 @@ -package com.moing.backend.domain.boardComment.application.dto.response; +package com.moing.backend.domain.comment.application.dto.response; import lombok.AllArgsConstructor; import lombok.Builder; @@ -11,6 +11,6 @@ @Builder @NoArgsConstructor @Getter -public class GetBoardCommentResponse { +public class GetCommentResponse { private List commentBlocks; } diff --git a/src/main/java/com/moing/backend/domain/comment/domain/entity/Comment.java b/src/main/java/com/moing/backend/domain/comment/domain/entity/Comment.java new file mode 100644 index 00000000..5410bf33 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/comment/domain/entity/Comment.java @@ -0,0 +1,24 @@ +package com.moing.backend.domain.comment.domain.entity; + +import com.moing.backend.global.entity.BaseTimeEntity; +import lombok.Getter; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.Column; +import javax.persistence.EntityListeners; +import javax.persistence.MappedSuperclass; + +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public class Comment extends BaseTimeEntity { + + @Column(nullable = false, length = 300) + protected String content; + + protected boolean isLeader; /*작성자 소모임장유무*/ + public void updateContent(String content) { + this.content = content; + } + +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/comment/domain/service/CommentDeleteService.java b/src/main/java/com/moing/backend/domain/comment/domain/service/CommentDeleteService.java new file mode 100644 index 00000000..1bd99c90 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/comment/domain/service/CommentDeleteService.java @@ -0,0 +1,5 @@ +package com.moing.backend.domain.comment.domain.service; + +public interface CommentDeleteService { + void deleteComment(T comment); +} diff --git a/src/main/java/com/moing/backend/domain/comment/domain/service/CommentGetService.java b/src/main/java/com/moing/backend/domain/comment/domain/service/CommentGetService.java new file mode 100644 index 00000000..3f6cb854 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/comment/domain/service/CommentGetService.java @@ -0,0 +1,14 @@ +package com.moing.backend.domain.comment.domain.service; + +import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse; +import com.moing.backend.domain.history.application.dto.response.NewUploadInfo; +import com.moing.backend.domain.teamMember.domain.entity.TeamMember; + +import java.util.List; +import java.util.Optional; + +public interface CommentGetService { + T getComment(Long commentId); + GetCommentResponse getCommentAll(Long boardId, TeamMember teamMember); + Optional> getNewUploadInfo(Long memberId, Long boardId); +} diff --git a/src/main/java/com/moing/backend/domain/comment/domain/service/CommentSaveService.java b/src/main/java/com/moing/backend/domain/comment/domain/service/CommentSaveService.java new file mode 100644 index 00000000..b0a73f8b --- /dev/null +++ b/src/main/java/com/moing/backend/domain/comment/domain/service/CommentSaveService.java @@ -0,0 +1,5 @@ +package com.moing.backend.domain.comment.domain.service; + +public interface CommentSaveService { + T saveComment(T comment); +} From 6fc0d5507284f3dc83228b5d1788ba851656df91 Mon Sep 17 00:00:00 2001 From: minsu20 Date: Tue, 7 May 2024 01:09:39 +0900 Subject: [PATCH 2/4] =?UTF-8?q?MNG-20=20refactor:=20BoardComment=EA=B0=80?= =?UTF-8?q?=20Comment=EC=9D=98=20=EA=B3=B5=ED=86=B5=20=EC=9D=B8=ED=84=B0?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=8A=A4=EB=A5=BC=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/presentation/BoardController.java | 13 ++++++++ .../mapper/BoardCommentMapper.java | 10 +++--- .../service/CreateBoardCommentUseCase.java | 10 +++--- .../service/DeleteBoardCommentUseCase.java | 4 +-- .../service/GetBoardCommentUseCase.java | 6 ++-- .../domain/entity/BoardComment.java | 16 +++------- .../BoardCommentCustomRepository.java | 4 +-- .../BoardCommentCustomRepositoryImpl.java | 10 +++--- .../repository/BoardCommentRepository.java | 1 - .../service/BoardCommentDeleteService.java | 7 +++-- .../service/BoardCommentGetService.java | 14 ++++++--- .../service/BoardCommentSaveService.java | 8 +++-- .../presentattion/BoardCommentController.java | 31 +++++++++---------- .../dto/res/MissionArchiveRes.java | 9 +++--- 14 files changed, 78 insertions(+), 65 deletions(-) diff --git a/src/main/java/com/moing/backend/domain/board/presentation/BoardController.java b/src/main/java/com/moing/backend/domain/board/presentation/BoardController.java index 739935e4..8ae0002f 100644 --- a/src/main/java/com/moing/backend/domain/board/presentation/BoardController.java +++ b/src/main/java/com/moing/backend/domain/board/presentation/BoardController.java @@ -91,4 +91,17 @@ public ResponseEntity> getBoardAll(@Authent @PathVariable Long teamId) { return ResponseEntity.ok(SuccessResponse.create(GET_BOARD_ALL_SUCCESS.getMessage(), this.getBoardUseCase.getAllBoard(user.getSocialId(), teamId))); } + + @PostMapping("/test") + public void test() { + Thread thread1 = new Thread(() -> { + this.getBoardUseCase.getBoardDetail("KAKAO@tester01", 1L,1L); + }); + Thread thread2 = new Thread(() -> { + this.getBoardUseCase.getBoardDetail("KAKAO@tester01", 1L,1L); + }); + thread1.start(); + thread2.start(); + } + } diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/mapper/BoardCommentMapper.java b/src/main/java/com/moing/backend/domain/boardComment/application/mapper/BoardCommentMapper.java index e2311e2a..00f9f751 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/mapper/BoardCommentMapper.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/mapper/BoardCommentMapper.java @@ -1,7 +1,7 @@ package com.moing.backend.domain.boardComment.application.mapper; import com.moing.backend.domain.board.domain.entity.Board; -import com.moing.backend.domain.boardComment.application.dto.request.CreateBoardCommentRequest; +import com.moing.backend.domain.comment.application.dto.request.CreateCommentRequest; import com.moing.backend.domain.boardComment.domain.entity.BoardComment; import com.moing.backend.domain.teamMember.domain.entity.TeamMember; import lombok.RequiredArgsConstructor; @@ -10,11 +10,9 @@ @Component @RequiredArgsConstructor public class BoardCommentMapper { - public static BoardComment toBoardComment(TeamMember teamMember, Board board, CreateBoardCommentRequest createBoardCommentRequest, boolean isLeader) { - BoardComment boardComment= BoardComment.builder() - .content(createBoardCommentRequest.getContent()) - .isLeader(isLeader) - .build(); + public static BoardComment toBoardComment(TeamMember teamMember, Board board, CreateCommentRequest createCommentRequest, boolean isLeader) { + BoardComment boardComment= new BoardComment(); + boardComment.init(createCommentRequest.getContent(),isLeader); boardComment.updateBoard(board); boardComment.updateTeamMember(teamMember); return boardComment; diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUseCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUseCase.java index 3530d8a5..ffac8705 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUseCase.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUseCase.java @@ -1,10 +1,10 @@ package com.moing.backend.domain.boardComment.application.service; -import com.moing.backend.domain.boardComment.application.dto.request.CreateBoardCommentRequest; -import com.moing.backend.domain.boardComment.application.dto.response.CreateBoardCommentResponse; import com.moing.backend.domain.boardComment.application.mapper.BoardCommentMapper; import com.moing.backend.domain.boardComment.domain.entity.BoardComment; import com.moing.backend.domain.boardComment.domain.service.BoardCommentSaveService; +import com.moing.backend.domain.comment.application.dto.request.CreateCommentRequest; +import com.moing.backend.domain.comment.application.dto.response.CreateCommentResponse; import com.moing.backend.domain.team.application.service.CheckLeaderUseCase; import com.moing.backend.global.response.BaseBoardServiceResponse; import com.moing.backend.global.utils.BaseBoardService; @@ -25,15 +25,15 @@ public class CreateBoardCommentUseCase { /** * 게시글 댓글 생성 */ - public CreateBoardCommentResponse createBoardComment(String socialId, Long teamId, Long boardId, CreateBoardCommentRequest createBoardCommentRequest) { + public CreateCommentResponse createBoardComment(String socialId, Long teamId, Long boardId, CreateCommentRequest createCommentRequest) { // 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.saveComment(BoardCommentMapper.toBoardComment(data.getTeamMember(), data.getBoard(), createCommentRequest, isLeader)); // 2. 게시글 댓글 개수 증가 data.getBoard().incrComNum(); // 3. 게시글 댓글 알림 sendCommentAlarmUseCase.sendNewUploadAlarm(data, boardComment); - return new CreateBoardCommentResponse(boardComment.getBoardCommentId()); + return new CreateCommentResponse(boardComment.getBoardCommentId()); } } diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUseCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUseCase.java index 0937123d..7c5a4611 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUseCase.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUseCase.java @@ -27,11 +27,11 @@ public class DeleteBoardCommentUseCase { public void deleteBoardComment(String socialId, Long teamId, Long boardId, Long boardCommentId){ // 1. 게시글 댓글 조회 BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); - BoardComment boardComment=boardCommentGetService.getBoardComment(boardCommentId); + BoardComment boardComment=boardCommentGetService.getComment(boardCommentId); // 2. 게시글 댓글 작성자만 if (data.getTeamMember() == boardComment.getTeamMember()) { // 3. 삭제 - boardCommentDeleteService.deleteBoardComment(boardComment); + boardCommentDeleteService.deleteComment(boardComment); // 4. 댓글 개수 줄이기 data.getBoard().decrComNum(); } else throw new NotAuthByBoardCommentException(); diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUseCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUseCase.java index a3163427..d34816cd 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUseCase.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUseCase.java @@ -1,7 +1,7 @@ package com.moing.backend.domain.boardComment.application.service; -import com.moing.backend.domain.boardComment.application.dto.response.GetBoardCommentResponse; import com.moing.backend.domain.boardComment.domain.service.BoardCommentGetService; +import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse; import com.moing.backend.global.response.BaseBoardServiceResponse; import com.moing.backend.global.utils.BaseBoardService; import lombok.RequiredArgsConstructor; @@ -20,8 +20,8 @@ public class GetBoardCommentUseCase { /** * 게시글 댓글 전체 조회 */ - public GetBoardCommentResponse getBoardCommentAll(String socialId, Long teamId, Long boardId){ + public GetCommentResponse getBoardCommentAll(String socialId, Long teamId, Long boardId){ BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); - return boardCommentGetService.getBoardCommentAll(boardId, data.getTeamMember()); + return boardCommentGetService.getCommentAll(boardId, data.getTeamMember()); } } diff --git a/src/main/java/com/moing/backend/domain/boardComment/domain/entity/BoardComment.java b/src/main/java/com/moing/backend/domain/boardComment/domain/entity/BoardComment.java index 7edf67cb..6a4092d4 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/domain/entity/BoardComment.java +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/entity/BoardComment.java @@ -1,9 +1,8 @@ package com.moing.backend.domain.boardComment.domain.entity; import com.moing.backend.domain.board.domain.entity.Board; -import com.moing.backend.domain.boardComment.application.dto.request.CreateBoardCommentRequest; +import com.moing.backend.domain.comment.domain.entity.Comment; import com.moing.backend.domain.teamMember.domain.entity.TeamMember; -import com.moing.backend.global.entity.BaseTimeEntity; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -16,16 +15,13 @@ @NoArgsConstructor @AllArgsConstructor @Getter -public class BoardComment extends BaseTimeEntity { +public class BoardComment extends Comment { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "board_comment_id") private Long boardCommentId; - @Column(nullable = false, length = 300) - private String content; - @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "team_member_id") private TeamMember teamMember; @@ -34,8 +30,6 @@ public class BoardComment extends BaseTimeEntity { @JoinColumn(name = "board_id") private Board board; - private boolean isLeader; /*작성자 소모임장유무*/ - /** * 연관관계 매핑 */ @@ -48,8 +42,8 @@ public void updateTeamMember(TeamMember teamMember) { this.teamMember = teamMember; } - public void updateBoardComment(CreateBoardCommentRequest createBoardCommentRequest) { - this.content = createBoardCommentRequest.getContent(); + public void init(String content, boolean isLeader){ + this.content=content; + this.isLeader=isLeader; } - } diff --git a/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentCustomRepository.java b/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentCustomRepository.java index 25a70306..8040bf28 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentCustomRepository.java @@ -1,6 +1,6 @@ package com.moing.backend.domain.boardComment.domain.repository; -import com.moing.backend.domain.boardComment.application.dto.response.GetBoardCommentResponse; +import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse; import com.moing.backend.domain.history.application.dto.response.NewUploadInfo; import com.moing.backend.domain.teamMember.domain.entity.TeamMember; @@ -8,7 +8,7 @@ import java.util.Optional; public interface BoardCommentCustomRepository { - GetBoardCommentResponse findBoardCommentAll(Long boardId, TeamMember teamMember); + GetCommentResponse findBoardCommentAll(Long boardId, TeamMember teamMember); Optional> findNewUploadInfo(Long memberId, Long boardId); } diff --git a/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentCustomRepositoryImpl.java index 048fa21f..413f4203 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentCustomRepositoryImpl.java @@ -1,9 +1,9 @@ package com.moing.backend.domain.boardComment.domain.repository; import com.moing.backend.domain.block.domain.repository.BlockRepositoryUtils; -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.dto.response.QCommentBlocks; +import com.moing.backend.domain.comment.application.dto.response.CommentBlocks; +import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse; +import com.moing.backend.domain.comment.application.dto.response.QCommentBlocks; import com.moing.backend.domain.history.application.dto.response.NewUploadInfo; import com.moing.backend.domain.teamMember.domain.entity.QTeamMember; import com.moing.backend.domain.teamMember.domain.entity.TeamMember; @@ -31,7 +31,7 @@ public BoardCommentCustomRepositoryImpl(EntityManager em) { @Override - public GetBoardCommentResponse findBoardCommentAll(Long boardId, TeamMember teamMember) { + public GetCommentResponse findBoardCommentAll(Long boardId, TeamMember teamMember) { BooleanExpression blockCondition = BlockRepositoryUtils.blockCondition(teamMember.getTeamMemberId(), boardComment.teamMember.member.memberId); @@ -59,7 +59,7 @@ public GetBoardCommentResponse findBoardCommentAll(Long boardId, TeamMember team .orderBy(boardComment.createdDate.asc()) .fetch(); - return new GetBoardCommentResponse(commentBlocks); + return new GetCommentResponse(commentBlocks); } @Override diff --git a/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentRepository.java b/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentRepository.java index 8ccec194..99a7b2a3 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentRepository.java +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentRepository.java @@ -1,6 +1,5 @@ package com.moing.backend.domain.boardComment.domain.repository; -import com.moing.backend.domain.board.domain.entity.Board; import com.moing.backend.domain.boardComment.domain.entity.BoardComment; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentDeleteService.java b/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentDeleteService.java index c3bd102f..63e55f09 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentDeleteService.java +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentDeleteService.java @@ -2,15 +2,18 @@ import com.moing.backend.domain.boardComment.domain.entity.BoardComment; import com.moing.backend.domain.boardComment.domain.repository.BoardCommentRepository; +import com.moing.backend.domain.comment.domain.service.CommentDeleteService; import com.moing.backend.global.annotation.DomainService; import lombok.RequiredArgsConstructor; @DomainService @RequiredArgsConstructor -public class BoardCommentDeleteService { +public class BoardCommentDeleteService implements CommentDeleteService { private final BoardCommentRepository boardCommentRepository; - public void deleteBoardComment(BoardComment boardComment){ + @Override + public void deleteComment(BoardComment boardComment){ this.boardCommentRepository.delete(boardComment); } + } diff --git a/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentGetService.java b/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentGetService.java index 28023ab0..1f2eaea0 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentGetService.java +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentGetService.java @@ -1,9 +1,10 @@ package com.moing.backend.domain.boardComment.domain.service; -import com.moing.backend.domain.boardComment.application.dto.response.GetBoardCommentResponse; import com.moing.backend.domain.boardComment.domain.entity.BoardComment; import com.moing.backend.domain.boardComment.domain.repository.BoardCommentRepository; import com.moing.backend.domain.boardComment.exception.NotFoundByBoardCommentIdException; +import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse; +import com.moing.backend.domain.comment.domain.service.CommentGetService; import com.moing.backend.domain.history.application.dto.response.NewUploadInfo; import com.moing.backend.domain.teamMember.domain.entity.TeamMember; import com.moing.backend.global.annotation.DomainService; @@ -16,18 +17,21 @@ @DomainService @Transactional @RequiredArgsConstructor -public class BoardCommentGetService { +public class BoardCommentGetService implements CommentGetService { private final BoardCommentRepository boardCommentRepository; - public BoardComment getBoardComment(Long boardCommentId){ - return boardCommentRepository.findBoardCommentByBoardCommentId(boardCommentId).orElseThrow(()->new NotFoundByBoardCommentIdException()); + @Override + public BoardComment getComment(Long boardCommentId){ + return boardCommentRepository.findBoardCommentByBoardCommentId(boardCommentId).orElseThrow(NotFoundByBoardCommentIdException::new); } - public GetBoardCommentResponse getBoardCommentAll(Long boardId, TeamMember teamMember){ + @Override + public GetCommentResponse getCommentAll(Long boardId, TeamMember teamMember){ return boardCommentRepository.findBoardCommentAll(boardId, teamMember); } + @Override public Optional> getNewUploadInfo(Long memberId, Long boardId) { return boardCommentRepository.findNewUploadInfo(memberId, boardId); } diff --git a/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentSaveService.java b/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentSaveService.java index 48b634aa..f4ac6d04 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentSaveService.java +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentSaveService.java @@ -1,17 +1,19 @@ package com.moing.backend.domain.boardComment.domain.service; -import com.moing.backend.domain.boardComment.domain.entity.BoardComment; import com.moing.backend.domain.boardComment.domain.repository.BoardCommentRepository; +import com.moing.backend.domain.boardComment.domain.entity.BoardComment; +import com.moing.backend.domain.comment.domain.service.CommentSaveService; import com.moing.backend.global.annotation.DomainService; import lombok.RequiredArgsConstructor; @DomainService @RequiredArgsConstructor -public class BoardCommentSaveService { +public class BoardCommentSaveService implements CommentSaveService { private final BoardCommentRepository boardCommentRepository; - public BoardComment saveBoardComment(BoardComment boardComment){ + @Override + public BoardComment saveComment(BoardComment boardComment){ return this.boardCommentRepository.save(boardComment); } } diff --git a/src/main/java/com/moing/backend/domain/boardComment/presentattion/BoardCommentController.java b/src/main/java/com/moing/backend/domain/boardComment/presentattion/BoardCommentController.java index 506d9250..501f0cfd 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/presentattion/BoardCommentController.java +++ b/src/main/java/com/moing/backend/domain/boardComment/presentattion/BoardCommentController.java @@ -1,11 +1,12 @@ package com.moing.backend.domain.boardComment.presentattion; -import com.moing.backend.domain.boardComment.application.dto.request.CreateBoardCommentRequest; -import com.moing.backend.domain.boardComment.application.dto.response.CreateBoardCommentResponse; -import com.moing.backend.domain.boardComment.application.dto.response.GetBoardCommentResponse; import com.moing.backend.domain.boardComment.application.service.CreateBoardCommentUseCase; import com.moing.backend.domain.boardComment.application.service.DeleteBoardCommentUseCase; import com.moing.backend.domain.boardComment.application.service.GetBoardCommentUseCase; +import com.moing.backend.domain.boardComment.presentattion.constant.BoardCommentResponseMessage; +import com.moing.backend.domain.comment.application.dto.request.CreateCommentRequest; +import com.moing.backend.domain.comment.application.dto.response.CreateCommentResponse; +import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse; import com.moing.backend.global.config.security.dto.User; import com.moing.backend.global.response.SuccessResponse; import lombok.AllArgsConstructor; @@ -15,9 +16,7 @@ import javax.validation.Valid; -import static com.moing.backend.domain.board.presentation.constant.BoardResponseMessage.GET_BOARD_ALL_SUCCESS; -import static com.moing.backend.domain.boardComment.presentattion.constant.BoardCommentResponseMessage.CREATE_BOARD_COMMENT_SUCCESS; -import static com.moing.backend.domain.boardComment.presentattion.constant.BoardCommentResponseMessage.DELETE_BOARD_COMMENT_SUCCESS; +import static com.moing.backend.domain.boardComment.presentattion.constant.BoardCommentResponseMessage.GET_BOARD_COMMENT_ALL_SUCCESS; @RestController @AllArgsConstructor @@ -34,11 +33,11 @@ public class BoardCommentController { * 작성자 : 김민수 */ @PostMapping - public ResponseEntity> createBoardComment(@AuthenticationPrincipal User user, - @PathVariable Long teamId, - @PathVariable Long boardId, - @Valid @RequestBody CreateBoardCommentRequest createBoardCommentRequest) { - return ResponseEntity.ok(SuccessResponse.create(CREATE_BOARD_COMMENT_SUCCESS.getMessage(), this.createBoardCommentUseCase.createBoardComment(user.getSocialId(), teamId, boardId, createBoardCommentRequest))); + public ResponseEntity> createBoardComment(@AuthenticationPrincipal User user, + @PathVariable Long teamId, + @PathVariable Long boardId, + @Valid @RequestBody CreateCommentRequest createCommentRequest) { + return ResponseEntity.ok(SuccessResponse.create(BoardCommentResponseMessage.CREATE_BOARD_COMMENT_SUCCESS.getMessage(), this.createBoardCommentUseCase.createBoardComment(user.getSocialId(), teamId, boardId, createCommentRequest))); } /** @@ -52,7 +51,7 @@ public ResponseEntity deleteBoardComment(@AuthenticationPrincip @PathVariable Long boardId, @PathVariable Long commentId) { this.deleteBoardCommentUseCase.deleteBoardComment(user.getSocialId(), teamId, boardId, commentId); - return ResponseEntity.ok(SuccessResponse.create(DELETE_BOARD_COMMENT_SUCCESS.getMessage())); + return ResponseEntity.ok(SuccessResponse.create(BoardCommentResponseMessage.DELETE_BOARD_COMMENT_SUCCESS.getMessage())); } @@ -62,9 +61,9 @@ public ResponseEntity deleteBoardComment(@AuthenticationPrincip * 작성자 : 김민수 */ @GetMapping - public ResponseEntity> getBoardCommentAll(@AuthenticationPrincipal User user, - @PathVariable Long teamId, - @PathVariable Long boardId) { - return ResponseEntity.ok(SuccessResponse.create(GET_BOARD_ALL_SUCCESS.getMessage(), this.getBoardCommentUseCase.getBoardCommentAll(user.getSocialId(), teamId, boardId))); + public ResponseEntity> getBoardCommentAll(@AuthenticationPrincipal User user, + @PathVariable Long teamId, + @PathVariable Long boardId) { + return ResponseEntity.ok(SuccessResponse.create(GET_BOARD_COMMENT_ALL_SUCCESS.getMessage(), this.getBoardCommentUseCase.getBoardCommentAll(user.getSocialId(), teamId, boardId))); } } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/MissionArchiveRes.java b/src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/MissionArchiveRes.java index a0d5e88f..871786c3 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/MissionArchiveRes.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/MissionArchiveRes.java @@ -1,9 +1,9 @@ package com.moing.backend.domain.missionArchive.application.dto.res; -import lombok.*; - -import javax.annotation.Nullable; -import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; @AllArgsConstructor @Builder @NoArgsConstructor @@ -19,6 +19,7 @@ public class MissionArchiveRes { private String heartStatus; private Long hearts; private String contents; + private Long comments; public void updateCount(Long count) { this.count = count; From d73cf59ff7682075fbd4af14e1ef433c291c52c2 Mon Sep 17 00:00:00 2001 From: minsu20 Date: Tue, 7 May 2024 01:10:49 +0900 Subject: [PATCH 3/4] =?UTF-8?q?MNG-20=20feat:=20MissionComment=20CRUD=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/MissionArchiveMapper.java | 1 + .../domain/entity/MissionArchive.java | 10 ++- .../mapper/MissionCommentMapper.java | 20 +++++ .../service/CreateMissionCommentUseCase.java | 41 +++++++++ .../service/DeleteMissionCommentUseCase.java | 39 +++++++++ .../service/GetMissionCommentUseCase.java | 27 ++++++ .../service/SendMissionAlarmUseCase.java | 4 + .../domain/entity/MissionComment.java | 48 +++++++++++ .../MissionCommentCustomRepository.java | 14 +++ .../MissionCommentCustomRepositoryImpl.java | 86 +++++++++++++++++++ .../repository/MissionCommentRepository.java | 12 +++ .../service/MissionCommentDeleteService.java | 18 ++++ .../service/MissionCommentGetService.java | 34 ++++++++ .../service/MissionCommentSaveService.java | 19 ++++ .../exception/MissionCommentException.java | 11 +++ .../NotAuthByMissionCommentException.java | 11 +++ .../NotFoundByMissionCommentIdException.java | 11 +++ .../MissionCommentController.java | 69 +++++++++++++++ .../service/ReportCreateUseCase.java | 8 +- .../team/presentation/TeamController.java | 12 +++ .../response/BaseMissionServiceResponse.java | 19 ++++ .../backend/global/response/ErrorCode.java | 5 +- .../global/utils/BaseMissionService.java | 32 +++++++ 23 files changed, 543 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/moing/backend/domain/missionComment/application/mapper/MissionCommentMapper.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/application/service/CreateMissionCommentUseCase.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/application/service/DeleteMissionCommentUseCase.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/application/service/GetMissionCommentUseCase.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/application/service/SendMissionAlarmUseCase.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/domain/entity/MissionComment.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/domain/repository/MissionCommentCustomRepository.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/domain/repository/MissionCommentCustomRepositoryImpl.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/domain/repository/MissionCommentRepository.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/domain/service/MissionCommentDeleteService.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/domain/service/MissionCommentGetService.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/domain/service/MissionCommentSaveService.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/exception/MissionCommentException.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/exception/NotAuthByMissionCommentException.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/exception/NotFoundByMissionCommentIdException.java create mode 100644 src/main/java/com/moing/backend/domain/missionComment/presentation/MissionCommentController.java create mode 100644 src/main/java/com/moing/backend/global/response/BaseMissionServiceResponse.java create mode 100644 src/main/java/com/moing/backend/global/utils/BaseMissionService.java diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/mapper/MissionArchiveMapper.java b/src/main/java/com/moing/backend/domain/missionArchive/application/mapper/MissionArchiveMapper.java index b84fe771..7dc09888 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/mapper/MissionArchiveMapper.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/mapper/MissionArchiveMapper.java @@ -51,6 +51,7 @@ public static MissionArchiveRes mapToMissionArchiveRes(MissionArchive missionArc .filter(heart -> heart.getMissionArchive().equals( missionArchive))// heartStatus가 true인 요소만 필터링 .count()) .contents(missionArchive.getContents()) + .comments(missionArchive.getCommentNum()) .build(); } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/entity/MissionArchive.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/entity/MissionArchive.java index 90826b52..2a60411f 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/entity/MissionArchive.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/entity/MissionArchive.java @@ -3,7 +3,6 @@ import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.mission.domain.entity.Mission; -import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveReq; import com.moing.backend.domain.missionHeart.domain.entity.MissionHeart; import com.moing.backend.global.entity.BaseTimeEntity; @@ -50,6 +49,8 @@ public class MissionArchive extends BaseTimeEntity { // 1회 미션을 저장 @OneToMany(mappedBy = "missionArchive", cascade = CascadeType.REMOVE) private List heartList = new ArrayList<>(); + //반정규화 + private Long commentNum; public void updateArchive(MissionArchiveReq missionArchiveReq) { this.archive = missionArchiveReq.getArchive(); @@ -60,6 +61,13 @@ public void updateCount(Long count) { this.count = count; } + public void incrComNum() { + this.commentNum++; + } + + public void decrComNum() { + this.commentNum--; + } } diff --git a/src/main/java/com/moing/backend/domain/missionComment/application/mapper/MissionCommentMapper.java b/src/main/java/com/moing/backend/domain/missionComment/application/mapper/MissionCommentMapper.java new file mode 100644 index 00000000..a47b6e68 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/application/mapper/MissionCommentMapper.java @@ -0,0 +1,20 @@ +package com.moing.backend.domain.missionComment.application.mapper; + +import com.moing.backend.domain.comment.application.dto.request.CreateCommentRequest; +import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; +import com.moing.backend.domain.missionComment.domain.entity.MissionComment; +import com.moing.backend.domain.teamMember.domain.entity.TeamMember; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class MissionCommentMapper { + public static MissionComment toMissionComment(TeamMember teamMember, MissionArchive missionArchive, CreateCommentRequest createCommentRequest, boolean isLeader) { + MissionComment missionComment=new MissionComment(); + missionComment.init(createCommentRequest.getContent(),isLeader); + missionComment.updateMissionArchive(missionArchive); + missionComment.updateTeamMember(teamMember); + return missionComment; + } +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/missionComment/application/service/CreateMissionCommentUseCase.java b/src/main/java/com/moing/backend/domain/missionComment/application/service/CreateMissionCommentUseCase.java new file mode 100644 index 00000000..54a0ef10 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/application/service/CreateMissionCommentUseCase.java @@ -0,0 +1,41 @@ +package com.moing.backend.domain.missionComment.application.service; + +import com.moing.backend.domain.boardComment.application.service.SendCommentAlarmUseCase; +import com.moing.backend.domain.comment.application.dto.request.CreateCommentRequest; +import com.moing.backend.domain.comment.application.dto.response.CreateCommentResponse; +import com.moing.backend.domain.missionComment.application.mapper.MissionCommentMapper; +import com.moing.backend.domain.missionComment.domain.entity.MissionComment; +import com.moing.backend.domain.missionComment.domain.service.MissionCommentSaveService; +import com.moing.backend.domain.team.application.service.CheckLeaderUseCase; +import com.moing.backend.global.response.BaseMissionServiceResponse; +import com.moing.backend.global.utils.BaseMissionService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class CreateMissionCommentUseCase { + + private final MissionCommentSaveService missionCommentSaveService; + private final BaseMissionService baseMissionService; + private final CheckLeaderUseCase checkLeaderUseCase; + private final SendCommentAlarmUseCase sendCommentAlarmUseCase; + /** + * 게시글 댓글 생성 + */ + public CreateCommentResponse createBoardComment(String socialId, Long teamId, Long missionArchiveId, CreateCommentRequest createCommentRequest) { + // 1. 미션 게시글 댓글 생성 + BaseMissionServiceResponse data = baseMissionService.getCommonData(socialId, teamId, missionArchiveId); + boolean isLeader = checkLeaderUseCase.isTeamLeader(data.getMember(), data.getTeam()); + MissionComment missionComment = missionCommentSaveService.saveComment(MissionCommentMapper.toMissionComment(data.getTeamMember(), data.getMissionArchive(), createCommentRequest, isLeader)); + // 2. 미션 게시글 댓글 개수 증가 + data.getMissionArchive().incrComNum(); +// // 3. 미션 게시글 댓글 알림 +// sendCommentAlarmUseCase.sendNewUploadAlarm(data, missionComment); + return new CreateCommentResponse(missionComment.getMissionCommentId()); + } +} + diff --git a/src/main/java/com/moing/backend/domain/missionComment/application/service/DeleteMissionCommentUseCase.java b/src/main/java/com/moing/backend/domain/missionComment/application/service/DeleteMissionCommentUseCase.java new file mode 100644 index 00000000..0c87c5b4 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/application/service/DeleteMissionCommentUseCase.java @@ -0,0 +1,39 @@ +package com.moing.backend.domain.missionComment.application.service; + +import com.moing.backend.domain.boardComment.exception.NotAuthByBoardCommentException; +import com.moing.backend.domain.missionComment.domain.entity.MissionComment; +import com.moing.backend.domain.missionComment.domain.service.MissionCommentDeleteService; +import com.moing.backend.domain.missionComment.domain.service.MissionCommentGetService; +import com.moing.backend.global.response.BaseMissionServiceResponse; +import com.moing.backend.global.utils.BaseMissionService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class DeleteMissionCommentUseCase { + + private final MissionCommentGetService missionCommentGetService; + private final MissionCommentDeleteService missionCommentDeleteService; + private final BaseMissionService baseMissionService; + + /** + * 게시글 댓글 삭제 + */ + + public void deleteMissionComment(String socialId, Long teamId, Long missionArchiveId, Long boardCommentId){ + // 1. 게시글 댓글 조회 + BaseMissionServiceResponse data = baseMissionService.getCommonData(socialId, teamId, missionArchiveId); + MissionComment missionComment =missionCommentGetService.getComment(boardCommentId); + // 2. 게시글 댓글 작성자만 + if (data.getTeamMember() == missionComment.getTeamMember()) { + // 3. 삭제 + missionCommentDeleteService.deleteComment(missionComment); + // 4. 댓글 개수 줄이기 + data.getMissionArchive().decrComNum(); + } else throw new NotAuthByBoardCommentException(); + } +} diff --git a/src/main/java/com/moing/backend/domain/missionComment/application/service/GetMissionCommentUseCase.java b/src/main/java/com/moing/backend/domain/missionComment/application/service/GetMissionCommentUseCase.java new file mode 100644 index 00000000..b3d5ca70 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/application/service/GetMissionCommentUseCase.java @@ -0,0 +1,27 @@ +package com.moing.backend.domain.missionComment.application.service; + +import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse; +import com.moing.backend.domain.missionComment.domain.service.MissionCommentGetService; +import com.moing.backend.global.response.BaseMissionServiceResponse; +import com.moing.backend.global.utils.BaseMissionService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class GetMissionCommentUseCase { + + private final MissionCommentGetService missionCommentGetService; + private final BaseMissionService baseMissionService; + + /** + * 게시글 댓글 전체 조회 + */ + public GetCommentResponse getBoardCommentAll(String socialId, Long teamId, Long missionArchiveId){ + BaseMissionServiceResponse data = baseMissionService.getCommonData(socialId, teamId, missionArchiveId); + return missionCommentGetService.getCommentAll(missionArchiveId, data.getTeamMember()); + } +} diff --git a/src/main/java/com/moing/backend/domain/missionComment/application/service/SendMissionAlarmUseCase.java b/src/main/java/com/moing/backend/domain/missionComment/application/service/SendMissionAlarmUseCase.java new file mode 100644 index 00000000..ced7594c --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/application/service/SendMissionAlarmUseCase.java @@ -0,0 +1,4 @@ +package com.moing.backend.domain.missionComment.application.service; + +public class SendMissionAlarmUseCase { +} diff --git a/src/main/java/com/moing/backend/domain/missionComment/domain/entity/MissionComment.java b/src/main/java/com/moing/backend/domain/missionComment/domain/entity/MissionComment.java new file mode 100644 index 00000000..a3941527 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/domain/entity/MissionComment.java @@ -0,0 +1,48 @@ +package com.moing.backend.domain.missionComment.domain.entity; + +import com.moing.backend.domain.comment.domain.entity.Comment; +import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; +import com.moing.backend.domain.teamMember.domain.entity.TeamMember; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Entity +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class MissionComment extends Comment { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "mission_comment_id") + private Long missionCommentId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "team_member_id") + private TeamMember teamMember; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "mission_archive_id") + private MissionArchive missionArchive; + + /** + * 연관관계 매핑 + */ + public void updateMissionArchive(MissionArchive missionArchive) { + this.missionArchive=missionArchive; + } + + public void updateTeamMember(TeamMember teamMember) { + this.teamMember = teamMember; + } + + public void init(String content, boolean isLeader){ + this.content=content; + this.isLeader=isLeader; + } +} diff --git a/src/main/java/com/moing/backend/domain/missionComment/domain/repository/MissionCommentCustomRepository.java b/src/main/java/com/moing/backend/domain/missionComment/domain/repository/MissionCommentCustomRepository.java new file mode 100644 index 00000000..253b0654 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/domain/repository/MissionCommentCustomRepository.java @@ -0,0 +1,14 @@ +package com.moing.backend.domain.missionComment.domain.repository; + +import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse; +import com.moing.backend.domain.history.application.dto.response.NewUploadInfo; +import com.moing.backend.domain.teamMember.domain.entity.TeamMember; + +import java.util.List; +import java.util.Optional; + +public interface MissionCommentCustomRepository { + GetCommentResponse findMissionCommentAll(Long missionArchiveId, TeamMember teamMember); + + Optional> findNewUploadInfo(Long memberId, Long missionArchiveId); +} diff --git a/src/main/java/com/moing/backend/domain/missionComment/domain/repository/MissionCommentCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionComment/domain/repository/MissionCommentCustomRepositoryImpl.java new file mode 100644 index 00000000..aecacdad --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/domain/repository/MissionCommentCustomRepositoryImpl.java @@ -0,0 +1,86 @@ +package com.moing.backend.domain.missionComment.domain.repository; + +import com.moing.backend.domain.block.domain.repository.BlockRepositoryUtils; +import com.moing.backend.domain.comment.application.dto.response.CommentBlocks; +import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse; +import com.moing.backend.domain.comment.application.dto.response.QCommentBlocks; +import com.moing.backend.domain.history.application.dto.response.NewUploadInfo; +import com.moing.backend.domain.teamMember.domain.entity.QTeamMember; +import com.moing.backend.domain.teamMember.domain.entity.TeamMember; +import com.querydsl.core.types.ExpressionUtils; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.JPAExpressions; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import javax.persistence.EntityManager; +import java.util.List; +import java.util.Optional; + +import static com.moing.backend.domain.member.domain.entity.QMember.member; +import static com.moing.backend.domain.missionComment.domain.entity.QMissionComment.missionComment; +import static com.moing.backend.domain.teamMember.domain.entity.QTeamMember.teamMember; + +public class MissionCommentCustomRepositoryImpl implements MissionCommentCustomRepository{ + + private final JPAQueryFactory queryFactory; + + public MissionCommentCustomRepositoryImpl(EntityManager em) { + this.queryFactory = new JPAQueryFactory(em); + } + + + @Override + public GetCommentResponse findMissionCommentAll(Long missionArchiveId, TeamMember teamMember) { + + BooleanExpression blockCondition = BlockRepositoryUtils.blockCondition(teamMember.getTeamMemberId(), missionComment.teamMember.member.memberId); + + List commentBlocks = queryFactory + .select(new QCommentBlocks( + missionComment.missionCommentId, + missionComment.content, + missionComment.teamMember.member.nickName, + missionComment.isLeader, + missionComment.teamMember.member.profileImage, + ExpressionUtils.as(JPAExpressions + .selectOne() + .from(QTeamMember.teamMember) + .where(QTeamMember.teamMember.eq(teamMember) + .and(QTeamMember.teamMember.eq(missionComment.teamMember))) + .exists(), "isWriter"), + missionComment.teamMember.isDeleted, + missionComment.createdDate, + missionComment.teamMember.member.memberId)) + .from(missionComment) + .leftJoin(missionComment.teamMember, QTeamMember.teamMember) + .leftJoin(missionComment.teamMember.member, member) + .where(missionComment.missionArchive.id.eq(missionArchiveId) + .and(blockCondition)) + .orderBy(missionComment.createdDate.asc()) + .fetch(); + + return new GetCommentResponse(commentBlocks); + } + + @Override + public Optional> findNewUploadInfo(Long memberId, Long missionArchiveId) { + BooleanExpression blockCondition= BlockRepositoryUtils.blockCondition(missionComment.teamMember.member.memberId, memberId); + + List result = queryFactory.select(Projections.constructor(NewUploadInfo.class, + missionComment.teamMember.member.fcmToken, + missionComment.teamMember.member.memberId, + missionComment.teamMember.member.isNewUploadPush, + missionComment.teamMember.member.isSignOut)) + .distinct() + .from(missionComment) + .leftJoin(missionComment.teamMember, teamMember) + .leftJoin(missionComment.teamMember.member, member) + .where(missionComment.missionArchive.id.eq(missionArchiveId) //게시글의 댓글인데 + .and(missionComment.teamMember.member.memberId.ne(memberId)) //나는 포함 안하고 + .and(missionComment.teamMember.isDeleted.eq(false)) //탈퇴한 사람도 포함 안함 + .and(blockCondition)) + .fetch(); + + return result.isEmpty() ? Optional.empty() : Optional.of(result); + } +} diff --git a/src/main/java/com/moing/backend/domain/missionComment/domain/repository/MissionCommentRepository.java b/src/main/java/com/moing/backend/domain/missionComment/domain/repository/MissionCommentRepository.java new file mode 100644 index 00000000..8c7d8e35 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/domain/repository/MissionCommentRepository.java @@ -0,0 +1,12 @@ +package com.moing.backend.domain.missionComment.domain.repository; + +import com.moing.backend.domain.missionComment.domain.entity.MissionComment; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface MissionCommentRepository extends JpaRepository, MissionCommentCustomRepository { + + Optional findMissionCommentByMissionCommentId(Long missionCommentId); + +} diff --git a/src/main/java/com/moing/backend/domain/missionComment/domain/service/MissionCommentDeleteService.java b/src/main/java/com/moing/backend/domain/missionComment/domain/service/MissionCommentDeleteService.java new file mode 100644 index 00000000..b41f541a --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/domain/service/MissionCommentDeleteService.java @@ -0,0 +1,18 @@ +package com.moing.backend.domain.missionComment.domain.service; + +import com.moing.backend.domain.comment.domain.service.CommentDeleteService; +import com.moing.backend.domain.missionComment.domain.entity.MissionComment; +import com.moing.backend.domain.missionComment.domain.repository.MissionCommentRepository; +import com.moing.backend.global.annotation.DomainService; +import lombok.RequiredArgsConstructor; + +@DomainService +@RequiredArgsConstructor +public class MissionCommentDeleteService implements CommentDeleteService { + + private final MissionCommentRepository missionCommentRepository; + @Override + public void deleteComment(MissionComment comment) { + missionCommentRepository.delete(comment); + } +} diff --git a/src/main/java/com/moing/backend/domain/missionComment/domain/service/MissionCommentGetService.java b/src/main/java/com/moing/backend/domain/missionComment/domain/service/MissionCommentGetService.java new file mode 100644 index 00000000..501dfe2b --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/domain/service/MissionCommentGetService.java @@ -0,0 +1,34 @@ +package com.moing.backend.domain.missionComment.domain.service; + +import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse; +import com.moing.backend.domain.comment.domain.service.CommentGetService; +import com.moing.backend.domain.history.application.dto.response.NewUploadInfo; +import com.moing.backend.domain.missionComment.domain.entity.MissionComment; +import com.moing.backend.domain.missionComment.domain.repository.MissionCommentRepository; +import com.moing.backend.domain.missionComment.exception.NotFoundByMissionCommentIdException; +import com.moing.backend.domain.teamMember.domain.entity.TeamMember; +import com.moing.backend.global.annotation.DomainService; +import lombok.RequiredArgsConstructor; + +import java.util.List; +import java.util.Optional; +@DomainService +@RequiredArgsConstructor +public class MissionCommentGetService implements CommentGetService { + private final MissionCommentRepository missionCommentRepository; + + @Override + public MissionComment getComment(Long commentId) { + return missionCommentRepository.findMissionCommentByMissionCommentId(commentId).orElseThrow(NotFoundByMissionCommentIdException::new); + } + + @Override + public GetCommentResponse getCommentAll(Long missionArchiveId, TeamMember teamMember) { + return missionCommentRepository.findMissionCommentAll(missionArchiveId, teamMember); + } + + @Override + public Optional> getNewUploadInfo(Long memberId, Long missionArchiveId) { + return missionCommentRepository.findNewUploadInfo(memberId, missionArchiveId); + } +} diff --git a/src/main/java/com/moing/backend/domain/missionComment/domain/service/MissionCommentSaveService.java b/src/main/java/com/moing/backend/domain/missionComment/domain/service/MissionCommentSaveService.java new file mode 100644 index 00000000..a62e2e5a --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/domain/service/MissionCommentSaveService.java @@ -0,0 +1,19 @@ +package com.moing.backend.domain.missionComment.domain.service; + +import com.moing.backend.domain.comment.domain.service.CommentSaveService; +import com.moing.backend.domain.missionComment.domain.entity.MissionComment; +import com.moing.backend.domain.missionComment.domain.repository.MissionCommentRepository; +import com.moing.backend.global.annotation.DomainService; +import lombok.RequiredArgsConstructor; + +@DomainService +@RequiredArgsConstructor +public class MissionCommentSaveService implements CommentSaveService { + + private final MissionCommentRepository missionCommentRepository; + + @Override + public MissionComment saveComment(MissionComment comment) { + return missionCommentRepository.save(comment); + } +} diff --git a/src/main/java/com/moing/backend/domain/missionComment/exception/MissionCommentException.java b/src/main/java/com/moing/backend/domain/missionComment/exception/MissionCommentException.java new file mode 100644 index 00000000..3079b682 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/exception/MissionCommentException.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.missionComment.exception; + +import com.moing.backend.global.exception.ApplicationException; +import com.moing.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public abstract class MissionCommentException extends ApplicationException { + protected MissionCommentException(ErrorCode errorCode, HttpStatus httpStatus) { + super(errorCode, httpStatus); + } +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/missionComment/exception/NotAuthByMissionCommentException.java b/src/main/java/com/moing/backend/domain/missionComment/exception/NotAuthByMissionCommentException.java new file mode 100644 index 00000000..04e9b114 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/exception/NotAuthByMissionCommentException.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.missionComment.exception; + +import com.moing.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public class NotAuthByMissionCommentException extends MissionCommentException { + public NotAuthByMissionCommentException() { + super(ErrorCode.NOT_AUTH_BY_MISSION_COMMENT_ID_ERROR, + HttpStatus.NOT_FOUND); + } +} diff --git a/src/main/java/com/moing/backend/domain/missionComment/exception/NotFoundByMissionCommentIdException.java b/src/main/java/com/moing/backend/domain/missionComment/exception/NotFoundByMissionCommentIdException.java new file mode 100644 index 00000000..94c9fcae --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/exception/NotFoundByMissionCommentIdException.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.missionComment.exception; + +import com.moing.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public class NotFoundByMissionCommentIdException extends MissionCommentException { + public NotFoundByMissionCommentIdException() { + super(ErrorCode.NOT_FOUND_BY_MISSION_COMMENT_ID_ERROR, + HttpStatus.NOT_FOUND); + } +} diff --git a/src/main/java/com/moing/backend/domain/missionComment/presentation/MissionCommentController.java b/src/main/java/com/moing/backend/domain/missionComment/presentation/MissionCommentController.java new file mode 100644 index 00000000..21b3ac18 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionComment/presentation/MissionCommentController.java @@ -0,0 +1,69 @@ +package com.moing.backend.domain.missionComment.presentation; + +import com.moing.backend.domain.boardComment.presentattion.constant.BoardCommentResponseMessage; +import com.moing.backend.domain.comment.application.dto.request.CreateCommentRequest; +import com.moing.backend.domain.comment.application.dto.response.CreateCommentResponse; +import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse; +import com.moing.backend.domain.missionComment.application.service.CreateMissionCommentUseCase; +import com.moing.backend.domain.missionComment.application.service.DeleteMissionCommentUseCase; +import com.moing.backend.domain.missionComment.application.service.GetMissionCommentUseCase; +import com.moing.backend.global.config.security.dto.User; +import com.moing.backend.global.response.SuccessResponse; +import lombok.AllArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +import static com.moing.backend.domain.boardComment.presentattion.constant.BoardCommentResponseMessage.GET_BOARD_COMMENT_ALL_SUCCESS; + +@RestController +@AllArgsConstructor +@RequestMapping("/api/{teamId}/{missionArchiveId}/mcomment") +public class MissionCommentController { + + private final CreateMissionCommentUseCase createMissionCommentUseCase; + private final DeleteMissionCommentUseCase deleteMissionCommentUseCase; + private final GetMissionCommentUseCase getMissionCommentUseCase; + + /** + * 댓글 생성 + * [POST] api/{teamId}/{missionArchiveId}/comment + * 작성자 : 김민수 + */ + @PostMapping + public ResponseEntity> createMissionComment(@AuthenticationPrincipal User user, + @PathVariable Long teamId, + @PathVariable Long missionArchiveId, + @Valid @RequestBody CreateCommentRequest createCommentRequest) { + return ResponseEntity.ok(SuccessResponse.create(BoardCommentResponseMessage.CREATE_BOARD_COMMENT_SUCCESS.getMessage(), this.createMissionCommentUseCase.createBoardComment(user.getSocialId(), teamId, missionArchiveId, createCommentRequest))); + } + + /** + * 댓글 삭제 + * [DELETE] api/{teamId}/{missionArchiveId}/comment/{commentId} + * 작성자 : 김민수 + */ + @DeleteMapping("/{commentId}") + public ResponseEntity deleteMissionComment(@AuthenticationPrincipal User user, + @PathVariable Long teamId, + @PathVariable Long missionArchiveId, + @PathVariable Long commentId) { + this.deleteMissionCommentUseCase.deleteMissionComment(user.getSocialId(), teamId, missionArchiveId, commentId); + return ResponseEntity.ok(SuccessResponse.create(BoardCommentResponseMessage.DELETE_BOARD_COMMENT_SUCCESS.getMessage())); + } + + + /** + * 댓글 전체 조회 + * [GET] api/{teamId}/{missionArchiveId}/mcomment + * 작성자 : 김민수 + */ + @GetMapping + public ResponseEntity> getMissionCommentAll(@AuthenticationPrincipal User user, + @PathVariable Long teamId, + @PathVariable Long missionArchiveId) { + return ResponseEntity.ok(SuccessResponse.create(GET_BOARD_COMMENT_ALL_SUCCESS.getMessage(), this.getMissionCommentUseCase.getBoardCommentAll(user.getSocialId(), teamId, missionArchiveId))); + } +} diff --git a/src/main/java/com/moing/backend/domain/report/application/service/ReportCreateUseCase.java b/src/main/java/com/moing/backend/domain/report/application/service/ReportCreateUseCase.java index 999140b9..d96b35ee 100644 --- a/src/main/java/com/moing/backend/domain/report/application/service/ReportCreateUseCase.java +++ b/src/main/java/com/moing/backend/domain/report/application/service/ReportCreateUseCase.java @@ -3,7 +3,6 @@ import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; import com.moing.backend.domain.board.domain.entity.Board; import com.moing.backend.domain.board.domain.service.BoardGetService; -import com.moing.backend.domain.boardComment.application.dto.request.CreateBoardCommentRequest; import com.moing.backend.domain.boardComment.domain.entity.BoardComment; import com.moing.backend.domain.boardComment.domain.service.BoardCommentGetService; import com.moing.backend.domain.member.domain.service.MemberGetService; @@ -13,7 +12,6 @@ import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService; -import com.moing.backend.domain.missionState.domain.entity.MissionState; import com.moing.backend.domain.report.application.mapper.ReportMapper; import com.moing.backend.domain.report.domain.entity.Report; import com.moing.backend.domain.report.domain.entity.constant.ReportType; @@ -56,12 +54,10 @@ public Long createReport(String socialId, Long targetId, String reportType) { .build()); } else if (reportType.equals(ReportType.COMMENT.name())) { - BoardComment boardComment = boardCommentGetService.getBoardComment(targetId); + BoardComment boardComment = boardCommentGetService.getComment(targetId); targetMemberNickName = boardComment.getTeamMember().getMember().getNickName(); + boardComment.updateContent(REPORT_BOARD_MESSAGE); - boardComment.updateBoardComment(CreateBoardCommentRequest.builder() - .content(REPORT_BOARD_MESSAGE) - .build()); } else { MissionArchive missionArchive = missionArchiveQueryService.findByMissionArchiveId(targetId); diff --git a/src/main/java/com/moing/backend/domain/team/presentation/TeamController.java b/src/main/java/com/moing/backend/domain/team/presentation/TeamController.java index 8e24226f..12de51b9 100644 --- a/src/main/java/com/moing/backend/domain/team/presentation/TeamController.java +++ b/src/main/java/com/moing/backend/domain/team/presentation/TeamController.java @@ -137,4 +137,16 @@ public ResponseEntity> getTeamCount(@Authe return ResponseEntity.ok(SuccessResponse.create(GET_TEAM_COUNT_SUCCESS.getMessage(), this.getTeamUseCase.getTeamCount(user.getSocialId(),teamId))); } + @PostMapping(value = "/test", name = "테스트") + public void test() { + Thread thread1 = new Thread(() -> { + this.signInTeamUseCase.signInTeam("KAKAO@tester01", 1L); + }); + Thread thread2 = new Thread(() -> { + this.signInTeamUseCase.signInTeam("KAKAO@tester01", 1L); + }); + thread1.start(); + thread2.start(); + } + } diff --git a/src/main/java/com/moing/backend/global/response/BaseMissionServiceResponse.java b/src/main/java/com/moing/backend/global/response/BaseMissionServiceResponse.java new file mode 100644 index 00000000..f0ee645d --- /dev/null +++ b/src/main/java/com/moing/backend/global/response/BaseMissionServiceResponse.java @@ -0,0 +1,19 @@ +package com.moing.backend.global.response; + +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; +import com.moing.backend.domain.team.domain.entity.Team; +import com.moing.backend.domain.teamMember.domain.entity.TeamMember; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class BaseMissionServiceResponse { + private Member member; + private Team team; + private MissionArchive missionArchive; + private TeamMember teamMember; +} diff --git a/src/main/java/com/moing/backend/global/response/ErrorCode.java b/src/main/java/com/moing/backend/global/response/ErrorCode.java index fc28ead7..72516a96 100644 --- a/src/main/java/com/moing/backend/global/response/ErrorCode.java +++ b/src/main/java/com/moing/backend/global/response/ErrorCode.java @@ -2,7 +2,6 @@ import lombok.AllArgsConstructor; import lombok.Getter; -import org.springframework.http.HttpStatus; @Getter @AllArgsConstructor @@ -63,6 +62,10 @@ public enum ErrorCode { NOT_FOUND_BY_BOARD_COMMENT_ID_ERROR("BC0001","해당 boardCommentId인 댓글이 존재하지 않습니다."), NOT_AUTH_BY_BOARD_COMMENT_ID_ERROR("BC0002","권한이 없습니다."), + //미션 댓글 관련 에러 코드 + NOT_FOUND_BY_MISSION_COMMENT_ID_ERROR("MC0001", "해당 missionCommentId인 댓글이 존재하지 않습니다."), + NOT_AUTH_BY_MISSION_COMMENT_ID_ERROR("MC0002", "권한이 없습니다."), + //알림 관련 에러 코드 NOT_FOUND_BY_ALARM_HISOTRY_ID_ERROR("AH0001","해당 alarmHistoryId인 알림이 존재하지 않습니다."), diff --git a/src/main/java/com/moing/backend/global/utils/BaseMissionService.java b/src/main/java/com/moing/backend/global/utils/BaseMissionService.java new file mode 100644 index 00000000..84311b40 --- /dev/null +++ b/src/main/java/com/moing/backend/global/utils/BaseMissionService.java @@ -0,0 +1,32 @@ +package com.moing.backend.global.utils; + +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.member.domain.service.MemberGetService; +import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; +import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService; +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.response.BaseMissionServiceResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class BaseMissionService { + + private final MemberGetService memberGetService; + private final TeamGetService teamGetService; + private final MissionArchiveQueryService missionArchiveQueryService; + private final TeamMemberGetService teamMemberGetService; + + public BaseMissionServiceResponse getCommonData(String socialId, Long teamId, Long missionArchiveId){ + Member member = memberGetService.getMemberBySocialId(socialId); + Team team = teamGetService.getTeamByTeamId(teamId); + MissionArchive missionArchive=missionArchiveQueryService.findByMissionArchiveId(missionArchiveId); + TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); + + return new BaseMissionServiceResponse(member, team, missionArchive, teamMember); + } +} From cd5ac80d4c1a95ab2f9bdcd5727d0c66a2805b64 Mon Sep 17 00:00:00 2001 From: minsu20 Date: Tue, 7 May 2024 01:12:48 +0900 Subject: [PATCH 4/4] =?UTF-8?q?MNG-20=20docs:=20docs=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../asciidoc/MissionArchiveComment_API.adoc | 17 ++ src/docs/asciidoc/api.adoc | 2 + .../board/presentation/BoardController.java | 12 -- .../BoardCommentControllerTest.java | 22 +- .../MissionArchiveControllerTest.java | 17 +- .../domain/MissionRepositoryTest.java | 22 ++ .../MissionCommentControllerTest.java | 192 ++++++++++++++++++ 7 files changed, 256 insertions(+), 28 deletions(-) create mode 100644 src/docs/asciidoc/MissionArchiveComment_API.adoc create mode 100644 src/test/java/com/moing/backend/domain/missionComment/domain/MissionRepositoryTest.java create mode 100644 src/test/java/com/moing/backend/domain/missionComment/presentation/MissionCommentControllerTest.java diff --git a/src/docs/asciidoc/MissionArchiveComment_API.adoc b/src/docs/asciidoc/MissionArchiveComment_API.adoc new file mode 100644 index 00000000..9ec5e7fa --- /dev/null +++ b/src/docs/asciidoc/MissionArchiveComment_API.adoc @@ -0,0 +1,17 @@ +[[Mission-Comment-API]] += Mission Comment API + +[[Mission-Comment-댓글-생성]] +== Mission Comment 댓글 생성 +operation::mission-comment-controller-test/create_mission_comment[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] +--- + +[[Mission-Comment-댓글-삭제]] +== Mission Comment 댓글 삭제 +operation::mission-comment-controller-test/delete_mission_comment[snippets='http-request,path-parameters,response-fields'] +--- + +[[MissionArchive-Comment-댓글-전체-조회]] +== Mission Comment 댓글 전체 조회 +operation::mission-comment-controller-test/get_board_comment_all[snippets='http-request,path-parameters,http-response,response-fields'] +--- \ No newline at end of file diff --git a/src/docs/asciidoc/api.adoc b/src/docs/asciidoc/api.adoc index 41519d3c..0addb28b 100644 --- a/src/docs/asciidoc/api.adoc +++ b/src/docs/asciidoc/api.adoc @@ -22,6 +22,8 @@ include::Mission-API.adoc[] include::MissionArchive-API.adoc[] +include::MissionArchiveComment_API.adoc[] + include::MissionBoard-API.adoc[] include::MissionGatherBoard-API.adoc[] diff --git a/src/main/java/com/moing/backend/domain/board/presentation/BoardController.java b/src/main/java/com/moing/backend/domain/board/presentation/BoardController.java index 8ae0002f..6e0c89c4 100644 --- a/src/main/java/com/moing/backend/domain/board/presentation/BoardController.java +++ b/src/main/java/com/moing/backend/domain/board/presentation/BoardController.java @@ -92,16 +92,4 @@ public ResponseEntity> getBoardAll(@Authent return ResponseEntity.ok(SuccessResponse.create(GET_BOARD_ALL_SUCCESS.getMessage(), this.getBoardUseCase.getAllBoard(user.getSocialId(), teamId))); } - @PostMapping("/test") - public void test() { - Thread thread1 = new Thread(() -> { - this.getBoardUseCase.getBoardDetail("KAKAO@tester01", 1L,1L); - }); - Thread thread2 = new Thread(() -> { - this.getBoardUseCase.getBoardDetail("KAKAO@tester01", 1L,1L); - }); - thread1.start(); - thread2.start(); - } - } diff --git a/src/test/java/com/moing/backend/domain/boardComment/presentation/BoardCommentControllerTest.java b/src/test/java/com/moing/backend/domain/boardComment/presentation/BoardCommentControllerTest.java index 0b8ea674..0d14b897 100644 --- a/src/test/java/com/moing/backend/domain/boardComment/presentation/BoardCommentControllerTest.java +++ b/src/test/java/com/moing/backend/domain/boardComment/presentation/BoardCommentControllerTest.java @@ -1,14 +1,14 @@ package com.moing.backend.domain.boardComment.presentation; import com.moing.backend.config.CommonControllerTest; -import com.moing.backend.domain.boardComment.application.dto.request.CreateBoardCommentRequest; -import com.moing.backend.domain.boardComment.application.dto.response.CommentBlocks; -import com.moing.backend.domain.boardComment.application.dto.response.CreateBoardCommentResponse; -import com.moing.backend.domain.boardComment.application.dto.response.GetBoardCommentResponse; import com.moing.backend.domain.boardComment.application.service.CreateBoardCommentUseCase; import com.moing.backend.domain.boardComment.application.service.DeleteBoardCommentUseCase; import com.moing.backend.domain.boardComment.application.service.GetBoardCommentUseCase; import com.moing.backend.domain.boardComment.presentattion.BoardCommentController; +import com.moing.backend.domain.comment.application.dto.request.CreateCommentRequest; +import com.moing.backend.domain.comment.application.dto.response.CommentBlocks; +import com.moing.backend.domain.comment.application.dto.response.CreateCommentResponse; +import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -44,14 +44,14 @@ public void create_board_comment() throws Exception { //given Long teamId = 1L; Long boardId = 1L; - CreateBoardCommentRequest input = CreateBoardCommentRequest.builder() + CreateCommentRequest input = CreateCommentRequest.builder() .content("게시글 내용") .build(); String body = objectMapper.writeValueAsString(input); - CreateBoardCommentResponse output = CreateBoardCommentResponse.builder() - .boardCommentId(1L) + CreateCommentResponse output = CreateCommentResponse.builder() + .commentId(1L) .build(); given(createBoardCommentUseCase.createBoardComment(any(), any(), any(), any())).willReturn(output); @@ -83,7 +83,7 @@ public void create_board_comment() throws Exception { responseFields( fieldWithPath("isSuccess").description("true"), fieldWithPath("message").description("댓글을 생성했습니다"), - fieldWithPath("data.boardCommentId").description("생성한 boardCommentId") + fieldWithPath("data.commentId").description("생성한 boardCommentId") ) ) ); @@ -135,7 +135,7 @@ public void get_board_comment_all() throws Exception { Long boardId = 1L; CommentBlocks commentBlock = CommentBlocks.builder() - .boardCommentId(1L) + .commentId(1L) .content("댓글 내용") .writerIsLeader(true) .writerNickName("작성자 닉네임") @@ -148,7 +148,7 @@ public void get_board_comment_all() throws Exception { commentBlocks.add(commentBlock); - GetBoardCommentResponse output = new GetBoardCommentResponse(commentBlocks); + GetCommentResponse output = new GetCommentResponse(commentBlocks); given(getBoardCommentUseCase.getBoardCommentAll(any(), any(), any())).willReturn(output); @@ -176,7 +176,7 @@ public void get_board_comment_all() throws Exception { responseFields( fieldWithPath("isSuccess").description("true"), fieldWithPath("message").description("댓글 목록을 모두 조회했습니다."), - fieldWithPath("data.commentBlocks[].boardCommentId").description("댓글 아이디"), + fieldWithPath("data.commentBlocks[].commentId").description("댓글 아이디"), fieldWithPath("data.commentBlocks[].content").description("댓글 내용"), fieldWithPath("data.commentBlocks[].writerIsLeader").description("작성자 소모임장 여부"), fieldWithPath("data.commentBlocks[].writerNickName").description("작성자 닉네임"), diff --git a/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionArchiveControllerTest.java b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionArchiveControllerTest.java index 14a05e86..7ed677de 100644 --- a/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionArchiveControllerTest.java +++ b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionArchiveControllerTest.java @@ -66,6 +66,7 @@ public class MissionArchiveControllerTest extends CommonControllerTest { .heartStatus("[True/False]") .hearts(1L) .contents("contents") + .comments(1L) .build(); given(missionArchiveCreateUseCase.createArchive(any(),any(),any())).willReturn(output); @@ -110,8 +111,10 @@ public class MissionArchiveControllerTest extends CommonControllerTest { fieldWithPath("data.count").description("미션 인증 횟수"), fieldWithPath("data.hearts").description("미션 인증 좋아요 수"), fieldWithPath("data.heartStatus").description("미션 인증 좋아요 상태"), - fieldWithPath("data.contents").description("미션 인증 문구") - ) + fieldWithPath("data.contents").description("미션 인증 문구"), + fieldWithPath("data.comments").description("미션 댓글 개수") + + ) ) ) .andReturn(); @@ -139,6 +142,7 @@ public class MissionArchiveControllerTest extends CommonControllerTest { .heartStatus("[True/False]") .hearts(1L) .contents("contents") + .comments(1L) .build(); given(missionArchiveUpdateUseCase.updateArchive(any(),any(),any())).willReturn(output); @@ -183,9 +187,10 @@ public class MissionArchiveControllerTest extends CommonControllerTest { fieldWithPath("data.count").description("미션 인증 횟수"), fieldWithPath("data.heartStatus").description("미션 인증 좋아요 상태"), fieldWithPath("data.hearts").description("미션 인증 좋아요 수"), - fieldWithPath("data.contents").description("미션 인증 문구") + fieldWithPath("data.contents").description("미션 인증 문구"), + fieldWithPath("data.comments").description("미션 댓글 개수") - ) + ) ) ) .andReturn(); @@ -248,6 +253,7 @@ public class MissionArchiveControllerTest extends CommonControllerTest { .heartStatus("[True/False]") .hearts(1L) .contents("contents") + .comments(1L) .build()); MyMissionArchiveRes output = MyMissionArchiveRes.builder() @@ -291,7 +297,8 @@ public class MissionArchiveControllerTest extends CommonControllerTest { fieldWithPath("data.archives[].count").description("미션 인증 횟수"), fieldWithPath("data.archives[].heartStatus").description("미션 인증 좋아요 상태"), fieldWithPath("data.archives[].hearts").description("미션 인증 좋아요 수"), - fieldWithPath("data.archives[].contents").description("미션 인증 문구") + fieldWithPath("data.archives[].contents").description("미션 인증 문구"), + fieldWithPath("data.archives[].comments").description("미션 댓글 개수") ) diff --git a/src/test/java/com/moing/backend/domain/missionComment/domain/MissionRepositoryTest.java b/src/test/java/com/moing/backend/domain/missionComment/domain/MissionRepositoryTest.java new file mode 100644 index 00000000..ee4c9b6c --- /dev/null +++ b/src/test/java/com/moing/backend/domain/missionComment/domain/MissionRepositoryTest.java @@ -0,0 +1,22 @@ +package com.moing.backend.domain.missionComment.domain; + +import com.moing.backend.domain.missionComment.domain.repository.MissionCommentRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.transaction.annotation.Transactional; + +@SpringBootTest +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) +@ActiveProfiles("dev") +@Transactional +public class MissionRepositoryTest { + + @Autowired + MissionCommentRepository missionCommentRepository; + public void create_Mission_Comment(){ + + } + +} diff --git a/src/test/java/com/moing/backend/domain/missionComment/presentation/MissionCommentControllerTest.java b/src/test/java/com/moing/backend/domain/missionComment/presentation/MissionCommentControllerTest.java new file mode 100644 index 00000000..072bc3eb --- /dev/null +++ b/src/test/java/com/moing/backend/domain/missionComment/presentation/MissionCommentControllerTest.java @@ -0,0 +1,192 @@ +package com.moing.backend.domain.missionComment.presentation; + +import com.moing.backend.config.CommonControllerTest; +import com.moing.backend.domain.comment.application.dto.request.CreateCommentRequest; +import com.moing.backend.domain.comment.application.dto.response.CommentBlocks; +import com.moing.backend.domain.comment.application.dto.response.CreateCommentResponse; +import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse; +import com.moing.backend.domain.missionComment.application.service.CreateMissionCommentUseCase; +import com.moing.backend.domain.missionComment.application.service.DeleteMissionCommentUseCase; +import com.moing.backend.domain.missionComment.application.service.GetMissionCommentUseCase; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; +import org.springframework.test.web.servlet.ResultActions; + +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; +import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; +import static org.springframework.restdocs.payload.PayloadDocumentation.*; +import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; +import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(MissionCommentController.class) +public class MissionCommentControllerTest extends CommonControllerTest { + + @MockBean + private CreateMissionCommentUseCase createMissionCommentUseCase; + @MockBean + private DeleteMissionCommentUseCase deleteMissionCommentUseCase; + @MockBean + private GetMissionCommentUseCase getMissionCommentUseCase; + + @Test + public void create_mission_comment() throws Exception { + + //given + Long teamId = 1L; + Long missionArchiveId = 1L; + CreateCommentRequest input = CreateCommentRequest.builder() + .content("게시글 내용") + .build(); + + String body = objectMapper.writeValueAsString(input); + + CreateCommentResponse output = CreateCommentResponse.builder() + .commentId(1L) + .build(); + + given(createMissionCommentUseCase.createBoardComment(any(), any(), any(), any())).willReturn(output); + + + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + post("/api/{teamId}/{missionArchiveId}/mcomment", teamId, missionArchiveId) + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + .content(body) + ); + + //then + actions + .andExpect(status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + pathParameters( + parameterWithName("teamId").description("팀 아이디"), + parameterWithName("missionArchiveId").description("미션 게시물 아이디") + ), + requestFields( + fieldWithPath("content").description("댓글 내용") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description("댓글을 생성했습니다"), + fieldWithPath("data.commentId").description("생성한 boardCommentId") + ) + ) + ); + } + + @Test + public void delete_mission_comment() throws Exception { + + //given + Long teamId = 1L; + Long boardId = 1L; + Long missionArchiveId = 1L; + + + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + delete("/api/{teamId}/{missionArchiveId}/mcomment/{boardCommentId}", teamId, boardId, missionArchiveId) + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + ); + + //then + actions + .andExpect(status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + pathParameters( + parameterWithName("teamId").description("팀 아이디"), + parameterWithName("missionArchiveId").description("미션 게시글 아이디"), + parameterWithName("boardCommentId").description("댓글 아이디") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description("댓글을 삭제했습니다") + ) + ) + ); + } + + + @Test + public void get_board_comment_all() throws Exception { + //given + List commentBlocks = new ArrayList<>(); + Long teamId = 1L; + Long boardId = 1L; + + CommentBlocks commentBlock = CommentBlocks.builder() + .commentId(1L) + .content("댓글 내용") + .writerIsLeader(true) + .writerNickName("작성자 닉네임") + .writerProfileImage("작성자 프로필 이미지") + .writerIsDeleted(false) + .isWriter(true) + .createdDate("2023/12/05 23:29") + .makerId(1L) + .build(); + + commentBlocks.add(commentBlock); + + GetCommentResponse output = new GetCommentResponse(commentBlocks); + + given(getMissionCommentUseCase.getBoardCommentAll(any(), any(), any())).willReturn(output); + + + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + get("/api/{teamId}/{missionArchiveId}/mcomment", teamId, boardId) + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + ); + + + //then + actions + .andExpect(status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + pathParameters( + parameterWithName("teamId").description("팀 아이디"), + parameterWithName("missionArchiveId").description("게시글 아이디") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description("댓글 목록을 모두 조회했습니다."), + fieldWithPath("data.commentBlocks[].commentId").description("댓글 아이디"), + fieldWithPath("data.commentBlocks[].content").description("댓글 내용"), + fieldWithPath("data.commentBlocks[].writerIsLeader").description("작성자 소모임장 여부"), + fieldWithPath("data.commentBlocks[].writerNickName").description("작성자 닉네임"), + fieldWithPath("data.commentBlocks[].writerProfileImage").description("작성자 프로필 이미지"), + fieldWithPath("data.commentBlocks[].writerIsDeleted").description("작성자 삭제 여부"), + fieldWithPath("data.commentBlocks[].isWriter").description("댓글 작성자 여부"), + fieldWithPath("data.commentBlocks[].createdDate").description("생성 시간"), + fieldWithPath("data.commentBlocks[].makerId").description("작성자 Id") + ) + + ) + ); + } +}