From a953be76d403ba3f54b0559292fc253cf599b8fa Mon Sep 17 00:00:00 2001 From: Minsu Kim <86006389+minsu20@users.noreply.github.com> Date: Mon, 25 Sep 2023 22:36:46 +0900 Subject: [PATCH 01/30] fix: delete data.sql --- .github/workflows/ci-cd.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 3b975a41..76670219 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -46,9 +46,7 @@ jobs: echo "${{env.APPLICATION}}" > ./application.yml touch ./firebase-key.json echo "${{env.GOOGLE_APPLICATION_CREDENTIALS}}" | base64 --decode > ./firebase-key.json - touch ./data.sql - echo "${{env.DATA_SQL}}" | base64 --decode > ./data.sql - + # 설정 파일을 작업공간에 저장 - uses: actions/upload-artifact@v2 with: @@ -60,11 +58,6 @@ jobs: name: firebase-key.json path: ./src/main/resources/firebase-key.json - - uses: actions/upload-artifact@v2 - with: - name: data.sql - path: ./src/main/resources/data.sql - # gradlew 권한 설정 - name: Grant execute permission for gradlew run: chmod +x gradlew From 4bf0729624d8ea8da4dc69b37d6a4c4e3833f1cf Mon Sep 17 00:00:00 2001 From: Minsu Kim Date: Thu, 28 Sep 2023 18:50:41 +0900 Subject: [PATCH 02/30] =?UTF-8?q?feat:=20Board=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20=EC=83=9D=EC=84=B1,=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/Auth-API.adoc | 18 +-- src/docs/asciidoc/Board-API.adoc | 12 ++ src/docs/asciidoc/api.adoc | 4 + .../dto/request/CreateBoardRequest.java | 27 ++++ .../dto/request/UpdateBoardRequest.java | 23 +++ .../application/dto/response/BoardBlocks.java | 23 +++ .../dto/response/CreateBoardResponse.java | 14 ++ .../dto/response/GetAllBoardResponse.java | 20 +++ .../dto/response/UpdateBoardResponse.java | 12 ++ .../board/application/mapper/BoardMapper.java | 29 ++++ .../service/CreateBoardUserCase.java | 46 ++++++ .../application/service/GetBoardUserCase.java | 10 ++ .../service/UpdateBoardUserCase.java | 37 +++++ .../domain/board/domain/entity/Board.java | 86 ++++++++++++ .../repository/BoardCustomRepository.java | 4 + .../BoardCustomerRepositoryImpl.java | 4 + .../domain/repository/BoardRepository.java | 11 ++ .../board/domain/service/BoardGetService.java | 22 +++ .../domain/service/BoardSaveService.java | 20 +++ .../board/exception/BoardException.java | 11 ++ .../exception/NotFoundByBoardIdException.java | 11 ++ .../board/presentation/BoardController.java | 54 ++++++++ .../constant/BoardResponseMessage.java | 13 ++ .../boardComment/domain/BoardComment.java | 33 +++++ .../boardRead/domain/entity/BoardRead.java | 53 +++++++ .../application/mapper/MemberMapper.java | 3 - .../team/application/mapper/TeamMapper.java | 17 +++ .../service/CreateTeamUserCase.java | 4 +- .../domain/team/domain/entity/Team.java | 16 --- .../oauth/CustomUserDetailsService.java | 4 +- .../exception/GlobalExceptionHandler.java | 8 +- .../backend/global/response/ErrorCode.java | 7 +- .../presentation/BoardControllerTest.java | 131 ++++++++++++++++++ 33 files changed, 747 insertions(+), 40 deletions(-) create mode 100644 src/docs/asciidoc/Board-API.adoc create mode 100644 src/main/java/com/moing/backend/domain/board/application/dto/request/CreateBoardRequest.java create mode 100644 src/main/java/com/moing/backend/domain/board/application/dto/request/UpdateBoardRequest.java create mode 100644 src/main/java/com/moing/backend/domain/board/application/dto/response/BoardBlocks.java create mode 100644 src/main/java/com/moing/backend/domain/board/application/dto/response/CreateBoardResponse.java create mode 100644 src/main/java/com/moing/backend/domain/board/application/dto/response/GetAllBoardResponse.java create mode 100644 src/main/java/com/moing/backend/domain/board/application/dto/response/UpdateBoardResponse.java create mode 100644 src/main/java/com/moing/backend/domain/board/application/mapper/BoardMapper.java create mode 100644 src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java create mode 100644 src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java create mode 100644 src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java create mode 100644 src/main/java/com/moing/backend/domain/board/domain/entity/Board.java create mode 100644 src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepository.java create mode 100644 src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomerRepositoryImpl.java create mode 100644 src/main/java/com/moing/backend/domain/board/domain/repository/BoardRepository.java create mode 100644 src/main/java/com/moing/backend/domain/board/domain/service/BoardGetService.java create mode 100644 src/main/java/com/moing/backend/domain/board/domain/service/BoardSaveService.java create mode 100644 src/main/java/com/moing/backend/domain/board/exception/BoardException.java create mode 100644 src/main/java/com/moing/backend/domain/board/exception/NotFoundByBoardIdException.java create mode 100644 src/main/java/com/moing/backend/domain/board/presentation/BoardController.java create mode 100644 src/main/java/com/moing/backend/domain/board/presentation/constant/BoardResponseMessage.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/domain/BoardComment.java create mode 100644 src/main/java/com/moing/backend/domain/boardRead/domain/entity/BoardRead.java create mode 100644 src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java diff --git a/src/docs/asciidoc/Auth-API.adoc b/src/docs/asciidoc/Auth-API.adoc index 45380bc1..900e3d54 100644 --- a/src/docs/asciidoc/Auth-API.adoc +++ b/src/docs/asciidoc/Auth-API.adoc @@ -2,36 +2,24 @@ = Auth API [[Auth-Kako-소셜-로그인]] -=== Auth Kakao 소셜 로그인 요청 +=== Auth Kakao 소셜 로그인 operation::auth-controller-test/kakao_소셜_로그인_회원가입_전[snippets='http-request,request-fields'] - -=== Auth Kakao 소셜 로그인 회원가입 전 응답 operation::auth-controller-test/kakao_소셜_로그인_회원가입_전[snippets='http-response,response-fields'] - -=== Auth Kakao 소셜 로그인 회원가입 후 응답 operation::auth-controller-test/kakao_소셜_로그인_회원가입_후[snippets='http-response,response-fields'] --- [[Auth-Apple-소셜-로그인]] -=== Auth Apple 소셜 로그인 요청 +=== Auth Apple 소셜 로그인 operation::auth-controller-test/apple_소셜_로그인_회원가입_전[snippets='http-request,request-fields'] - -=== Auth Apple 소셜 로그인 회원가입 전 응답 operation::auth-controller-test/apple_소셜_로그인_회원가입_전[snippets='http-response,response-fields'] - -=== Auth Apple 소셜 로그인 회원가입 후 응답 operation::auth-controller-test/apple_소셜_로그인_회원가입_후[snippets='http-response,response-fields'] [[Auth-Google-소셜-로그인]] -=== Auth Google 소셜 로그인 요청 +=== Auth Google 소셜 로그인 operation::auth-controller-test/google_소셜_로그인_회원가입_전[snippets='http-request,request-fields'] - -=== Auth Google 소셜 로그인 회원가입 전 응답 operation::auth-controller-test/google_소셜_로그인_회원가입_전[snippets='http-response,response-fields'] - -=== Auth Google 소셜 로그인 회원가입 후 응답 operation::auth-controller-test/google_소셜_로그인_회원가입_후[snippets='http-response,response-fields'] diff --git a/src/docs/asciidoc/Board-API.adoc b/src/docs/asciidoc/Board-API.adoc new file mode 100644 index 00000000..451cd602 --- /dev/null +++ b/src/docs/asciidoc/Board-API.adoc @@ -0,0 +1,12 @@ +[[Board-API]] += Board API + +[[Board-게시글-생성]] +=== Board 게시글 생성 +operation::board-controller-test/create_board[snippets='http-request,request-fields,http-response,response-fields'] +--- + +[[Board-게시글-수정]] +=== Board 게시글 수정 +operation::board-controller-test/update_board[snippets='http-request,request-fields,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 2e4a5a6c..26bed444 100644 --- a/src/docs/asciidoc/api.adoc +++ b/src/docs/asciidoc/api.adoc @@ -20,4 +20,8 @@ include::Mission-API.adoc[] include::MissionArchive-API.adoc[] +include::Mission-API.adoc[] + +include::Board-API.adoc[] + diff --git a/src/main/java/com/moing/backend/domain/board/application/dto/request/CreateBoardRequest.java b/src/main/java/com/moing/backend/domain/board/application/dto/request/CreateBoardRequest.java new file mode 100644 index 00000000..b1d6209b --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/application/dto/request/CreateBoardRequest.java @@ -0,0 +1,27 @@ +package com.moing.backend.domain.board.application.dto.request; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +@AllArgsConstructor +@Builder +@NoArgsConstructor +@Getter +public class CreateBoardRequest { + @NotBlank(message = "title 을 입력해 주세요.") + @Size(min = 1, max = 15, message = "title 은 최소 1개, 최대 15개의 문자만 입력 가능합니다.") + private String title; + + @NotBlank(message = "content 을 입력해 주세요.") + @Size(min = 1, max = 300, message = "content 은 최소 1개, 최대 10개의 문자만 입력 가능합니다.") + private String content; + + @NotNull(message = "notice 사용 여부(isNotice) 를 입력해 주세요.") + private Boolean isNotice; +} diff --git a/src/main/java/com/moing/backend/domain/board/application/dto/request/UpdateBoardRequest.java b/src/main/java/com/moing/backend/domain/board/application/dto/request/UpdateBoardRequest.java new file mode 100644 index 00000000..685ee2ba --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/application/dto/request/UpdateBoardRequest.java @@ -0,0 +1,23 @@ +package com.moing.backend.domain.board.application.dto.request; + +import lombok.Builder; +import lombok.Getter; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +@Getter +@Builder +public class UpdateBoardRequest { + @NotBlank(message = "title 을 입력해 주세요.") + @Size(min = 1, max = 15, message = "title 은 최소 1개, 최대 15개의 문자만 입력 가능합니다.") + private String title; + + @NotBlank(message = "content 을 입력해 주세요.") + @Size(min = 1, max = 300, message = "content 은 최소 1개, 최대 10개의 문자만 입력 가능합니다.") + private String content; + + @NotNull(message = "notice 사용 여부(isNotice) 를 입력해 주세요.") + private Boolean isNotice; +} diff --git a/src/main/java/com/moing/backend/domain/board/application/dto/response/BoardBlocks.java b/src/main/java/com/moing/backend/domain/board/application/dto/response/BoardBlocks.java new file mode 100644 index 00000000..08d453bd --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/application/dto/response/BoardBlocks.java @@ -0,0 +1,23 @@ +package com.moing.backend.domain.board.application.dto.response; + +import lombok.Getter; + +@Getter +public class BoardBlocks { + + private Long boardId; + + private String writerNickName; + + private Boolean isLeader; + + private String writerProfileImage; + + private String title; + + private String content; + + private Integer commentNum; + + private Boolean isRead; +} diff --git a/src/main/java/com/moing/backend/domain/board/application/dto/response/CreateBoardResponse.java b/src/main/java/com/moing/backend/domain/board/application/dto/response/CreateBoardResponse.java new file mode 100644 index 00000000..75662b71 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/application/dto/response/CreateBoardResponse.java @@ -0,0 +1,14 @@ +package com.moing.backend.domain.board.application.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@Builder +@NoArgsConstructor +@Getter +public class CreateBoardResponse { + private Long boardId; +} diff --git a/src/main/java/com/moing/backend/domain/board/application/dto/response/GetAllBoardResponse.java b/src/main/java/com/moing/backend/domain/board/application/dto/response/GetAllBoardResponse.java new file mode 100644 index 00000000..b2d200ab --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/application/dto/response/GetAllBoardResponse.java @@ -0,0 +1,20 @@ +package com.moing.backend.domain.board.application.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@AllArgsConstructor +@Builder +@NoArgsConstructor +@Getter +public class GetAllBoardResponse { + private Long noticeNum; + private List notices=new ArrayList<>(); + private Long notNoticeNum; + private List notNotices=new ArrayList<>(); +} diff --git a/src/main/java/com/moing/backend/domain/board/application/dto/response/UpdateBoardResponse.java b/src/main/java/com/moing/backend/domain/board/application/dto/response/UpdateBoardResponse.java new file mode 100644 index 00000000..48b4b114 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/application/dto/response/UpdateBoardResponse.java @@ -0,0 +1,12 @@ +package com.moing.backend.domain.board.application.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@AllArgsConstructor +@Builder +public class UpdateBoardResponse { + private Long boardId; +} diff --git a/src/main/java/com/moing/backend/domain/board/application/mapper/BoardMapper.java b/src/main/java/com/moing/backend/domain/board/application/mapper/BoardMapper.java new file mode 100644 index 00000000..c10a0659 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/application/mapper/BoardMapper.java @@ -0,0 +1,29 @@ +package com.moing.backend.domain.board.application.mapper; + +import com.moing.backend.domain.board.application.dto.request.CreateBoardRequest; +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.entity.TeamMember; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class BoardMapper { + + public Board toBoard(Member member, TeamMember teamMember, Team team, CreateBoardRequest createBoardRequest, boolean isLeader) { + Board board = Board.builder() + .writerNickName(member.getNickName()) + .writerProfileImage(member.getProfileImage()) + .title(createBoardRequest.getTitle()) + .content(createBoardRequest.getContent()) + .isNotice(createBoardRequest.getIsNotice()) + .commentNum(0) + .isLeader(isLeader) + .build(); + board.updateTeamMember(teamMember); + board.updateTeam(team); + return board; + } +} diff --git a/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java new file mode 100644 index 00000000..9c2c615f --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java @@ -0,0 +1,46 @@ +package com.moing.backend.domain.board.application.service; + +import com.moing.backend.domain.board.application.dto.request.CreateBoardRequest; +import com.moing.backend.domain.board.application.dto.response.CreateBoardResponse; +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.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 lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class CreateBoardUserCase { + + private final MemberGetService memberGetService; + private final BoardSaveService boardSaveService; + private final CheckLeaderUserCase checkLeaderUserCase; + private final TeamGetService teamGetService; + private final BoardMapper boardMapper; + private final TeamMemberGetService teamMemberGetService; + + /** + * 게시글 생성 + * @param user + * @param teamId + * @param createBoardRequest + * @return CreateBoardResponse + */ + public CreateBoardResponse createBoard(User user, Long teamId, CreateBoardRequest createBoardRequest) { + Member member = memberGetService.getMemberBySocialId(user.getSocialId()); + Team team = teamGetService.getTeamByTeamId(teamId); + TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); + boolean isLeader = checkLeaderUserCase.isTeamLeader(member, team); + Board board = boardMapper.toBoard(member, teamMember, team, createBoardRequest, isLeader); + boardSaveService.saveBoard(board); + return new CreateBoardResponse(board.getBoardId()); + } +} diff --git a/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java new file mode 100644 index 00000000..20cf5fba --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java @@ -0,0 +1,10 @@ +package com.moing.backend.domain.board.application.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class GetBoardUserCase { + +} diff --git a/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java new file mode 100644 index 00000000..71a8574b --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java @@ -0,0 +1,37 @@ +package com.moing.backend.domain.board.application.service; + +import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; +import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse; +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.BoardGetService; +import com.moing.backend.domain.board.domain.service.BoardSaveService; +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.service.TeamMemberGetService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; + +@Service +@RequiredArgsConstructor +public class UpdateBoardUserCase { + private final MemberGetService memberGetService; + private final BoardSaveService boardSaveService; + private final CheckLeaderUserCase checkLeaderUserCase; + private final TeamGetService teamGetService; + private final BoardMapper boardMapper; + private final BoardGetService boardGetService; + + @Transactional + public UpdateBoardResponse updateBoard(String socialId, Long teamId, Long boardId, UpdateBoardRequest updateBoardRequest){ + Member member=memberGetService.getMemberBySocialId(socialId); + Board board=boardGetService.getBoard(boardId); + board.updateBoard(updateBoardRequest); + return new UpdateBoardResponse(board.getBoardId()); + } +} diff --git a/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java b/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java new file mode 100644 index 00000000..d6034391 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java @@ -0,0 +1,86 @@ +package com.moing.backend.domain.board.domain.entity; + +import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; +import com.moing.backend.domain.boardRead.domain.entity.BoardRead; +import com.moing.backend.domain.team.domain.entity.Team; +import com.moing.backend.domain.teamMember.domain.entity.TeamMember; +import com.moing.backend.global.entity.BaseTimeEntity; +import com.moing.backend.global.util.AesConverter; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class Board extends BaseTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "board_id") + private Long boardId; + + //반정규화 -> 작성자에 대한 정보 + @Convert(converter = AesConverter.class) + @Column(nullable = false) + private String writerNickName; + + private boolean isLeader; + + private String writerProfileImage; + + @Column(nullable = false, length = 15) + private String title; + + @Column(nullable = false, length = 300) + private String content; + + private boolean isNotice; + + //반정규화 -> 댓글 개수 + private Integer commentNum; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "team_member_id") + private TeamMember teamMember; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "team_id") + private Team team; + + @OneToMany(mappedBy = "board", cascade = CascadeType.ALL) + private List boardReads = new ArrayList<>(); + + + public void incrComNum() { + this.commentNum++; + } + + public void decrComNum() { + this.commentNum--; + } + + public void updateBoard(UpdateBoardRequest updateBoardRequest){ + this.title= updateBoardRequest.getTitle(); + this.content= updateBoardRequest.getContent(); + this.isNotice= updateBoardRequest.getIsNotice(); + } + + //==연관관계 메서드 ==// + public void updateTeamMember(TeamMember teamMember) { + this.teamMember = teamMember; + } + + public void updateTeam(Team team) { + this.team = team; + } +} diff --git a/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepository.java b/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepository.java new file mode 100644 index 00000000..ef5053e3 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepository.java @@ -0,0 +1,4 @@ +package com.moing.backend.domain.board.domain.repository; + +public interface BoardCustomRepository { +} diff --git a/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomerRepositoryImpl.java b/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomerRepositoryImpl.java new file mode 100644 index 00000000..668825cf --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomerRepositoryImpl.java @@ -0,0 +1,4 @@ +package com.moing.backend.domain.board.domain.repository; + +public class BoardCustomerRepositoryImpl implements BoardCustomRepository{ +} diff --git a/src/main/java/com/moing/backend/domain/board/domain/repository/BoardRepository.java b/src/main/java/com/moing/backend/domain/board/domain/repository/BoardRepository.java new file mode 100644 index 00000000..4059cec3 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/domain/repository/BoardRepository.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.board.domain.repository; + +import com.moing.backend.domain.board.domain.entity.Board; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface BoardRepository extends JpaRepository, BoardCustomRepository { + + Optional findBoardByBoardId(Long boardId); +} diff --git a/src/main/java/com/moing/backend/domain/board/domain/service/BoardGetService.java b/src/main/java/com/moing/backend/domain/board/domain/service/BoardGetService.java new file mode 100644 index 00000000..88cc75e0 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/domain/service/BoardGetService.java @@ -0,0 +1,22 @@ +package com.moing.backend.domain.board.domain.service; + +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.board.domain.repository.BoardRepository; +import com.moing.backend.domain.board.exception.NotFoundByBoardIdException; +import com.moing.backend.global.annotation.DomainService; +import lombok.RequiredArgsConstructor; + +import javax.transaction.Transactional; +import java.util.Optional; + +@DomainService +@Transactional +@RequiredArgsConstructor +public class BoardGetService { + + private final BoardRepository boardRepository; + + public Board getBoard(Long boardId){ + return boardRepository.findBoardByBoardId(boardId).orElseThrow(()->new NotFoundByBoardIdException()); + } +} diff --git a/src/main/java/com/moing/backend/domain/board/domain/service/BoardSaveService.java b/src/main/java/com/moing/backend/domain/board/domain/service/BoardSaveService.java new file mode 100644 index 00000000..33c8a180 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/domain/service/BoardSaveService.java @@ -0,0 +1,20 @@ +package com.moing.backend.domain.board.domain.service; + +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.board.domain.repository.BoardRepository; +import com.moing.backend.global.annotation.DomainService; +import lombok.RequiredArgsConstructor; + +import javax.transaction.Transactional; + +@DomainService +@Transactional +@RequiredArgsConstructor +public class BoardSaveService { + + private final BoardRepository boardRepository; + + public void saveBoard(Board board) { + this.boardRepository.save(board); + } +} diff --git a/src/main/java/com/moing/backend/domain/board/exception/BoardException.java b/src/main/java/com/moing/backend/domain/board/exception/BoardException.java new file mode 100644 index 00000000..d0502d4e --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/exception/BoardException.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.board.exception; + +import com.moing.backend.global.exception.ApplicationException; +import com.moing.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public abstract class BoardException extends ApplicationException { + protected BoardException(ErrorCode errorCode, HttpStatus httpStatus) { + super(errorCode, httpStatus); + } +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/board/exception/NotFoundByBoardIdException.java b/src/main/java/com/moing/backend/domain/board/exception/NotFoundByBoardIdException.java new file mode 100644 index 00000000..e9fbb6c7 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/exception/NotFoundByBoardIdException.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.board.exception; + +import com.moing.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public class NotFoundByBoardIdException extends BoardException { + public NotFoundByBoardIdException() { + super(ErrorCode.NOT_FOUND_BY_BOARD_ID_ERROR, + HttpStatus.NOT_FOUND); + } +} 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 new file mode 100644 index 00000000..a3b86e9c --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/presentation/BoardController.java @@ -0,0 +1,54 @@ +package com.moing.backend.domain.board.presentation; + +import com.moing.backend.domain.board.application.dto.request.CreateBoardRequest; +import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; +import com.moing.backend.domain.board.application.dto.response.CreateBoardResponse; +import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse; +import com.moing.backend.domain.board.application.service.CreateBoardUserCase; +import com.moing.backend.domain.board.application.service.UpdateBoardUserCase; +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.board.presentation.constant.BoardResponseMessage.CREATE_BOARD_SUCCESS; +import static com.moing.backend.domain.board.presentation.constant.BoardResponseMessage.UPDATE_BOARD_SUCCESS; + +@RestController +@AllArgsConstructor +@RequestMapping("/api/{teamId}/board") +public class BoardController { + + private final CreateBoardUserCase createBoardUserCase; + private final UpdateBoardUserCase updateBoardUserCase; + + /** + * 게시글 생성 + * [POST] api/{teamId}/board + * 작성자 : 김민수 + */ + @PostMapping + public ResponseEntity> createBoard(@AuthenticationPrincipal User user, + @PathVariable Long teamId, + @Valid @RequestBody CreateBoardRequest createBoardRequest) { + return ResponseEntity.ok(SuccessResponse.create(CREATE_BOARD_SUCCESS.getMessage(), this.createBoardUserCase.createBoard(user, teamId, createBoardRequest))); + } + + /** + * 게시글 수정 + * [PUT] api/{teamId}/board/{boardId} + * 작성자 : 김민수 + */ + + @PutMapping("/{boardId}") + public ResponseEntity> updateBoard(@AuthenticationPrincipal User user, + @PathVariable Long teamId, + @PathVariable Long boardId, + @Valid @RequestBody UpdateBoardRequest updateBoardRequest) { + return ResponseEntity.ok(SuccessResponse.create(UPDATE_BOARD_SUCCESS.getMessage(), this.updateBoardUserCase.updateBoard(user.getSocialId(), teamId, boardId, updateBoardRequest))); + } +} diff --git a/src/main/java/com/moing/backend/domain/board/presentation/constant/BoardResponseMessage.java b/src/main/java/com/moing/backend/domain/board/presentation/constant/BoardResponseMessage.java new file mode 100644 index 00000000..65a9fbcd --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/presentation/constant/BoardResponseMessage.java @@ -0,0 +1,13 @@ +package com.moing.backend.domain.board.presentation.constant; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum BoardResponseMessage { + CREATE_BOARD_SUCCESS("게시글을 생성했습니다."), + GET_BOARD_ALL_SUCCESS("게시글 목록을 모두 조회했습니다."), + UPDATE_BOARD_SUCCESS("게시글을 수정했습니다."); + private final String message; +} diff --git a/src/main/java/com/moing/backend/domain/boardComment/domain/BoardComment.java b/src/main/java/com/moing/backend/domain/boardComment/domain/BoardComment.java new file mode 100644 index 00000000..e3b39428 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/BoardComment.java @@ -0,0 +1,33 @@ +package com.moing.backend.domain.boardComment.domain; + +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.teamMember.domain.entity.TeamMember; +import com.moing.backend.global.entity.BaseTimeEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Entity +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class BoardComment extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "board_comment_id") + private Long boardCommentId; + private String content; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "team_member_id") + private TeamMember teamMember; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "board_id") + private Board board; +} diff --git a/src/main/java/com/moing/backend/domain/boardRead/domain/entity/BoardRead.java b/src/main/java/com/moing/backend/domain/boardRead/domain/entity/BoardRead.java new file mode 100644 index 00000000..4c5d6334 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardRead/domain/entity/BoardRead.java @@ -0,0 +1,53 @@ +package com.moing.backend.domain.boardRead.domain.entity; + +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 lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Entity +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class BoardRead { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "board_read_id") + private Long boardReadId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "board_id") + private Board board; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "team__id") + private Team team; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "Member_id") + private Member member; + + + /** + * 연관관계 매핑 + */ + public void updateBoard(Board board) { + this.board = board; + board.getBoardReads().add(this); + } + + public void updateTeam(Team team) { + this.team = team; + } + + public void updateMember(Member member) { + this.member = member; + } +} diff --git a/src/main/java/com/moing/backend/domain/member/application/mapper/MemberMapper.java b/src/main/java/com/moing/backend/domain/member/application/mapper/MemberMapper.java index df55b8a7..e31a33e0 100644 --- a/src/main/java/com/moing/backend/domain/member/application/mapper/MemberMapper.java +++ b/src/main/java/com/moing/backend/domain/member/application/mapper/MemberMapper.java @@ -7,9 +7,6 @@ import com.moing.backend.domain.member.domain.entity.Member; import org.springframework.stereotype.Component; -import java.time.LocalDate; -import java.time.LocalDateTime; - @Component public class MemberMapper { diff --git a/src/main/java/com/moing/backend/domain/team/application/mapper/TeamMapper.java b/src/main/java/com/moing/backend/domain/team/application/mapper/TeamMapper.java index 2118d7f0..327adba1 100644 --- a/src/main/java/com/moing/backend/domain/team/application/mapper/TeamMapper.java +++ b/src/main/java/com/moing/backend/domain/team/application/mapper/TeamMapper.java @@ -1,9 +1,26 @@ package com.moing.backend.domain.team.application.mapper; +import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.team.application.dto.request.CreateTeamRequest; +import com.moing.backend.domain.team.domain.constant.ApprovalStatus; +import com.moing.backend.domain.team.domain.constant.Category; import com.moing.backend.domain.team.domain.entity.Team; import org.springframework.stereotype.Component; @Component public class TeamMapper { + + public Team createTeam(CreateTeamRequest createTeamRequest, Member member) { + return Team.builder() + .category(Enum.valueOf(Category.class, createTeamRequest.getCategory())) + .name(createTeamRequest.getName()) + .introduction(createTeamRequest.getIntroduction()) + .promise(createTeamRequest.getPromise()) + .profileImgUrl(createTeamRequest.getProfileImgUrl()) + .approvalStatus(ApprovalStatus.NO_CONFIRMATION) + .leaderId(member.getMemberId()) + .numOfMember(0) + .levelOfFire(1) + .build(); + } } diff --git a/src/main/java/com/moing/backend/domain/team/application/service/CreateTeamUserCase.java b/src/main/java/com/moing/backend/domain/team/application/service/CreateTeamUserCase.java index b5b3f423..6513c478 100644 --- a/src/main/java/com/moing/backend/domain/team/application/service/CreateTeamUserCase.java +++ b/src/main/java/com/moing/backend/domain/team/application/service/CreateTeamUserCase.java @@ -4,6 +4,7 @@ import com.moing.backend.domain.member.domain.service.MemberGetService; import com.moing.backend.domain.team.application.dto.request.CreateTeamRequest; import com.moing.backend.domain.team.application.dto.response.CreateTeamResponse; +import com.moing.backend.domain.team.application.mapper.TeamMapper; import com.moing.backend.domain.team.domain.entity.Team; import com.moing.backend.domain.team.domain.service.TeamSaveService; import com.moing.backend.domain.teamMember.domain.service.TeamMemberSaveService; @@ -20,10 +21,11 @@ public class CreateTeamUserCase { private final MemberGetService memberGetService; private final TeamSaveService teamSaveService; private final TeamMemberSaveService teamMemberSaveService; + private final TeamMapper teamMapper; public CreateTeamResponse createTeam(CreateTeamRequest createTeamRequest, String socialId){ Member member = memberGetService.getMemberBySocialId(socialId); - Team team=Team.createTeam(createTeamRequest, member); + Team team=teamMapper.createTeam(createTeamRequest, member); teamSaveService.saveTeam(team); teamMemberSaveService.addTeamMember(team, member); //====지워야 함 (테스트 용)===== diff --git a/src/main/java/com/moing/backend/domain/team/domain/entity/Team.java b/src/main/java/com/moing/backend/domain/team/domain/entity/Team.java index a7fef763..1b4f531e 100644 --- a/src/main/java/com/moing/backend/domain/team/domain/entity/Team.java +++ b/src/main/java/com/moing/backend/domain/team/domain/entity/Team.java @@ -1,8 +1,6 @@ package com.moing.backend.domain.team.domain.entity; -import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.mission.domain.entity.Mission; -import com.moing.backend.domain.team.application.dto.request.CreateTeamRequest; import com.moing.backend.domain.team.domain.constant.ApprovalStatus; import com.moing.backend.domain.team.domain.constant.Category; import com.moing.backend.global.entity.BaseTimeEntity; @@ -66,20 +64,6 @@ public class Team extends BaseTimeEntity { @OneToMany(mappedBy = "team") List missions = new ArrayList<>(); - public static Team createTeam(CreateTeamRequest createTeamRequest, Member member) { - return Team.builder() - .category(Enum.valueOf(Category.class, createTeamRequest.getCategory())) - .name(createTeamRequest.getName()) - .introduction(createTeamRequest.getIntroduction()) - .promise(createTeamRequest.getPromise()) - .profileImgUrl(createTeamRequest.getProfileImgUrl()) - .approvalStatus(ApprovalStatus.NO_CONFIRMATION) - .leaderId(member.getMemberId()) - .numOfMember(0) - .levelOfFire(1) - .build(); - } - public void approveTeam() { this.approvalStatus = ApprovalStatus.APPROVAL; this.approvalTime = LocalDateTime.now(ZoneId.of("Asia/Seoul")).withNano(0); diff --git a/src/main/java/com/moing/backend/global/config/security/oauth/CustomUserDetailsService.java b/src/main/java/com/moing/backend/global/config/security/oauth/CustomUserDetailsService.java index 07a328ad..c48027a9 100644 --- a/src/main/java/com/moing/backend/global/config/security/oauth/CustomUserDetailsService.java +++ b/src/main/java/com/moing/backend/global/config/security/oauth/CustomUserDetailsService.java @@ -12,12 +12,12 @@ @Service @RequiredArgsConstructor public class CustomUserDetailsService implements UserDetailsService { - private final MemberGetService memberQueryService; + private final MemberGetService memberGetService; @Override @Transactional(readOnly = true) public UserDetails loadUserByUsername(String socialId) throws UsernameNotFoundException { - Member member = this.memberQueryService.getMemberBySocialId(socialId); + Member member = this.memberGetService.getMemberBySocialId(socialId); if (member == null) { throw new UsernameNotFoundException("User not found with socialId: " + socialId); diff --git a/src/main/java/com/moing/backend/global/exception/GlobalExceptionHandler.java b/src/main/java/com/moing/backend/global/exception/GlobalExceptionHandler.java index 492e6528..7a5b3529 100644 --- a/src/main/java/com/moing/backend/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/moing/backend/global/exception/GlobalExceptionHandler.java @@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -39,6 +40,11 @@ public ResponseEntity inputPatternSyntaxExceptionHandler(PatternS return handleException(ex, ErrorCode.BAD_REQUEST, ErrorCode.BAD_REQUEST.getMessage(), HttpStatus.BAD_REQUEST, log::warn); } + @ExceptionHandler(HttpMessageNotReadableException.class) + public ResponseEntity jsonParseExceptionHandler(HttpMessageNotReadableException ex) { + return handleException(ex, ErrorCode.BAD_REQUEST, ErrorCode.BAD_REQUEST.getMessage(), HttpStatus.BAD_REQUEST, log::warn); + } + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) public ResponseEntity httpRequestNotSupportedExceptionHandler(HttpRequestMethodNotSupportedException ex) { return handleException(ex, ErrorCode.METHOD_NOT_ALLOWED, ErrorCode.METHOD_NOT_ALLOWED.getMessage(), HttpStatus.METHOD_NOT_ALLOWED, log::warn); @@ -50,7 +56,7 @@ public ResponseEntity internalServerErrorHandler(Exception ex) { } private ResponseEntity handleException(Exception ex, ErrorCode errorCode, String message, HttpStatus httpStatus, Consumer logger) { - logger.accept(String.format(LOG_FORMAT, ex.getClass().getSimpleName(), errorCode.getErrorCode(), ex.getMessage())); + log.error(LOG_FORMAT, ex.getClass().getSimpleName(), errorCode.getErrorCode(), ex.getMessage()); ErrorResponse errorResponse = new ErrorResponse(errorCode, message); return ResponseEntity.status(httpStatus.value()).body(errorResponse); } 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 6574d86f..dda3ec42 100644 --- a/src/main/java/com/moing/backend/global/response/ErrorCode.java +++ b/src/main/java/com/moing/backend/global/response/ErrorCode.java @@ -8,7 +8,7 @@ @AllArgsConstructor public enum ErrorCode { - BAD_REQUEST("400", "올바른 패턴을 입력하세요."), + BAD_REQUEST("400", "입력값이 유효하지 않습니다."), METHOD_NOT_ALLOWED("405", "클라이언트가 사용한 HTTP 메서드가 리소스에서 허용되지 않습니다."), INTERNAL_SERVER_ERROR("500", "서버에서 요청을 처리하는 동안 오류가 발생했습니다."), NOT_FOUND_REFRESH_TOKEN_ERROR( "J0008", "유효하지 않는 RefreshToken 입니다."), @@ -30,7 +30,10 @@ public enum ErrorCode { //팀 관련 에러 코드 NOT_FOUND_BY_TEAM_ID_ERROR("T0001", "해당 teamId인 팀이 존재하지 않습니다."), - NOT_AUTH_BY_TEAM_ERROR("T0002","권한이 없습니다."); + NOT_AUTH_BY_TEAM_ERROR("T0002","권한이 없습니다."), + + //게시글 관련 에러 코드 + NOT_FOUND_BY_BOARD_ID_ERROR("B0001","해당 boardId인 팀이 존재하지 않습니다."); private String errorCode; private String message; diff --git a/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java b/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java new file mode 100644 index 00000000..bb368b7a --- /dev/null +++ b/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java @@ -0,0 +1,131 @@ +package com.moing.backend.domain.board.presentation; + +import com.moing.backend.config.CommonControllerTest; +import com.moing.backend.domain.board.application.dto.request.CreateBoardRequest; +import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; +import com.moing.backend.domain.board.application.dto.response.CreateBoardResponse; +import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse; +import com.moing.backend.domain.board.application.service.CreateBoardUserCase; +import com.moing.backend.domain.board.application.service.UpdateBoardUserCase; +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 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.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(BoardController.class) +public class BoardControllerTest extends CommonControllerTest { + @MockBean + private CreateBoardUserCase createBoardUserCase; + @MockBean + private UpdateBoardUserCase updateBoardUserCase; + + @Test + public void create_board() throws Exception { + + //given + Long teamId = 1L; + CreateBoardRequest input = CreateBoardRequest.builder() + .title("게시글 제목") + .content("게시글 내용") + .isNotice(false) + .build(); + + String body = objectMapper.writeValueAsString(input); + + CreateBoardResponse output = CreateBoardResponse.builder() + .boardId(1L) + .build(); + + given(createBoardUserCase.createBoard(any(), any(), any())).willReturn(output); + + + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + post("/api/{teamId}/board", teamId) + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + .content(body) + ); + + //then + actions + .andExpect(status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + requestFields( + fieldWithPath("title").description("게시글 제목"), + fieldWithPath("content").description("게시글 내용"), + fieldWithPath("isNotice").description("공지 여부") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description("게시글을 생성했습니다"), + fieldWithPath("data.boardId").description("생성한 boardId") + ) + ) + ); + } + + @Test + public void update_board() throws Exception { + + //given + Long teamId = 1L; + Long boardId = 1L; + UpdateBoardRequest input = UpdateBoardRequest.builder() + .title("게시글 제목") + .content("게시글 내용") + .isNotice(false) + .build(); + + String body = objectMapper.writeValueAsString(input); + + UpdateBoardResponse output = UpdateBoardResponse.builder() + .boardId(1L) + .build(); + + given(updateBoardUserCase.updateBoard(any(), any(), any(), any())).willReturn(output); + + + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + put("/api/{teamId}/board/{boardId}", teamId, boardId) + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + .content(body) + ); + + //then + actions + .andExpect(status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + requestFields( + fieldWithPath("title").description("게시글 제목"), + fieldWithPath("content").description("게시글 내용"), + fieldWithPath("isNotice").description("공지 여부") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description("게시글을 수정했습니다"), + fieldWithPath("data.boardId").description("수정한 boardId") + ) + ) + ); + } +} From ecaf7d0326c53db23296c677347caa5d8fc34111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Sat, 30 Sep 2023 03:17:51 +0900 Subject: [PATCH 03/30] =?UTF-8?q?feat=20:=20@/@=EB=AA=85=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=EC=84=B1=EA=B3=B5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/res/MissionArchiveStatusRes.java | 11 +++++++++++ .../service/SingleMissionArchiveReadUseCase.java | 14 ++++++++++++++ .../constant/MissionArchiveResponseMessage.java | 3 ++- .../repository/MissionArchiveCustomRepository.java | 3 +++ .../MissionArchiveCustomRepositoryImpl.java | 13 +++++++++++++ .../domain/service/MissionArchiveQueryService.java | 4 ++++ .../presentation/MissionArchiveController.java | 11 +++++++++++ 7 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/MissionArchiveStatusRes.java diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/MissionArchiveStatusRes.java b/src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/MissionArchiveStatusRes.java new file mode 100644 index 00000000..67216a52 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/MissionArchiveStatusRes.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.missionArchive.application.dto.res; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class MissionArchiveStatusRes { + private String total; + private String done; +} diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/SingleMissionArchiveReadUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/SingleMissionArchiveReadUseCase.java index 1959984e..87204ea6 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/SingleMissionArchiveReadUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/SingleMissionArchiveReadUseCase.java @@ -5,11 +5,13 @@ import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.mission.domain.service.MissionQueryService; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; +import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveStatusRes; import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchive; import com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper; 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.repository.TeamRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -28,6 +30,7 @@ public class SingleMissionArchiveReadUseCase { private final MemberGetService memberGetService; private final MissionQueryService missionQueryService; private final MissionArchiveQueryService missionArchiveQueryService; + private final TeamRepository teamRepository; // 미션 인증 조회 @@ -51,5 +54,16 @@ public List getPersonalArchive(String userSocialId,Long mission // return personalArchives; } + public MissionArchiveStatusRes getMissionDoneStatus(Long missionId) { + Mission mission = missionQueryService.findMissionById(missionId); + Team team = mission.getTeam(); + + return MissionArchiveStatusRes.builder() + .total(team.getNumOfMember().toString()) + .done(missionArchiveQueryService.findDoneArchives(missionId).toString()) + .build(); + + } + } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/constant/MissionArchiveResponseMessage.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/constant/MissionArchiveResponseMessage.java index 39750179..5cda14a5 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/constant/MissionArchiveResponseMessage.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/constant/MissionArchiveResponseMessage.java @@ -11,7 +11,8 @@ public enum MissionArchiveResponseMessage { READ_MY_ARCHIVE_SUCCESS("나의 미션 인증 현황 조회를 완료 했습니다."), READ_TEAM_ARCHIVE_SUCCESS("팀원 미션 인증 현황 조회를 완료 했습니다."), HEART_UPDATE_SUCCESS("미션 인증 좋아요를 성공적으로 눌렀습니다."), - ACTIVE_SINGLE_MISSION_SUCCESS("진행 중인 한번 인증 미션 조회를 완료하였습니다."), + MISSION_ARCHIVE_PEOPLE_STATUS_SUCCESS("미션 인증 성공한 인원 상태 조회를 완료 했습니다."), + ACTIVE_SINGLE_MISSION_SUCCESS("진행 중인 한번 인증 미션 조회를 완료 했습니다."), FINISH_ALL_MISSION_SUCCESS("종료된 미션 조회를 완료하였습니다."); private final String message; diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java index ee7ca799..19273667 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java @@ -14,5 +14,8 @@ public interface MissionArchiveCustomRepository { Optional> findAllMissionArchivesByMemberId(Long memberId, Long teamId, MissionStatus missionStatus); + Optional findDonePeopleByMissionId(Long missionId); + + } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java index a8fba537..1c4bff6e 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java @@ -92,5 +92,18 @@ public Optional> findAllMissionArchivesByMemberId(Long memb ); } + @Override + public Optional findDonePeopleByMissionId(Long missionId) { + return Optional.ofNullable(queryFactory + .select(missionArchive.count()) + .from(missionArchive) + .where( + missionArchive.mission.id.eq(missionId) + ) + .fetchFirst() + + ); + } + } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java index 77891d9b..9b3c968c 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java @@ -87,6 +87,10 @@ public List findMyAllMissionArchives(Long memberId, Long teamId, return missionArchiveRepository.findAllMissionArchivesByMemberId(memberId, teamId, missionStatus).orElseThrow(NotFoundMissionArchiveException::new); } + public Long findDoneArchives(Long missionId) { + return missionArchiveRepository.findDonePeopleByMissionId(missionId).orElseThrow(NotFoundMissionArchiveException::new); + } + diff --git a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java index d89372cb..6ced5bf5 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java @@ -4,6 +4,7 @@ import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveHeartReq; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveHeartRes; +import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveStatusRes; import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchive; import com.moing.backend.domain.missionArchive.application.service.MissionArchiveCreateUseCase; import com.moing.backend.domain.missionArchive.application.service.MissionArchiveHeartUseCase; @@ -84,6 +85,16 @@ public ResponseEntity>> getOtherPeopleArch return ResponseEntity.ok(SuccessResponse.create(READ_TEAM_ARCHIVE_SUCCESS.getMessage(), this.singleMissionArchiveReadUseCase.getPersonalArchive(user.getSocialId(),missionId))); } + + + @GetMapping("/status") + public ResponseEntity> getMissionDoneStatus(@AuthenticationPrincipal User user, + @PathVariable("teamId") Long teamId, + @PathVariable("missionId") Long missionId) { + return ResponseEntity.ok(SuccessResponse.create(MISSION_ARCHIVE_PEOPLE_STATUS_SUCCESS.getMessage(), this.singleMissionArchiveReadUseCase.getMissionDoneStatus(missionId))); + } + + @PostMapping("/hearts") public ResponseEntity> pushHeart(@AuthenticationPrincipal User user, @PathVariable("teamId") Long teamId, From 10a71429e9690821212f0b9ad3bc373d21d78404 Mon Sep 17 00:00:00 2001 From: Minsu Kim Date: Sat, 30 Sep 2023 12:56:40 +0900 Subject: [PATCH 04/30] =?UTF-8?q?feat:=20Board=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20=EB=8B=A8=EA=B1=B4=20=EC=A1=B0=ED=9A=8C,=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/Board-API.adoc | 9 +- src/docs/asciidoc/Team-API.adoc | 6 +- src/docs/asciidoc/api.adoc | 2 - .../application/dto/response/BoardBlocks.java | 23 ++- .../dto/response/GetAllBoardResponse.java | 8 +- .../dto/response/GetBoardDetailResponse.java | 31 ++++ .../board/application/mapper/BoardMapper.java | 26 +++ .../service/CreateBoardUserCase.java | 24 ++- .../application/service/GetBoardUserCase.java | 41 +++++ .../service/UpdateBoardUserCase.java | 24 +-- .../domain/board/domain/entity/Board.java | 6 +- .../repository/BoardCustomRepository.java | 3 + .../repository/BoardCustomRepositoryImpl.java | 67 ++++++++ .../BoardCustomerRepositoryImpl.java | 4 - .../board/domain/service/BoardGetService.java | 6 + .../domain/service/BoardSaveService.java | 4 +- .../board/presentation/BoardController.java | 34 +++- .../constant/BoardResponseMessage.java | 3 +- .../application/mapper/BoardReadMapper.java | 17 ++ .../repository/BoardReadRepository.java | 13 ++ .../domain/service/BoardReadSaveService.java | 24 +++ .../repository/TeamMemberRepository.java | 3 +- .../domain/service/TeamMemberGetService.java | 3 +- .../presentation/BoardControllerTest.java | 162 +++++++++++++++++- .../team/presentation/TeamControllerTest.java | 25 ++- 25 files changed, 511 insertions(+), 57 deletions(-) create mode 100644 src/main/java/com/moing/backend/domain/board/application/dto/response/GetBoardDetailResponse.java create mode 100644 src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepositoryImpl.java delete mode 100644 src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomerRepositoryImpl.java create mode 100644 src/main/java/com/moing/backend/domain/boardRead/application/mapper/BoardReadMapper.java create mode 100644 src/main/java/com/moing/backend/domain/boardRead/domain/repository/BoardReadRepository.java create mode 100644 src/main/java/com/moing/backend/domain/boardRead/domain/service/BoardReadSaveService.java diff --git a/src/docs/asciidoc/Board-API.adoc b/src/docs/asciidoc/Board-API.adoc index 451cd602..91c9cca7 100644 --- a/src/docs/asciidoc/Board-API.adoc +++ b/src/docs/asciidoc/Board-API.adoc @@ -3,10 +3,15 @@ [[Board-게시글-생성]] === Board 게시글 생성 -operation::board-controller-test/create_board[snippets='http-request,request-fields,http-response,response-fields'] +operation::board-controller-test/create_board[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] --- [[Board-게시글-수정]] === Board 게시글 수정 -operation::board-controller-test/update_board[snippets='http-request,request-fields,http-response,response-fields'] +operation::board-controller-test/update_board[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] +--- + +[[Board-게시글-전체-조회]] +=== Board 게시글 전체 조회 +operation::board-controller-test/get_board_all[snippets='http-request,path-parameters,http-response,response-fields'] --- \ No newline at end of file diff --git a/src/docs/asciidoc/Team-API.adoc b/src/docs/asciidoc/Team-API.adoc index 05ff32e3..c4269911 100644 --- a/src/docs/asciidoc/Team-API.adoc +++ b/src/docs/asciidoc/Team-API.adoc @@ -31,7 +31,7 @@ operation::team-controller-test/create_team[snippets='http-request,request-field [[Team-소모임-가입]] === Team 소모임 가입 -operation::team-controller-test/sign-in_team[snippets='http-request,http-response,response-fields'] +operation::team-controller-test/sign-in_team[snippets='http-request,path-parameters,http-response,response-fields'] [[Team-소모임-조회]] @@ -40,8 +40,8 @@ operation::team-controller-test/get_team[snippets='http-request,http-response,re [[Team-소모임-강제종료]] === Team 소모임 강제종료 -operation::team-controller-test/disband_team[snippets='http-request,http-response,response-fields'] +operation::team-controller-test/disband_team[snippets='http-request,path-parameters,http-response,response-fields'] [[Team-소모임-탈퇴]] === Team 소모임원 강제종료 -operation::team-controller-test/withdraw_team[snippets='http-request,http-response,response-fields'] +operation::team-controller-test/withdraw_team[snippets='http-request,path-parameters,http-response,response-fields'] diff --git a/src/docs/asciidoc/api.adoc b/src/docs/asciidoc/api.adoc index 26bed444..31ab6d71 100644 --- a/src/docs/asciidoc/api.adoc +++ b/src/docs/asciidoc/api.adoc @@ -20,8 +20,6 @@ include::Mission-API.adoc[] include::MissionArchive-API.adoc[] -include::Mission-API.adoc[] - include::Board-API.adoc[] diff --git a/src/main/java/com/moing/backend/domain/board/application/dto/response/BoardBlocks.java b/src/main/java/com/moing/backend/domain/board/application/dto/response/BoardBlocks.java index 08d453bd..eb878fb8 100644 --- a/src/main/java/com/moing/backend/domain/board/application/dto/response/BoardBlocks.java +++ b/src/main/java/com/moing/backend/domain/board/application/dto/response/BoardBlocks.java @@ -1,15 +1,20 @@ package com.moing.backend.domain.board.application.dto.response; +import com.querydsl.core.annotations.QueryProjection; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; @Getter +@Builder +@AllArgsConstructor public class BoardBlocks { private Long boardId; private String writerNickName; - private Boolean isLeader; + private Boolean writerIsLeader; private String writerProfileImage; @@ -20,4 +25,20 @@ public class BoardBlocks { private Integer commentNum; private Boolean isRead; + + @QueryProjection + public BoardBlocks(Long boardId, String writerNickName, Boolean writerIsLeader, String writerProfileImage, String title, String content, Integer commentNum) { + this.boardId = boardId; + this.writerNickName = writerNickName; + this.writerIsLeader = writerIsLeader; + this.writerProfileImage = writerProfileImage; + this.title = title; + this.content = content; + this.commentNum = commentNum; + this.isRead = false; + } + + public void readBoard() { + this.isRead = true; + } } diff --git a/src/main/java/com/moing/backend/domain/board/application/dto/response/GetAllBoardResponse.java b/src/main/java/com/moing/backend/domain/board/application/dto/response/GetAllBoardResponse.java index b2d200ab..f020d9e7 100644 --- a/src/main/java/com/moing/backend/domain/board/application/dto/response/GetAllBoardResponse.java +++ b/src/main/java/com/moing/backend/domain/board/application/dto/response/GetAllBoardResponse.java @@ -13,8 +13,8 @@ @NoArgsConstructor @Getter public class GetAllBoardResponse { - private Long noticeNum; - private List notices=new ArrayList<>(); - private Long notNoticeNum; - private List notNotices=new ArrayList<>(); + private int noticeNum; + private List noticeBlocks=new ArrayList<>(); + private int notNoticeNum; + private List notNoticeBlocks=new ArrayList<>(); } diff --git a/src/main/java/com/moing/backend/domain/board/application/dto/response/GetBoardDetailResponse.java b/src/main/java/com/moing/backend/domain/board/application/dto/response/GetBoardDetailResponse.java new file mode 100644 index 00000000..9d9b4197 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/application/dto/response/GetBoardDetailResponse.java @@ -0,0 +1,31 @@ +package com.moing.backend.domain.board.application.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@Builder +@NoArgsConstructor +@Getter +public class GetBoardDetailResponse { + + private Long boardId; + + private String writerNickName; + + private Boolean writerIsLeader; + + private String writerProfileImage; + + private String title; + + private String content; + + private String createdDate; + + private Boolean isWriter; + + private Boolean isNotice; +} diff --git a/src/main/java/com/moing/backend/domain/board/application/mapper/BoardMapper.java b/src/main/java/com/moing/backend/domain/board/application/mapper/BoardMapper.java index c10a0659..a32c8452 100644 --- a/src/main/java/com/moing/backend/domain/board/application/mapper/BoardMapper.java +++ b/src/main/java/com/moing/backend/domain/board/application/mapper/BoardMapper.java @@ -1,6 +1,7 @@ package com.moing.backend.domain.board.application.mapper; import com.moing.backend.domain.board.application.dto.request.CreateBoardRequest; +import com.moing.backend.domain.board.application.dto.response.GetBoardDetailResponse; 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; @@ -8,6 +9,10 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; + @Component @RequiredArgsConstructor public class BoardMapper { @@ -21,9 +26,30 @@ public Board toBoard(Member member, TeamMember teamMember, Team team, CreateBoar .isNotice(createBoardRequest.getIsNotice()) .commentNum(0) .isLeader(isLeader) + .boardReads(new ArrayList<>()) .build(); board.updateTeamMember(teamMember); board.updateTeam(team); return board; } + + public GetBoardDetailResponse toBoardDetail(Board board, boolean isWriter) { + return GetBoardDetailResponse.builder() + .boardId(board.getBoardId()) + .title(board.getTitle()) + .content(board.getContent()) + .writerNickName(board.getWriterNickName()) + .writerIsLeader(board.isLeader()) + .writerProfileImage(board.getWriterProfileImage()) + .createdDate(getFormattedDate(board.getCreatedDate())) + .isWriter(isWriter) + .isNotice(board.isNotice()) + .build(); + } + + public String getFormattedDate(LocalDateTime localDateTime) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm"); + return localDateTime.format(formatter); + } + } diff --git a/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java index 9c2c615f..25576f2d 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java @@ -5,6 +5,9 @@ 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.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; @@ -16,31 +19,34 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import javax.transaction.Transactional; + @Service +@Transactional @RequiredArgsConstructor public class CreateBoardUserCase { - private final MemberGetService memberGetService; private final BoardSaveService boardSaveService; private final CheckLeaderUserCase checkLeaderUserCase; private final TeamGetService teamGetService; private final BoardMapper boardMapper; private final TeamMemberGetService teamMemberGetService; + private final BoardReadMapper boardReadMapper; + private final BoardReadSaveService boardReadSaveService; /** * 게시글 생성 - * @param user - * @param teamId - * @param createBoardRequest - * @return CreateBoardResponse */ - public CreateBoardResponse createBoard(User user, Long teamId, CreateBoardRequest createBoardRequest) { - Member member = memberGetService.getMemberBySocialId(user.getSocialId()); + public CreateBoardResponse createBoard(String socialId, Long teamId, CreateBoardRequest createBoardRequest) { + Member member=memberGetService.getMemberBySocialId(socialId); Team team = teamGetService.getTeamByTeamId(teamId); TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); boolean isLeader = checkLeaderUserCase.isTeamLeader(member, team); - Board board = boardMapper.toBoard(member, teamMember, team, createBoardRequest, isLeader); - boardSaveService.saveBoard(board); + Board board=boardSaveService.saveBoard(boardMapper.toBoard(member, teamMember, team, createBoardRequest, isLeader)); + + //읽음 처리 + BoardRead boardRead = boardReadMapper.toBoardRead(team, member); + boardReadSaveService.saveBoardRead(board, boardRead); return new CreateBoardResponse(board.getBoardId()); } } diff --git a/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java index 20cf5fba..6be225ae 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java @@ -1,10 +1,51 @@ package com.moing.backend.domain.board.application.service; +import com.moing.backend.domain.board.application.dto.response.GetAllBoardResponse; +import com.moing.backend.domain.board.application.dto.response.GetBoardDetailResponse; +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.BoardGetService; +import com.moing.backend.domain.boardRead.application.mapper.BoardReadMapper; +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.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 lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import javax.transaction.Transactional; + @Service +@Transactional @RequiredArgsConstructor public class GetBoardUserCase { + private final MemberGetService memberGetService; + private final BoardGetService boardGetService; + private final BoardMapper boardMapper; + private final TeamGetService teamGetService; + private final BoardReadMapper boardReadMapper; + private final BoardReadSaveService boardReadSaveService; + private final TeamMemberGetService teamMemberGetService; + + public GetBoardDetailResponse getBoardDetail(String socialId, Long teamId, Long boardId) { + Member member=memberGetService.getMemberBySocialId(socialId); + Team team = teamGetService.getTeamByTeamId(teamId); + Board board = boardGetService.getBoard(boardId); + TeamMember teamMember=teamMemberGetService.getTeamMember(member, team); + //읽음 처리 + BoardRead boardRead = boardReadMapper.toBoardRead(team, member); + boardReadSaveService.saveBoardRead(board, boardRead); + + return boardMapper.toBoardDetail(board, teamMember==board.getTeamMember()); + } + + public GetAllBoardResponse getAllBoard(String socialId, Long teamId){ + Member member=memberGetService.getMemberBySocialId(socialId); + return boardGetService.getBoardAll(teamId, member.getMemberId()); + } } diff --git a/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java index 71a8574b..f11512cf 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java @@ -2,15 +2,14 @@ import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse; -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.BoardGetService; -import com.moing.backend.domain.board.domain.service.BoardSaveService; 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.team.exception.NotAuthException; +import com.moing.backend.domain.teamMember.domain.entity.TeamMember; import com.moing.backend.domain.teamMember.domain.service.TeamMemberGetService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -18,20 +17,25 @@ import javax.transaction.Transactional; @Service +@Transactional @RequiredArgsConstructor public class UpdateBoardUserCase { private final MemberGetService memberGetService; - private final BoardSaveService boardSaveService; - private final CheckLeaderUserCase checkLeaderUserCase; private final TeamGetService teamGetService; - private final BoardMapper boardMapper; private final BoardGetService boardGetService; + private final TeamMemberGetService teamMemberGetService; - @Transactional + /** + * 게시글 수정 + */ public UpdateBoardResponse updateBoard(String socialId, Long teamId, Long boardId, UpdateBoardRequest updateBoardRequest){ Member member=memberGetService.getMemberBySocialId(socialId); - Board board=boardGetService.getBoard(boardId); - board.updateBoard(updateBoardRequest); - return new UpdateBoardResponse(board.getBoardId()); + Team team = teamGetService.getTeamByTeamId(teamId); + Board board = boardGetService.getBoard(boardId); + TeamMember teamMember=teamMemberGetService.getTeamMember(member, team); + if(teamMember==board.getTeamMember()) { + board.updateBoard(updateBoardRequest); + return new UpdateBoardResponse(board.getBoardId()); + }else throw new NotAuthException(); } } diff --git a/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java b/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java index d6034391..cb73c2a7 100644 --- a/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java +++ b/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java @@ -32,11 +32,11 @@ public class Board extends BaseTimeEntity { //반정규화 -> 작성자에 대한 정보 @Convert(converter = AesConverter.class) @Column(nullable = false) - private String writerNickName; + private String writerNickName; /*작성자 닉네임*/ - private boolean isLeader; + private boolean isLeader; /*작성자 소모임장유무*/ - private String writerProfileImage; + private String writerProfileImage; /*작성자 프로필 사진*/ @Column(nullable = false, length = 15) private String title; diff --git a/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepository.java b/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepository.java index ef5053e3..10d5ffbd 100644 --- a/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepository.java @@ -1,4 +1,7 @@ package com.moing.backend.domain.board.domain.repository; +import com.moing.backend.domain.board.application.dto.response.GetAllBoardResponse; + public interface BoardCustomRepository { + GetAllBoardResponse findBoardAll(Long teamId, Long boardId); } diff --git a/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepositoryImpl.java new file mode 100644 index 00000000..b1b0e863 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomRepositoryImpl.java @@ -0,0 +1,67 @@ +package com.moing.backend.domain.board.domain.repository; + +import com.moing.backend.domain.board.application.dto.response.BoardBlocks; +import com.moing.backend.domain.board.application.dto.response.GetAllBoardResponse; +import com.moing.backend.domain.board.domain.entity.Board; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import javax.persistence.EntityManager; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +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 { + private final JPAQueryFactory queryFactory; + + public BoardCustomRepositoryImpl(EntityManager em) { + this.queryFactory = new JPAQueryFactory(em); + } + + @Override + public GetAllBoardResponse findBoardAll(Long teamId, Long memberId) { + // 전체 게시글 보기 + List allBoards = queryFactory.selectFrom(board) + .where(board.team.teamId.eq(teamId)) + .orderBy(board.createdDate.desc()) + .fetch(); + + // 읽은 게시글 보기 + List readBoards = queryFactory.selectFrom(board) + .join(boardRead).on(boardRead.board.eq(board)) + .where(board.team.teamId.eq(teamId)) + .where(boardRead.member.memberId.eq(memberId)) + .groupBy(board.boardId) + .orderBy(board.createdDate.desc()) + .fetch(); + + // 공지와 일반 게시글로 나누기 + List notices = allBoards.stream().filter(Board::isNotice).collect(Collectors.toList()); + List regularPosts = allBoards.stream().filter(b -> !b.isNotice()).collect(Collectors.toList()); + + // Board -> BoardBlocks 변환 + Function toBoardBlocks = b -> { + boolean isRead = readBoards.contains(b); + BoardBlocks boardBlocks = new BoardBlocks( + b.getBoardId(), + b.getWriterNickName(), + b.isLeader(), + b.getWriterProfileImage(), + b.getTitle(), + b.getContent(), + b.getCommentNum() + ); + if (isRead) { + boardBlocks.readBoard(); + } + return boardBlocks; + }; + + List noticeBlocks = notices.stream().map(toBoardBlocks).collect(Collectors.toList()); + List regularBlocks = regularPosts.stream().map(toBoardBlocks).collect(Collectors.toList()); + + return new GetAllBoardResponse(noticeBlocks.size(), noticeBlocks, regularBlocks.size(), regularBlocks); + } +} diff --git a/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomerRepositoryImpl.java b/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomerRepositoryImpl.java deleted file mode 100644 index 668825cf..00000000 --- a/src/main/java/com/moing/backend/domain/board/domain/repository/BoardCustomerRepositoryImpl.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.moing.backend.domain.board.domain.repository; - -public class BoardCustomerRepositoryImpl implements BoardCustomRepository{ -} diff --git a/src/main/java/com/moing/backend/domain/board/domain/service/BoardGetService.java b/src/main/java/com/moing/backend/domain/board/domain/service/BoardGetService.java index 88cc75e0..f1c62e2e 100644 --- a/src/main/java/com/moing/backend/domain/board/domain/service/BoardGetService.java +++ b/src/main/java/com/moing/backend/domain/board/domain/service/BoardGetService.java @@ -1,5 +1,7 @@ package com.moing.backend.domain.board.domain.service; +import com.moing.backend.domain.board.application.dto.response.GetAllBoardResponse; +import com.moing.backend.domain.board.application.dto.response.GetBoardDetailResponse; import com.moing.backend.domain.board.domain.entity.Board; import com.moing.backend.domain.board.domain.repository.BoardRepository; import com.moing.backend.domain.board.exception.NotFoundByBoardIdException; @@ -19,4 +21,8 @@ public class BoardGetService { public Board getBoard(Long boardId){ return boardRepository.findBoardByBoardId(boardId).orElseThrow(()->new NotFoundByBoardIdException()); } + + public GetAllBoardResponse getBoardAll(Long teamId, Long memberId){ + return boardRepository.findBoardAll(teamId, memberId); + } } diff --git a/src/main/java/com/moing/backend/domain/board/domain/service/BoardSaveService.java b/src/main/java/com/moing/backend/domain/board/domain/service/BoardSaveService.java index 33c8a180..e2e800ff 100644 --- a/src/main/java/com/moing/backend/domain/board/domain/service/BoardSaveService.java +++ b/src/main/java/com/moing/backend/domain/board/domain/service/BoardSaveService.java @@ -14,7 +14,7 @@ public class BoardSaveService { private final BoardRepository boardRepository; - public void saveBoard(Board board) { - this.boardRepository.save(board); + public Board saveBoard(Board board) { + return this.boardRepository.save(board); } } 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 a3b86e9c..629eebeb 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 @@ -3,9 +3,13 @@ import com.moing.backend.domain.board.application.dto.request.CreateBoardRequest; import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; import com.moing.backend.domain.board.application.dto.response.CreateBoardResponse; +import com.moing.backend.domain.board.application.dto.response.GetAllBoardResponse; +import com.moing.backend.domain.board.application.dto.response.GetBoardDetailResponse; import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse; import com.moing.backend.domain.board.application.service.CreateBoardUserCase; +import com.moing.backend.domain.board.application.service.GetBoardUserCase; import com.moing.backend.domain.board.application.service.UpdateBoardUserCase; +import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.global.config.security.dto.User; import com.moing.backend.global.response.SuccessResponse; import lombok.AllArgsConstructor; @@ -15,8 +19,7 @@ import javax.validation.Valid; -import static com.moing.backend.domain.board.presentation.constant.BoardResponseMessage.CREATE_BOARD_SUCCESS; -import static com.moing.backend.domain.board.presentation.constant.BoardResponseMessage.UPDATE_BOARD_SUCCESS; +import static com.moing.backend.domain.board.presentation.constant.BoardResponseMessage.*; @RestController @AllArgsConstructor @@ -25,6 +28,7 @@ public class BoardController { private final CreateBoardUserCase createBoardUserCase; private final UpdateBoardUserCase updateBoardUserCase; + private final GetBoardUserCase getBoardUserCase; /** * 게시글 생성 @@ -35,7 +39,7 @@ public class BoardController { public ResponseEntity> createBoard(@AuthenticationPrincipal User user, @PathVariable Long teamId, @Valid @RequestBody CreateBoardRequest createBoardRequest) { - return ResponseEntity.ok(SuccessResponse.create(CREATE_BOARD_SUCCESS.getMessage(), this.createBoardUserCase.createBoard(user, teamId, createBoardRequest))); + return ResponseEntity.ok(SuccessResponse.create(CREATE_BOARD_SUCCESS.getMessage(), this.createBoardUserCase.createBoard(user.getSocialId(), teamId, createBoardRequest))); } /** @@ -43,7 +47,6 @@ public ResponseEntity> createBoard(@Authent * [PUT] api/{teamId}/board/{boardId} * 작성자 : 김민수 */ - @PutMapping("/{boardId}") public ResponseEntity> updateBoard(@AuthenticationPrincipal User user, @PathVariable Long teamId, @@ -51,4 +54,27 @@ public ResponseEntity> updateBoard(@Authent @Valid @RequestBody UpdateBoardRequest updateBoardRequest) { return ResponseEntity.ok(SuccessResponse.create(UPDATE_BOARD_SUCCESS.getMessage(), this.updateBoardUserCase.updateBoard(user.getSocialId(), teamId, boardId, updateBoardRequest))); } + + /** + * 게시글 상세 조회 + * [GET] api/{teamId}/board/{boardId} + * 작성자 : 김민수 + */ + @GetMapping("/{boardId}") + public ResponseEntity> getBoardDetail(@AuthenticationPrincipal User user, + @PathVariable Long teamId, + @PathVariable Long boardId) { + return ResponseEntity.ok(SuccessResponse.create(GET_BOARD_DETAIL_SUCCESS.getMessage(), this.getBoardUserCase.getBoardDetail(user.getSocialId(), teamId, boardId))); + } + + /** + * 게시글 전체 조회 + * [GET] api/{teamId}/board + * 작성자 : 김민수 + */ + @GetMapping + public ResponseEntity> getBoardAll(@AuthenticationPrincipal User user, + @PathVariable Long teamId) { + return ResponseEntity.ok(SuccessResponse.create(GET_BOARD_ALL_SUCCESS.getMessage(), this.getBoardUserCase.getAllBoard(user.getSocialId(), teamId))); + } } diff --git a/src/main/java/com/moing/backend/domain/board/presentation/constant/BoardResponseMessage.java b/src/main/java/com/moing/backend/domain/board/presentation/constant/BoardResponseMessage.java index 65a9fbcd..37eba647 100644 --- a/src/main/java/com/moing/backend/domain/board/presentation/constant/BoardResponseMessage.java +++ b/src/main/java/com/moing/backend/domain/board/presentation/constant/BoardResponseMessage.java @@ -8,6 +8,7 @@ public enum BoardResponseMessage { CREATE_BOARD_SUCCESS("게시글을 생성했습니다."), GET_BOARD_ALL_SUCCESS("게시글 목록을 모두 조회했습니다."), - UPDATE_BOARD_SUCCESS("게시글을 수정했습니다."); + UPDATE_BOARD_SUCCESS("게시글을 수정했습니다."), + GET_BOARD_DETAIL_SUCCESS("게시글 상세 조회했습니다."); private final String message; } diff --git a/src/main/java/com/moing/backend/domain/boardRead/application/mapper/BoardReadMapper.java b/src/main/java/com/moing/backend/domain/boardRead/application/mapper/BoardReadMapper.java new file mode 100644 index 00000000..740e6b1a --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardRead/application/mapper/BoardReadMapper.java @@ -0,0 +1,17 @@ +package com.moing.backend.domain.boardRead.application.mapper; + +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.boardRead.domain.entity.BoardRead; +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.team.domain.entity.Team; +import org.springframework.stereotype.Component; + +@Component +public class BoardReadMapper { + public BoardRead toBoardRead(Team team, Member member){ + BoardRead boardRead=new BoardRead(); + boardRead.updateTeam(team); + boardRead.updateMember(member); + return boardRead; + } +} diff --git a/src/main/java/com/moing/backend/domain/boardRead/domain/repository/BoardReadRepository.java b/src/main/java/com/moing/backend/domain/boardRead/domain/repository/BoardReadRepository.java new file mode 100644 index 00000000..b17cca58 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardRead/domain/repository/BoardReadRepository.java @@ -0,0 +1,13 @@ +package com.moing.backend.domain.boardRead.domain.repository; + +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.boardRead.domain.entity.BoardRead; +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.team.domain.entity.Team; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface BoardReadRepository extends JpaRepository { + Optional findBoardReadByBoardAndMemberAndTeam(Board board, Member member, Team team); +} diff --git a/src/main/java/com/moing/backend/domain/boardRead/domain/service/BoardReadSaveService.java b/src/main/java/com/moing/backend/domain/boardRead/domain/service/BoardReadSaveService.java new file mode 100644 index 00000000..1e81792d --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardRead/domain/service/BoardReadSaveService.java @@ -0,0 +1,24 @@ +package com.moing.backend.domain.boardRead.domain.service; + +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.boardRead.domain.entity.BoardRead; +import com.moing.backend.domain.boardRead.domain.repository.BoardReadRepository; +import com.moing.backend.global.annotation.DomainService; +import lombok.RequiredArgsConstructor; + +import javax.transaction.Transactional; + +@DomainService +@RequiredArgsConstructor +@Transactional +public class BoardReadSaveService { + + private final BoardReadRepository boardReadRepository; + + public void saveBoardRead(Board board, BoardRead boardRead) { + if ((boardReadRepository.findBoardReadByBoardAndMemberAndTeam(board, boardRead.getMember(), boardRead.getTeam())).isEmpty()) { + boardRead.updateBoard(board); + boardReadRepository.save(boardRead); + } + } +} diff --git a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberRepository.java b/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberRepository.java index 703bb968..6bcc3808 100644 --- a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberRepository.java +++ b/src/main/java/com/moing/backend/domain/teamMember/domain/repository/TeamMemberRepository.java @@ -9,6 +9,5 @@ import java.util.Optional; public interface TeamMemberRepository extends JpaRepository, TeamMemberCustomRepository{ - - TeamMember findTeamMemberByTeamAndMember(Team team, Member member); + Optional findTeamMemberByTeamAndMember(Team team, Member member); } diff --git a/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberGetService.java b/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberGetService.java index f91866e0..e224a89a 100644 --- a/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberGetService.java +++ b/src/main/java/com/moing/backend/domain/teamMember/domain/service/TeamMemberGetService.java @@ -2,6 +2,7 @@ import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.team.domain.entity.Team; +import com.moing.backend.domain.team.exception.NotFoundByTeamIdException; import com.moing.backend.domain.teamMember.domain.entity.TeamMember; import com.moing.backend.domain.teamMember.domain.repository.TeamMemberRepository; import com.moing.backend.global.annotation.DomainService; @@ -19,6 +20,6 @@ public List getTeamMemberIds(Long teamId){ } public TeamMember getTeamMember(Member member, Team team){ - return teamMemberRepository.findTeamMemberByTeamAndMember(team, member); + return teamMemberRepository.findTeamMemberByTeamAndMember(team, member).orElseThrow(()-> new NotFoundByTeamIdException()); } } diff --git a/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java b/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java index bb368b7a..ed64387e 100644 --- a/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java +++ b/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java @@ -3,9 +3,9 @@ import com.moing.backend.config.CommonControllerTest; import com.moing.backend.domain.board.application.dto.request.CreateBoardRequest; import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; -import com.moing.backend.domain.board.application.dto.response.CreateBoardResponse; -import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse; +import com.moing.backend.domain.board.application.dto.response.*; import com.moing.backend.domain.board.application.service.CreateBoardUserCase; +import com.moing.backend.domain.board.application.service.GetBoardUserCase; import com.moing.backend.domain.board.application.service.UpdateBoardUserCase; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -14,11 +14,16 @@ 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(BoardController.class) @@ -28,6 +33,9 @@ public class BoardControllerTest extends CommonControllerTest { @MockBean private UpdateBoardUserCase updateBoardUserCase; + @MockBean + private GetBoardUserCase getBoardUserCase; + @Test public void create_board() throws Exception { @@ -64,6 +72,9 @@ public void create_board() throws Exception { requestHeaders( headerWithName("Authorization").description("접근 토큰") ), + pathParameters( + parameterWithName("teamId").description("팀 아이디") + ), requestFields( fieldWithPath("title").description("게시글 제목"), fieldWithPath("content").description("게시글 내용"), @@ -115,6 +126,10 @@ public void update_board() throws Exception { requestHeaders( headerWithName("Authorization").description("접근 토큰") ), + pathParameters( + parameterWithName("teamId").description("팀 아이디"), + parameterWithName("boardId").description("게시글 아이디") + ), requestFields( fieldWithPath("title").description("게시글 제목"), fieldWithPath("content").description("게시글 내용"), @@ -128,4 +143,147 @@ public void update_board() throws Exception { ) ); } + + @Test + public void get_board_all() throws Exception { + //given + List noticeBlocks = new ArrayList<>(); + List notNoticeBlocks = new ArrayList<>(); + Long teamId = 1L; + + BoardBlocks noticeBlock = BoardBlocks.builder() + .boardId(1L) + .writerIsLeader(true) + .writerNickName("작성자 닉네임") + .writerProfileImage("작성자 프로필 이미지") + .title("공지 제목") + .content("공지 내용") + .commentNum(2) + .isRead(false) + .build(); + + BoardBlocks notNoticeBlock = BoardBlocks.builder() + .boardId(1L) + .writerIsLeader(true) + .writerNickName("작성자 닉네임") + .writerProfileImage("작성자 프로필 이미지") + .title("게시글 제목") + .content("게시글 내용") + .commentNum(2) + .isRead(false) + .build(); + + noticeBlocks.add(noticeBlock); + notNoticeBlocks.add(notNoticeBlock); + + GetAllBoardResponse output = new GetAllBoardResponse(noticeBlocks.size(), noticeBlocks, notNoticeBlocks.size(), notNoticeBlocks); + + given(getBoardUserCase.getAllBoard(any(), any())).willReturn(output); + + + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + get("/api/{teamId}/board", teamId) + .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("팀 아이디") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description("게시글 목록을 모두 조회했습니다."), + fieldWithPath("data.noticeNum").description("공지 개수"), + fieldWithPath("data.noticeBlocks[0].boardId").description("공지 아이디"), + fieldWithPath("data.noticeBlocks[0].writerNickName").description("작성자 닉네임"), + fieldWithPath("data.noticeBlocks[0].writerIsLeader").description("작성자 소모임장 여부"), + fieldWithPath("data.noticeBlocks[0].writerProfileImage").description("작성자 프로필 이미지"), + fieldWithPath("data.noticeBlocks[0].title").description("공지 제목"), + fieldWithPath("data.noticeBlocks[0].content").description("공지 내용"), + fieldWithPath("data.noticeBlocks[0].commentNum").description("공지 댓글 개수"), + fieldWithPath("data.noticeBlocks[0].isRead").description("공지 읽음 처리 여부"), + fieldWithPath("data.notNoticeNum").description("일반 게시글 개수"), + fieldWithPath("data.notNoticeBlocks[0].boardId").description("일반 게시글 아이디"), + fieldWithPath("data.notNoticeBlocks[0].writerNickName").description("작성자 닉네임"), + fieldWithPath("data.notNoticeBlocks[0].writerIsLeader").description("작성자 소모임장 여부"), + fieldWithPath("data.notNoticeBlocks[0].writerProfileImage").description("작성자 프로필 이미지"), + fieldWithPath("data.notNoticeBlocks[0].title").description("일반 게시글 제목"), + fieldWithPath("data.notNoticeBlocks[0].content").description("일반 게시글 내용"), + fieldWithPath("data.notNoticeBlocks[0].commentNum").description("일반 게시글 댓글 개수"), + fieldWithPath("data.notNoticeBlocks[0].isRead").description("일반 게시글 읽음 처리 여부") + ) + + ) + ); + } + + @Test + public void get_board_detail() throws Exception { + //given + Long teamId = 1L; + Long boardId=1L; + + GetBoardDetailResponse output = GetBoardDetailResponse.builder() + .boardId(1L) + .writerIsLeader(true) + .writerNickName("작성자 닉네임") + .writerProfileImage("작성자 프로필 이미지") + .title("게시글 제목") + .content("게시글 내용") + .createdDate("2023/09/29 23:42") + .isWriter(false) + .isNotice(false) + .build(); + + given(getBoardUserCase.getBoardDetail(any(), any(), any())).willReturn(output); + + + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + get("/api/{teamId}/board/{boardId}", 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("boardId").description("게시글 아이디") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description("게시글 목록을 모두 조회했습니다."), + fieldWithPath("data.boardId").description("게시글 아이디"), + fieldWithPath("data.writerNickName").description("작성자 닉네임"), + fieldWithPath("data.writerIsLeader").description("작성자 소모임장 여부"), + fieldWithPath("data.writerProfileImage").description("작성자 프로필 이미지"), + fieldWithPath("data.title").description("게시글 제목"), + fieldWithPath("data.content").description("게시글 내용"), + fieldWithPath("data.createdDate").description("게시글 생성 날짜, 시간"), + fieldWithPath("data.isWriter").description("게시글 작성자 여부"), + fieldWithPath("data.isNotice").description("게시글 공지 여부") + ) + + ) + ); + } + } diff --git a/src/test/java/com/moing/backend/domain/team/presentation/TeamControllerTest.java b/src/test/java/com/moing/backend/domain/team/presentation/TeamControllerTest.java index 737c7af4..734d871f 100644 --- a/src/test/java/com/moing/backend/domain/team/presentation/TeamControllerTest.java +++ b/src/test/java/com/moing/backend/domain/team/presentation/TeamControllerTest.java @@ -8,10 +8,10 @@ import com.moing.backend.domain.team.application.dto.response.TeamBlock; import com.moing.backend.domain.team.application.service.*; import org.junit.jupiter.api.Test; -import org.mockito.Mock; 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; @@ -22,6 +22,8 @@ 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.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -174,8 +176,8 @@ public void disband_team() throws Exception { given(disbandTeamUserCase.disbandTeam(any(), any())).willReturn(output); //when - ResultActions actions = mockMvc.perform( - delete("/api/team/" + teamId + "/disband") + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + delete("/api/team/{teamId}/disband", teamId) .header("Authorization", "Bearer ACCESS_TOKEN") .contentType(MediaType.APPLICATION_JSON) ); @@ -188,6 +190,9 @@ public void disband_team() throws Exception { requestHeaders( headerWithName("Authorization").description("접근 토큰") ), + pathParameters( + parameterWithName("teamId").description("팀 아이디") + ), responseFields( fieldWithPath("isSuccess").description("true"), fieldWithPath("message").description("[소모임장 권한] 소모임을 강제 종료했습니다."), @@ -207,8 +212,8 @@ public void withdraw_team() throws Exception { given(withdrawTeamUserCase.withdrawTeam(any(), any())).willReturn(output); //when - ResultActions actions = mockMvc.perform( - delete("/api/team/" + teamId + "/withdraw") + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + delete("/api/team/{teamId}/withdraw", teamId) .header("Authorization", "Bearer ACCESS_TOKEN") .contentType(MediaType.APPLICATION_JSON) ); @@ -221,6 +226,9 @@ public void withdraw_team() throws Exception { requestHeaders( headerWithName("Authorization").description("접근 토큰") ), + pathParameters( + parameterWithName("teamId").description("팀 아이디") + ), responseFields( fieldWithPath("isSuccess").description("true"), fieldWithPath("message").description("[소모임원 권한] 소모임을 탈퇴하였습니다"), @@ -241,8 +249,8 @@ public void signIn_team() throws Exception { given(signInTeamUserCase.signInTeam(any(), any())).willReturn(output); //when - ResultActions actions = mockMvc.perform( - post("/api/team/" + teamId) + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + post("/api/team/{teamId}", teamId) .header("Authorization", "Bearer ACCESS_TOKEN") .contentType(MediaType.APPLICATION_JSON) ); @@ -255,6 +263,9 @@ public void signIn_team() throws Exception { requestHeaders( headerWithName("Authorization").description("접근 토큰") ), + pathParameters( + parameterWithName("teamId").description("팀 아이디") + ), responseFields( fieldWithPath("isSuccess").description("true"), fieldWithPath("message").description("소모임에 가입하였습니다."), From ddecb7955eb8cf4531113fa60cbefe86a1d8f604 Mon Sep 17 00:00:00 2001 From: Minsu Kim Date: Sat, 30 Sep 2023 13:17:00 +0900 Subject: [PATCH 05/30] =?UTF-8?q?errorCode=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/Overview.adoc | 38 +++++++++++++++++-- .../service/UpdateBoardUserCase.java | 6 +-- .../exception/NotAuthByBoardException.java | 11 ++++++ .../service/DisbandTeamUserCase.java | 4 +- ...ption.java => NotAuthByTeamException.java} | 4 +- .../backend/global/response/ErrorCode.java | 8 ++-- 6 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/moing/backend/domain/board/exception/NotAuthByBoardException.java rename src/main/java/com/moing/backend/domain/team/exception/{NotAuthException.java => NotAuthByTeamException.java} (71%) diff --git a/src/docs/asciidoc/Overview.adoc b/src/docs/asciidoc/Overview.adoc index 4461b8a4..2b9e0a24 100644 --- a/src/docs/asciidoc/Overview.adoc +++ b/src/docs/asciidoc/Overview.adoc @@ -78,15 +78,45 @@ | `AU0003` | 로그인할 때 | appId가 일치하지 않음 (유효하지 않음) + +| `AU0004` +| 회원가입할 때 +| 닉네임이 중복됨 +|=== + +=== Team ErrorCode +|=== +| ErrorCode | Scope | Description +| `T0001` +| API PATH에 teamId가 있을 때 +| teamId가 유효하지 않음 (존재하지 않거나, 해당 유저가 그 팀에 속해있지 않거나) + +| `T0002` +| 소모임을 수정, 삭제하려고 할 때 +| 소모임장이 아님 (권한 없음) |=== -=== Team / Team_member ErrorCode +=== Board ErrorCode |=== | ErrorCode | Scope | Description -| `TM0001` -| 팀 개설할 때 -| 팀 최대 개수 3을 초과 +| `B0001` +| API PATH에 boardId가 있을 때 +| boardId가 유효하지 않음 (존재하지 않음) + +| `B0002` +| 게시글을 수정, 삭제하려고 할 때 +| 작성자가 아님 (권한 없음) |=== +=== Mission ErrorCode +|=== +| ErrorCode | Scope | Description +| `M0001` +| 미션 생성할 때 +| 소모임장이 아님 +| `M0002` +| API PATH에 missionId가 있으 때 +| missionId가 유요하지 않음 +|=== diff --git a/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java index f11512cf..2643da09 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java @@ -4,11 +4,11 @@ import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse; import com.moing.backend.domain.board.domain.entity.Board; import com.moing.backend.domain.board.domain.service.BoardGetService; +import com.moing.backend.domain.board.exception.NotAuthByBoardException; import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.member.domain.service.MemberGetService; import com.moing.backend.domain.team.domain.entity.Team; import com.moing.backend.domain.team.domain.service.TeamGetService; -import com.moing.backend.domain.team.exception.NotAuthException; import com.moing.backend.domain.teamMember.domain.entity.TeamMember; import com.moing.backend.domain.teamMember.domain.service.TeamMemberGetService; import lombok.RequiredArgsConstructor; @@ -33,9 +33,9 @@ public UpdateBoardResponse updateBoard(String socialId, Long teamId, Long boardI Team team = teamGetService.getTeamByTeamId(teamId); Board board = boardGetService.getBoard(boardId); TeamMember teamMember=teamMemberGetService.getTeamMember(member, team); - if(teamMember==board.getTeamMember()) { + if (teamMember == board.getTeamMember()) { board.updateBoard(updateBoardRequest); return new UpdateBoardResponse(board.getBoardId()); - }else throw new NotAuthException(); + } else throw new NotAuthByBoardException(); } } diff --git a/src/main/java/com/moing/backend/domain/board/exception/NotAuthByBoardException.java b/src/main/java/com/moing/backend/domain/board/exception/NotAuthByBoardException.java new file mode 100644 index 00000000..704c0873 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/exception/NotAuthByBoardException.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.board.exception; + +import com.moing.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public class NotAuthByBoardException extends BoardException { + public NotAuthByBoardException() { + super(ErrorCode.NOT_AUTH_BY_BOARD_ID_ERROR, + HttpStatus.NOT_FOUND); + } +} diff --git a/src/main/java/com/moing/backend/domain/team/application/service/DisbandTeamUserCase.java b/src/main/java/com/moing/backend/domain/team/application/service/DisbandTeamUserCase.java index 3efa23fe..19e133ad 100644 --- a/src/main/java/com/moing/backend/domain/team/application/service/DisbandTeamUserCase.java +++ b/src/main/java/com/moing/backend/domain/team/application/service/DisbandTeamUserCase.java @@ -5,7 +5,7 @@ import com.moing.backend.domain.team.application.dto.response.DeleteTeamResponse; import com.moing.backend.domain.team.domain.entity.Team; import com.moing.backend.domain.team.domain.service.TeamGetService; -import com.moing.backend.domain.team.exception.NotAuthException; +import com.moing.backend.domain.team.exception.NotAuthByTeamException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -26,7 +26,7 @@ public DeleteTeamResponse disbandTeam(String socialId, Long teamId) { if (checkLeaderUserCase.isTeamLeader(member, team)) { team.deleteTeam(); } else { - throw new NotAuthException(); + throw new NotAuthByTeamException(); } return new DeleteTeamResponse(team.getTeamId()); } diff --git a/src/main/java/com/moing/backend/domain/team/exception/NotAuthException.java b/src/main/java/com/moing/backend/domain/team/exception/NotAuthByTeamException.java similarity index 71% rename from src/main/java/com/moing/backend/domain/team/exception/NotAuthException.java rename to src/main/java/com/moing/backend/domain/team/exception/NotAuthByTeamException.java index 14e66aef..7d99e8cb 100644 --- a/src/main/java/com/moing/backend/domain/team/exception/NotAuthException.java +++ b/src/main/java/com/moing/backend/domain/team/exception/NotAuthByTeamException.java @@ -3,8 +3,8 @@ import com.moing.backend.global.response.ErrorCode; import org.springframework.http.HttpStatus; -public class NotAuthException extends TeamException{ - public NotAuthException(){ +public class NotAuthByTeamException extends TeamException{ + public NotAuthByTeamException(){ super(ErrorCode.NOT_AUTH_BY_TEAM_ERROR, HttpStatus.UNAUTHORIZED); } 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 dda3ec42..d81c948d 100644 --- a/src/main/java/com/moing/backend/global/response/ErrorCode.java +++ b/src/main/java/com/moing/backend/global/response/ErrorCode.java @@ -18,10 +18,7 @@ public enum ErrorCode { ACCOUNT_ALREADY_EXIST("AU0001", "해당 email로 다른 소셜 플랫폼으로 가입하였습니다."), TOKEN_INVALID_ERROR("AU0002", "입력 토큰이 유효하지 않습니다."), APPID_INVALID_ERROR("AU0003", "appId가 유효하지 않습니다"), - NICKNAME_DUPLICATION_ERROR("AU0003", "닉네임이 중복됩니다."), - - //팀멤버 에러 코드 - TOO_MANY_TEAM_MEMBER_ERROR("TM0001", "팀 최대 개수 3을 초과했습니다"), + NICKNAME_DUPLICATION_ERROR("AU0004", "닉네임이 중복됩니다."), //미션 관련 에러코드 NO_ACCESS_CREATE_MISSION("M0001", "소모임장만 미션을 생성할 수 있습니다."), @@ -33,7 +30,8 @@ public enum ErrorCode { NOT_AUTH_BY_TEAM_ERROR("T0002","권한이 없습니다."), //게시글 관련 에러 코드 - NOT_FOUND_BY_BOARD_ID_ERROR("B0001","해당 boardId인 팀이 존재하지 않습니다."); + NOT_FOUND_BY_BOARD_ID_ERROR("B0001","해당 boardId인 팀이 존재하지 않습니다."), + NOT_AUTH_BY_BOARD_ID_ERROR("B0002","권한이 없습니다."); private String errorCode; private String message; From 50f3dc93e0d9f0b39cb86dfc378ae3df37ef02ba Mon Sep 17 00:00:00 2001 From: Minsu Kim Date: Sat, 30 Sep 2023 14:16:42 +0900 Subject: [PATCH 06/30] =?UTF-8?q?feat:=20Board=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/Board-API.adoc | 10 +++++ .../service/DeleteBoardUserCase.java | 42 +++++++++++++++++++ .../application/service/GetBoardUserCase.java | 6 +++ .../domain/service/BoardDeleteService.java | 20 +++++++++ .../board/presentation/BoardController.java | 15 +++++++ .../constant/BoardResponseMessage.java | 3 +- .../presentation/BoardControllerTest.java | 40 +++++++++++++++++- 7 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java create mode 100644 src/main/java/com/moing/backend/domain/board/domain/service/BoardDeleteService.java diff --git a/src/docs/asciidoc/Board-API.adoc b/src/docs/asciidoc/Board-API.adoc index 91c9cca7..8e0de4ca 100644 --- a/src/docs/asciidoc/Board-API.adoc +++ b/src/docs/asciidoc/Board-API.adoc @@ -11,7 +11,17 @@ operation::board-controller-test/create_board[snippets='http-request,path-parame operation::board-controller-test/update_board[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] --- +[[Board-게시글-삭제]] +=== Board 게시글 삭제 +operation::board-controller-test/delete_board[snippets='http-request,path-parameters,request-fields,response-fields'] +--- + [[Board-게시글-전체-조회]] === Board 게시글 전체 조회 operation::board-controller-test/get_board_all[snippets='http-request,path-parameters,http-response,response-fields'] +--- + +[[Board-게시글-상제-조회]] +=== Board 게시글 상세 조회 +operation::board-controller-test/get_board_detail[snippets='http-request,path-parameters,http-response,response-fields'] --- \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java new file mode 100644 index 00000000..6a6cee91 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java @@ -0,0 +1,42 @@ +package com.moing.backend.domain.board.application.service; + +import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; +import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse; +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.board.domain.service.BoardDeleteService; +import com.moing.backend.domain.board.domain.service.BoardGetService; +import com.moing.backend.domain.board.exception.NotAuthByBoardException; +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.member.domain.service.MemberGetService; +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 lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class DeleteBoardUserCase { + + private final MemberGetService memberGetService; + private final TeamGetService teamGetService; + private final BoardGetService boardGetService; + private final TeamMemberGetService teamMemberGetService; + private final BoardDeleteService boardDeleteService; + /** + * 게시글 삭제 + */ + public void deleteBoard(String socialId, Long teamId, Long boardId){ + Member member=memberGetService.getMemberBySocialId(socialId); + Team team = teamGetService.getTeamByTeamId(teamId); + Board board = boardGetService.getBoard(boardId); + TeamMember teamMember=teamMemberGetService.getTeamMember(member, team); + if (teamMember == board.getTeamMember()) { + boardDeleteService.deleteBoard(board); + } else throw new NotAuthByBoardException(); + } +} diff --git a/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java index 6be225ae..c9116f63 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java @@ -32,6 +32,9 @@ public class GetBoardUserCase { private final BoardReadSaveService boardReadSaveService; private final TeamMemberGetService teamMemberGetService; + /** + * 게시글 상세 조회 + */ public GetBoardDetailResponse getBoardDetail(String socialId, Long teamId, Long boardId) { Member member=memberGetService.getMemberBySocialId(socialId); Team team = teamGetService.getTeamByTeamId(teamId); @@ -44,6 +47,9 @@ public GetBoardDetailResponse getBoardDetail(String socialId, Long teamId, Long return boardMapper.toBoardDetail(board, teamMember==board.getTeamMember()); } + /** + * 게시글 전체 조회 + */ public GetAllBoardResponse getAllBoard(String socialId, Long teamId){ Member member=memberGetService.getMemberBySocialId(socialId); return boardGetService.getBoardAll(teamId, member.getMemberId()); diff --git a/src/main/java/com/moing/backend/domain/board/domain/service/BoardDeleteService.java b/src/main/java/com/moing/backend/domain/board/domain/service/BoardDeleteService.java new file mode 100644 index 00000000..cb016b83 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/board/domain/service/BoardDeleteService.java @@ -0,0 +1,20 @@ +package com.moing.backend.domain.board.domain.service; + +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.board.domain.repository.BoardRepository; +import com.moing.backend.global.annotation.DomainService; +import lombok.RequiredArgsConstructor; + +import javax.transaction.Transactional; + +@DomainService +@Transactional +@RequiredArgsConstructor +public class BoardDeleteService { + + private final BoardRepository boardRepository; + + public void deleteBoard(Board board){ + boardRepository.delete(board); + } +} 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 629eebeb..a25fdf9d 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 @@ -7,6 +7,7 @@ import com.moing.backend.domain.board.application.dto.response.GetBoardDetailResponse; import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse; import com.moing.backend.domain.board.application.service.CreateBoardUserCase; +import com.moing.backend.domain.board.application.service.DeleteBoardUserCase; import com.moing.backend.domain.board.application.service.GetBoardUserCase; import com.moing.backend.domain.board.application.service.UpdateBoardUserCase; import com.moing.backend.domain.member.domain.entity.Member; @@ -29,6 +30,7 @@ public class BoardController { private final CreateBoardUserCase createBoardUserCase; private final UpdateBoardUserCase updateBoardUserCase; private final GetBoardUserCase getBoardUserCase; + private final DeleteBoardUserCase deleteBoardUserCase; /** * 게시글 생성 @@ -55,6 +57,19 @@ public ResponseEntity> updateBoard(@Authent return ResponseEntity.ok(SuccessResponse.create(UPDATE_BOARD_SUCCESS.getMessage(), this.updateBoardUserCase.updateBoard(user.getSocialId(), teamId, boardId, updateBoardRequest))); } + /** + * 게시글 삭제 + * [DELETE] api/{teamId}/board/{boardId} + * 작성자 : 김민수 + */ + @DeleteMapping("/{boardId}") + public ResponseEntity> deleteBoard(@AuthenticationPrincipal User user, + @PathVariable Long teamId, + @PathVariable Long boardId) { + this.deleteBoardUserCase.deleteBoard(user.getSocialId(), teamId, boardId); + return ResponseEntity.ok(SuccessResponse.create(DELETE_BOARD_SUCCESS.getMessage())); + } + /** * 게시글 상세 조회 * [GET] api/{teamId}/board/{boardId} diff --git a/src/main/java/com/moing/backend/domain/board/presentation/constant/BoardResponseMessage.java b/src/main/java/com/moing/backend/domain/board/presentation/constant/BoardResponseMessage.java index 37eba647..da90a821 100644 --- a/src/main/java/com/moing/backend/domain/board/presentation/constant/BoardResponseMessage.java +++ b/src/main/java/com/moing/backend/domain/board/presentation/constant/BoardResponseMessage.java @@ -9,6 +9,7 @@ public enum BoardResponseMessage { CREATE_BOARD_SUCCESS("게시글을 생성했습니다."), GET_BOARD_ALL_SUCCESS("게시글 목록을 모두 조회했습니다."), UPDATE_BOARD_SUCCESS("게시글을 수정했습니다."), - GET_BOARD_DETAIL_SUCCESS("게시글 상세 조회했습니다."); + GET_BOARD_DETAIL_SUCCESS("게시글 상세 조회했습니다."), + DELETE_BOARD_SUCCESS("게시글을 삭제했습니다"); private final String message; } diff --git a/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java b/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java index ed64387e..229f067c 100644 --- a/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java +++ b/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java @@ -5,6 +5,7 @@ import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; import com.moing.backend.domain.board.application.dto.response.*; import com.moing.backend.domain.board.application.service.CreateBoardUserCase; +import com.moing.backend.domain.board.application.service.DeleteBoardUserCase; import com.moing.backend.domain.board.application.service.GetBoardUserCase; import com.moing.backend.domain.board.application.service.UpdateBoardUserCase; import org.junit.jupiter.api.Test; @@ -32,9 +33,10 @@ public class BoardControllerTest extends CommonControllerTest { private CreateBoardUserCase createBoardUserCase; @MockBean private UpdateBoardUserCase updateBoardUserCase; - @MockBean private GetBoardUserCase getBoardUserCase; + @MockBean + private DeleteBoardUserCase deleteBoardUserCase; @Test public void create_board() throws Exception { @@ -144,6 +146,42 @@ public void update_board() throws Exception { ); } + @Test + public void delete_board() throws Exception { + + //given + Long teamId = 1L; + Long boardId = 1L; + + + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + delete("/api/{teamId}/board/{boardId}", 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("boardId").description("게시글 아이디") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description("게시글을 삭제했습니다") + ) + ) + ); + } + + @Test public void get_board_all() throws Exception { //given From 4fc7343b45fe637d1f915aa3c5858af40ca29b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Sat, 30 Sep 2023 18:51:38 +0900 Subject: [PATCH 07/30] =?UTF-8?q?feat=20:=20=EB=AF=B8=EC=85=98=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=EA=B2=8C=EC=8B=9C=EB=AC=BC=20=EC=A2=8B=EC=95=84?= =?UTF-8?q?=EC=9A=94,=20=EC=9D=B8=EC=A6=9D=20=EC=84=B1=EA=B3=B5=20?= =?UTF-8?q?=EC=9D=B8=EC=9B=90=20=EC=A1=B0=ED=9A=8C=20test=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/req/MissionArchiveHeartReq.java | 2 + .../MissionArchiveController.java | 19 ++- .../MissionArchiveControllerTest.java | 109 +++++++++++++++++- 3 files changed, 124 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/dto/req/MissionArchiveHeartReq.java b/src/main/java/com/moing/backend/domain/missionArchive/application/dto/req/MissionArchiveHeartReq.java index 48ec9458..db569206 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/dto/req/MissionArchiveHeartReq.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/dto/req/MissionArchiveHeartReq.java @@ -1,12 +1,14 @@ package com.moing.backend.domain.missionArchive.application.dto.req; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter @NoArgsConstructor @AllArgsConstructor +@Builder public class MissionArchiveHeartReq { private Long archiveId; private String heartStatus; diff --git a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java index 6ced5bf5..0d5e628a 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java @@ -36,7 +36,7 @@ public class MissionArchiveController { * 미션 인증 하기 * [POST] {teamId}/missions/{missionId}/archive * 작성자 : 정승연 - */ + **/ @PostMapping() public ResponseEntity> createArchive(@AuthenticationPrincipal User user, @@ -50,7 +50,7 @@ public ResponseEntity> createArchive(@Authent * 미션 재인증 하기 * [POST] {teamId}/missions/{missionId}/archive * 작성자 : 정승연 - */ + **/ @PutMapping() public ResponseEntity> updateArchive(@AuthenticationPrincipal User user, @@ -64,7 +64,7 @@ public ResponseEntity> updateArchive(@Authent * 미션 인증 조회 * [GET] {teamId}/missions/{missionId}/archive * 작성자 : 정승연 - */ + **/ @GetMapping() public ResponseEntity> getMyArchive(@AuthenticationPrincipal User user, @@ -77,7 +77,7 @@ public ResponseEntity> getMyArchive(@Authenti * 모임원 미션 인증 목록 조회 * [GET] {teamId}/missions/{missionId}/archive/others * 작성자 : 정승연 - */ + **/ @GetMapping("/others") public ResponseEntity>> getOtherPeopleArchives(@AuthenticationPrincipal User user, @PathVariable("teamId") Long teamId, @@ -85,7 +85,11 @@ public ResponseEntity>> getOtherPeopleArch return ResponseEntity.ok(SuccessResponse.create(READ_TEAM_ARCHIVE_SUCCESS.getMessage(), this.singleMissionArchiveReadUseCase.getPersonalArchive(user.getSocialId(),missionId))); } - + /** + * 인증 성공 인원 조회 + * [GET] {teamId}/m원issions/{missionId}/archive/status + * 작성자 : 정승연 + **/ @GetMapping("/status") public ResponseEntity> getMissionDoneStatus(@AuthenticationPrincipal User user, @@ -94,6 +98,11 @@ public ResponseEntity> getMissionDoneSt return ResponseEntity.ok(SuccessResponse.create(MISSION_ARCHIVE_PEOPLE_STATUS_SUCCESS.getMessage(), this.singleMissionArchiveReadUseCase.getMissionDoneStatus(missionId))); } + /** + * 미션 인증 게시물 좋아요 + * [GET] {teamId}/m원issions/{missionId}/archive/hearts + * 작성자 : 정승연 + **/ @PostMapping("/hearts") public ResponseEntity> pushHeart(@AuthenticationPrincipal User user, 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 c998c86b..5e35a46b 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 @@ -10,8 +10,11 @@ import com.moing.backend.domain.mission.application.service.MissionReadUseCase; import com.moing.backend.domain.mission.application.service.MissionUpdateUseCase; import com.moing.backend.domain.mission.presentation.MissionController; +import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveHeartReq; import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveReq; +import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveHeartRes; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; +import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveStatusRes; import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchive; import com.moing.backend.domain.missionArchive.application.service.MissionArchiveCreateUseCase; import com.moing.backend.domain.missionArchive.application.service.MissionArchiveHeartUseCase; @@ -31,7 +34,7 @@ import java.time.LocalDateTime; import java.util.List; -import static com.moing.backend.domain.missionArchive.domain.constant.MissionArchiveResponseMessage.READ_MY_ARCHIVE_SUCCESS; +import static com.moing.backend.domain.missionArchive.domain.constant.MissionArchiveResponseMessage.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; @@ -286,5 +289,109 @@ public class MissionArchiveControllerTest extends CommonControllerTest { } + @Test + public void 인증_성공_인원_조회() throws Exception { + //given + + MissionArchiveStatusRes output = MissionArchiveStatusRes.builder() + .total("8") + .done("3") + .build(); + + given(singleMissionArchiveReadUseCase.getMissionDoneStatus(any())).willReturn(output); + + Long teamId = 1L; + Long missionId = 1L; + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + get("/api/{teamId}/missions/{missionId}/archive/status",teamId,missionId) + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + + ); + + //then + actions + .andExpect(MockMvcResultMatchers.status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + pathParameters( + parameterWithName("teamId").description("팀 아이디"), + parameterWithName("missionId").description("미션 아이디") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description(MISSION_ARCHIVE_PEOPLE_STATUS_SUCCESS.getMessage()), + fieldWithPath("data.total").description("전체 미션 참여자"), + fieldWithPath("data.done").description("미션 인증 완료한 미션 참여자 ") + + ) + ) + ) + .andReturn(); + + } + @Test + public void 미션_인증물_좋아요() throws Exception { + //given + MissionArchiveHeartReq input = MissionArchiveHeartReq.builder() + .archiveId(1L) + .heartStatus("content[s3 Link / text / link]") + .build(); + + String body = objectMapper.writeValueAsString(input); + + MissionArchiveHeartRes output = MissionArchiveHeartRes.builder() + .archiveId(1L) + .heartStatus("content[s3 Link / text / link]") + .hearts(3) + .build(); + + given(missionArchiveHeartUseCase.pushHeart(any())).willReturn(output); + + Long teamId = 1L; + Long missionId = 1L; + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + post("/api/{teamId}/missions/{missionId}/archive/hearts", teamId, missionId) + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + .content(body) + ); + + //then + actions + .andExpect(MockMvcResultMatchers.status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + pathParameters( + parameterWithName("teamId").description("팀 아이디"), + parameterWithName("missionId").description("미션 아이디") + ), + requestFields( + fieldWithPath("archiveId").description("미션 인증 아이디"), + fieldWithPath("heartStatus").description("미션 인증물 좋아요 상태 [True]") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description(HEART_UPDATE_SUCCESS.getMessage()), + fieldWithPath("data.archiveId").description("미션 인증 아이디"), + fieldWithPath("data.heartStatus").description("미션 인증물 좋아요 상태 [True]"), + fieldWithPath("data.hearts").description("미션 인증물 좋아요 수") + + ) + ) + ) + .andReturn(); + } + + + } From e0968a337dfa0cc693ffd81d89318b8ece349879 Mon Sep 17 00:00:00 2001 From: Minsu Kim Date: Sat, 30 Sep 2023 21:59:52 +0900 Subject: [PATCH 08/30] =?UTF-8?q?feat:=20Board=20=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1,=20=EC=82=AD=EC=A0=9C=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/application/mapper/BoardMapper.java | 1 + .../domain/board/domain/entity/Board.java | 6 +- .../board/presentation/BoardController.java | 3 +- .../request/CreateBoardCommentRequest.java | 18 +++++ .../dto/response/CommentBlocks.java | 24 +++++++ .../response/CreateBoardCommentResponse.java | 14 ++++ .../dto/response/GetBoardCommentResponse.java | 16 +++++ .../mapper/BoardCommentMapper.java | 21 ++++++ .../service/CreateBoardCommentUserCase.java | 42 +++++++++++ .../service/DeleteBoardCommentUserCase.java | 41 +++++++++++ .../service/GetBoardCommentUserCase.java | 33 +++++++++ .../domain/{ => entity}/BoardComment.java | 15 +++- .../BoardCommentCustomRepository.java | 8 +++ .../BoardCommentCustomRepositoryImpl.java | 52 ++++++++++++++ .../repository/BoardCommentRepository.java | 11 +++ .../service/BoardCommentDeleteService.java | 16 +++++ .../service/BoardCommentGetService.java | 27 +++++++ .../service/BoardCommentSaveService.java | 17 +++++ .../exception/BoardCommentException.java | 11 +++ .../NotAuthByBoardCommentException.java | 11 +++ .../NotFoundByBoardCommentIdException.java | 11 +++ .../presentattion/BoardCommentController.java | 70 +++++++++++++++++++ .../constant/BoardCommentResponseMessage.java | 13 ++++ .../backend/global/response/ErrorCode.java | 8 ++- 24 files changed, 481 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/moing/backend/domain/boardComment/application/dto/request/CreateBoardCommentRequest.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CommentBlocks.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CreateBoardCommentResponse.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/application/dto/response/GetBoardCommentResponse.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/application/mapper/BoardCommentMapper.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java rename src/main/java/com/moing/backend/domain/boardComment/domain/{ => entity}/BoardComment.java (71%) create mode 100644 src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentCustomRepository.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentCustomRepositoryImpl.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentRepository.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentDeleteService.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentGetService.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentSaveService.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/exception/BoardCommentException.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/exception/NotAuthByBoardCommentException.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/exception/NotFoundByBoardCommentIdException.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/presentattion/BoardCommentController.java create mode 100644 src/main/java/com/moing/backend/domain/boardComment/presentattion/constant/BoardCommentResponseMessage.java diff --git a/src/main/java/com/moing/backend/domain/board/application/mapper/BoardMapper.java b/src/main/java/com/moing/backend/domain/board/application/mapper/BoardMapper.java index a32c8452..4dc06d79 100644 --- a/src/main/java/com/moing/backend/domain/board/application/mapper/BoardMapper.java +++ b/src/main/java/com/moing/backend/domain/board/application/mapper/BoardMapper.java @@ -27,6 +27,7 @@ public Board toBoard(Member member, TeamMember teamMember, Team team, CreateBoar .commentNum(0) .isLeader(isLeader) .boardReads(new ArrayList<>()) + .boardComments(new ArrayList<>()) .build(); board.updateTeamMember(teamMember); board.updateTeam(team); diff --git a/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java b/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java index cb73c2a7..829bfe53 100644 --- a/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java +++ b/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java @@ -1,6 +1,7 @@ package com.moing.backend.domain.board.domain.entity; import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; +import com.moing.backend.domain.boardComment.domain.entity.BoardComment; import com.moing.backend.domain.boardRead.domain.entity.BoardRead; import com.moing.backend.domain.team.domain.entity.Team; import com.moing.backend.domain.teamMember.domain.entity.TeamMember; @@ -12,9 +13,6 @@ import lombok.NoArgsConstructor; import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import java.util.ArrayList; import java.util.List; @@ -60,6 +58,8 @@ public class Board extends BaseTimeEntity { @OneToMany(mappedBy = "board", cascade = CascadeType.ALL) private List boardReads = new ArrayList<>(); + @OneToMany(mappedBy = "board", cascade = CascadeType.ALL) + private List boardComments = new ArrayList<>(); public void incrComNum() { this.commentNum++; 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 a25fdf9d..26443cca 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 @@ -10,7 +10,6 @@ import com.moing.backend.domain.board.application.service.DeleteBoardUserCase; import com.moing.backend.domain.board.application.service.GetBoardUserCase; import com.moing.backend.domain.board.application.service.UpdateBoardUserCase; -import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.global.config.security.dto.User; import com.moing.backend.global.response.SuccessResponse; import lombok.AllArgsConstructor; @@ -63,7 +62,7 @@ public ResponseEntity> updateBoard(@Authent * 작성자 : 김민수 */ @DeleteMapping("/{boardId}") - public ResponseEntity> deleteBoard(@AuthenticationPrincipal User user, + public ResponseEntity deleteBoard(@AuthenticationPrincipal User user, @PathVariable Long teamId, @PathVariable Long boardId) { this.deleteBoardUserCase.deleteBoard(user.getSocialId(), teamId, boardId); diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/dto/request/CreateBoardCommentRequest.java b/src/main/java/com/moing/backend/domain/boardComment/application/dto/request/CreateBoardCommentRequest.java new file mode 100644 index 00000000..06bd1a8b --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/application/dto/request/CreateBoardCommentRequest.java @@ -0,0 +1,18 @@ +package com.moing.backend.domain.boardComment.application.dto.request; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +@AllArgsConstructor +@Builder +@NoArgsConstructor +@Getter +public class CreateBoardCommentRequest { + @NotBlank(message = "content 을 입력해 주세요.") + private String content; +} + diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CommentBlocks.java b/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CommentBlocks.java new file mode 100644 index 00000000..37e40ed0 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CommentBlocks.java @@ -0,0 +1,24 @@ +package com.moing.backend.domain.boardComment.application.dto.response; + +import com.querydsl.core.annotations.QueryProjection; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +@AllArgsConstructor +public class CommentBlocks { + + private Long boardCommentId; + + private String content; + + private String writerNickName; + + private Boolean writerIsLeader; + + private String writerProfileImage; + + private Boolean isWriter; +} diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CreateBoardCommentResponse.java b/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CreateBoardCommentResponse.java new file mode 100644 index 00000000..8967920c --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/CreateBoardCommentResponse.java @@ -0,0 +1,14 @@ +package com.moing.backend.domain.boardComment.application.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@Builder +@NoArgsConstructor +@Getter +public class CreateBoardCommentResponse { + private Long boardCommentId; +} diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/GetBoardCommentResponse.java b/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/GetBoardCommentResponse.java new file mode 100644 index 00000000..94bbbe1d --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/application/dto/response/GetBoardCommentResponse.java @@ -0,0 +1,16 @@ +package com.moing.backend.domain.boardComment.application.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@AllArgsConstructor +@Builder +@NoArgsConstructor +@Getter +public class GetBoardCommentResponse { + private List commentBlocks; +} 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 new file mode 100644 index 00000000..03169f2d --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/application/mapper/BoardCommentMapper.java @@ -0,0 +1,21 @@ +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.boardComment.domain.entity.BoardComment; +import com.moing.backend.domain.teamMember.domain.entity.TeamMember; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class BoardCommentMapper { + public BoardComment toBoardComment(TeamMember teamMember, Board board, CreateBoardCommentRequest createBoardCommentRequest){ + BoardComment boardComment= BoardComment.builder() + .content(createBoardCommentRequest.getContent()) + .build(); + boardComment.updateBoard(board); + boardComment.updateTeamMember(teamMember); + return boardComment; + } +} diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java new file mode 100644 index 00000000..6a2cb5ed --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java @@ -0,0 +1,42 @@ +package com.moing.backend.domain.boardComment.application.service; + +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.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.member.domain.entity.Member; +import com.moing.backend.domain.member.domain.service.MemberGetService; +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 lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class CreateBoardCommentUserCase { + + private final MemberGetService memberGetService; + private final TeamGetService teamGetService; + private final BoardGetService boardGetService; + private final TeamMemberGetService teamMemberGetService; + private final BoardCommentSaveService boardCommentSaveService; + private final BoardCommentMapper boardCommentMapper; + + public CreateBoardCommentResponse createBoardComment(String socialId, Long teamId, Long boardId, CreateBoardCommentRequest createBoardCommentRequest) { + Member member = memberGetService.getMemberBySocialId(socialId); + Team team = teamGetService.getTeamByTeamId(teamId); + Board board = boardGetService.getBoard(boardId); + TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); + BoardComment boardComment = boardCommentSaveService.saveBoardComment(boardCommentMapper.toBoardComment(teamMember, board, createBoardCommentRequest)); + board.incrComNum(); + return new CreateBoardCommentResponse(boardComment.getBoardCommentId()); + } +} diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java new file mode 100644 index 00000000..b9aa1be9 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java @@ -0,0 +1,41 @@ +package com.moing.backend.domain.boardComment.application.service; + +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.board.domain.service.BoardGetService; +import com.moing.backend.domain.board.exception.NotAuthByBoardException; +import com.moing.backend.domain.boardComment.domain.entity.BoardComment; +import com.moing.backend.domain.boardComment.domain.service.BoardCommentDeleteService; +import com.moing.backend.domain.boardComment.domain.service.BoardCommentGetService; +import com.moing.backend.domain.boardComment.domain.service.BoardCommentSaveService; +import com.moing.backend.domain.boardComment.exception.NotAuthByBoardCommentException; +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.member.domain.service.MemberGetService; +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 lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class DeleteBoardCommentUserCase { + private final MemberGetService memberGetService; + private final TeamGetService teamGetService; + private final TeamMemberGetService teamMemberGetService; + private final BoardCommentGetService boardCommentGetService; + private final BoardCommentDeleteService boardCommentDeleteService; + + public void deleteBoardComment(String socialId, Long teamId, Long boardId, Long boardCommentId){ + Member member = memberGetService.getMemberBySocialId(socialId); + Team team = teamGetService.getTeamByTeamId(teamId); + TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); + BoardComment boardComment=boardCommentGetService.getBoardComment(boardCommentId); + if (teamMember == boardComment.getTeamMember()) { + boardCommentDeleteService.deleteBoardComment(boardComment); + } else throw new NotAuthByBoardCommentException(); + } +} diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java new file mode 100644 index 00000000..8763a033 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java @@ -0,0 +1,33 @@ +package com.moing.backend.domain.boardComment.application.service; + +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.boardComment.application.dto.response.GetBoardCommentResponse; +import com.moing.backend.domain.boardComment.domain.service.BoardCommentDeleteService; +import com.moing.backend.domain.boardComment.domain.service.BoardCommentGetService; +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.member.domain.service.MemberGetService; +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 lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class GetBoardCommentUserCase { + private final MemberGetService memberGetService; + private final TeamGetService teamGetService; + private final TeamMemberGetService teamMemberGetService; + private final BoardCommentGetService boardCommentGetService; + + public GetBoardCommentResponse getBoardCommentAll(String socialId, Long teamId, Long boardId){ + Member member = memberGetService.getMemberBySocialId(socialId); + Team team = teamGetService.getTeamByTeamId(teamId); + TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); + return boardCommentGetService.getBoardCommentAll(boardId, teamMember); + } +} diff --git a/src/main/java/com/moing/backend/domain/boardComment/domain/BoardComment.java b/src/main/java/com/moing/backend/domain/boardComment/domain/entity/BoardComment.java similarity index 71% rename from src/main/java/com/moing/backend/domain/boardComment/domain/BoardComment.java rename to src/main/java/com/moing/backend/domain/boardComment/domain/entity/BoardComment.java index e3b39428..35381e68 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/domain/BoardComment.java +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/entity/BoardComment.java @@ -1,4 +1,4 @@ -package com.moing.backend.domain.boardComment.domain; +package com.moing.backend.domain.boardComment.domain.entity; import com.moing.backend.domain.board.domain.entity.Board; import com.moing.backend.domain.teamMember.domain.entity.TeamMember; @@ -30,4 +30,17 @@ public class BoardComment extends BaseTimeEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "board_id") private Board board; + + /** + * 연관관계 매핑 + */ + public void updateBoard(Board board) { + this.board = board; + board.getBoardComments().add(this); + } + + public void updateTeamMember(TeamMember teamMember) { + this.teamMember = teamMember; + } + } 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 new file mode 100644 index 00000000..f5e48759 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentCustomRepository.java @@ -0,0 +1,8 @@ +package com.moing.backend.domain.boardComment.domain.repository; + +import com.moing.backend.domain.boardComment.application.dto.response.GetBoardCommentResponse; +import com.moing.backend.domain.teamMember.domain.entity.TeamMember; + +public interface BoardCommentCustomRepository { + GetBoardCommentResponse findBoardCommentAll(Long boardId, TeamMember teamMember); +} 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 new file mode 100644 index 00000000..178a26ea --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentCustomRepositoryImpl.java @@ -0,0 +1,52 @@ +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; +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.JPAExpressions; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import javax.persistence.EntityManager; +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{ + + private final JPAQueryFactory queryFactory; + + public BoardCommentCustomRepositoryImpl(EntityManager em) { + this.queryFactory = new JPAQueryFactory(em); + } + + + @Override + public GetBoardCommentResponse findBoardCommentAll(Long boardId, TeamMember teamMember) { + List commentBlocks = queryFactory + .select(Projections.constructor(CommentBlocks.class, + boardComment.boardCommentId, + boardComment.content, + boardComment.board.writerNickName, + boardComment.board.isLeader, + boardComment.board.writerProfileImage, + ExpressionUtils.as(JPAExpressions + .selectOne() + .from(QTeamMember.teamMember) + .where(QTeamMember.teamMember.eq(teamMember) + .and(QTeamMember.teamMember.eq(boardComment.teamMember))) + .exists(), "isWriter"))) + .from(boardComment) + .where(boardComment.board.boardId.eq(boardId)) + .orderBy(boardComment.createdDate.asc()) + .fetch(); + return new GetBoardCommentResponse(commentBlocks); + } +} 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 new file mode 100644 index 00000000..8ccec194 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/repository/BoardCommentRepository.java @@ -0,0 +1,11 @@ +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; + +import java.util.Optional; + +public interface BoardCommentRepository extends JpaRepository, BoardCommentCustomRepository { + Optional findBoardCommentByBoardCommentId(Long boardCommentId); +} 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 new file mode 100644 index 00000000..c3bd102f --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentDeleteService.java @@ -0,0 +1,16 @@ +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.global.annotation.DomainService; +import lombok.RequiredArgsConstructor; + +@DomainService +@RequiredArgsConstructor +public class BoardCommentDeleteService { + private final BoardCommentRepository boardCommentRepository; + + public void deleteBoardComment(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 new file mode 100644 index 00000000..005c10a4 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentGetService.java @@ -0,0 +1,27 @@ +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.teamMember.domain.entity.TeamMember; +import com.moing.backend.global.annotation.DomainService; +import lombok.RequiredArgsConstructor; + +import javax.transaction.Transactional; + +@DomainService +@Transactional +@RequiredArgsConstructor +public class BoardCommentGetService { + + private final BoardCommentRepository boardCommentRepository; + + public BoardComment getBoardComment(Long boardCommentId){ + return boardCommentRepository.findBoardCommentByBoardCommentId(boardCommentId).orElseThrow(()->new NotFoundByBoardCommentIdException()); + } + + public GetBoardCommentResponse getBoardCommentAll(Long boardId, TeamMember teamMember){ + return boardCommentRepository.findBoardCommentAll(boardId, teamMember); + } +} 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 new file mode 100644 index 00000000..48b634aa --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/service/BoardCommentSaveService.java @@ -0,0 +1,17 @@ +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.global.annotation.DomainService; +import lombok.RequiredArgsConstructor; + +@DomainService +@RequiredArgsConstructor +public class BoardCommentSaveService { + + private final BoardCommentRepository boardCommentRepository; + + public BoardComment saveBoardComment(BoardComment boardComment){ + return this.boardCommentRepository.save(boardComment); + } +} diff --git a/src/main/java/com/moing/backend/domain/boardComment/exception/BoardCommentException.java b/src/main/java/com/moing/backend/domain/boardComment/exception/BoardCommentException.java new file mode 100644 index 00000000..6a7778f6 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/exception/BoardCommentException.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.boardComment.exception; + +import com.moing.backend.global.exception.ApplicationException; +import com.moing.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public abstract class BoardCommentException extends ApplicationException { + protected BoardCommentException(ErrorCode errorCode, HttpStatus httpStatus) { + super(errorCode, httpStatus); + } +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/boardComment/exception/NotAuthByBoardCommentException.java b/src/main/java/com/moing/backend/domain/boardComment/exception/NotAuthByBoardCommentException.java new file mode 100644 index 00000000..4743776a --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/exception/NotAuthByBoardCommentException.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.boardComment.exception; + +import com.moing.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public class NotAuthByBoardCommentException extends BoardCommentException { + public NotAuthByBoardCommentException() { + super(ErrorCode.NOT_AUTH_BY_BOARD_COMMENT_ID_ERROR, + HttpStatus.NOT_FOUND); + } +} diff --git a/src/main/java/com/moing/backend/domain/boardComment/exception/NotFoundByBoardCommentIdException.java b/src/main/java/com/moing/backend/domain/boardComment/exception/NotFoundByBoardCommentIdException.java new file mode 100644 index 00000000..256aa3e1 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/exception/NotFoundByBoardCommentIdException.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.boardComment.exception; + +import com.moing.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public class NotFoundByBoardCommentIdException extends BoardCommentException { + public NotFoundByBoardCommentIdException() { + super(ErrorCode.NOT_FOUND_BY_BOARD_COMMENT_ID_ERROR, + HttpStatus.NOT_FOUND); + } +} 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 new file mode 100644 index 00000000..1ba471ca --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/presentattion/BoardCommentController.java @@ -0,0 +1,70 @@ +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.CreateBoardCommentUserCase; +import com.moing.backend.domain.boardComment.application.service.DeleteBoardCommentUserCase; +import com.moing.backend.domain.boardComment.application.service.GetBoardCommentUserCase; +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.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; + +@RestController +@AllArgsConstructor +@RequestMapping("/api/{teamId}/{boardId}/comment") +public class BoardCommentController { + + private final CreateBoardCommentUserCase createBoardCommentUserCase; + private final DeleteBoardCommentUserCase deleteBoardCommentUserCase; + private final GetBoardCommentUserCase getBoardCommentUserCase; + + /** + * 댓글 생성 + * [POST] api/{teamId}/{boardId}/comment + * 작성자 : 김민수 + */ + @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.createBoardCommentUserCase.createBoardComment(user.getSocialId(), teamId, boardId, createBoardCommentRequest))); + } + + /** + * 댓글 삭제 + * [DELETE] api/{teamId}/{boardId}/comment/{commentId} + * 작성자 : 김민수 + */ + @DeleteMapping("/{commentId}") + public ResponseEntity deleteBoardComment(@AuthenticationPrincipal User user, + @PathVariable Long teamId, + @PathVariable Long boardId, + @PathVariable Long commentId) { + this.deleteBoardCommentUserCase.deleteBoardComment(user.getSocialId(), teamId, boardId, commentId); + return ResponseEntity.ok(SuccessResponse.create(DELETE_BOARD_COMMENT_SUCCESS.getMessage())); + } + + + /** + * 댓글 전체 조회 + * [GET] api/{teamId}/{boardId}/comment + * 작성자 : 김민수 + */ + @GetMapping + public ResponseEntity> getBoardCommentAll(@AuthenticationPrincipal User user, + @PathVariable Long teamId, + @PathVariable Long boardId) { + return ResponseEntity.ok(SuccessResponse.create(GET_BOARD_ALL_SUCCESS.getMessage(), this.getBoardCommentUserCase.getBoardCommentAll(user.getSocialId(), teamId, boardId))); + } +} diff --git a/src/main/java/com/moing/backend/domain/boardComment/presentattion/constant/BoardCommentResponseMessage.java b/src/main/java/com/moing/backend/domain/boardComment/presentattion/constant/BoardCommentResponseMessage.java new file mode 100644 index 00000000..0cf29554 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardComment/presentattion/constant/BoardCommentResponseMessage.java @@ -0,0 +1,13 @@ +package com.moing.backend.domain.boardComment.presentattion.constant; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum BoardCommentResponseMessage { + CREATE_BOARD_COMMENT_SUCCESS("댓글을 생성했습니다."), + GET_BOARD_COMMENT_ALL_SUCCESS("댓글 목록을 모두 조회했습니다."), + DELETE_BOARD_COMMENT_SUCCESS("댓글을 삭제했습니다"); + private final String message; +} \ No newline at end of file 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 d81c948d..31aa29b6 100644 --- a/src/main/java/com/moing/backend/global/response/ErrorCode.java +++ b/src/main/java/com/moing/backend/global/response/ErrorCode.java @@ -30,8 +30,12 @@ public enum ErrorCode { NOT_AUTH_BY_TEAM_ERROR("T0002","권한이 없습니다."), //게시글 관련 에러 코드 - NOT_FOUND_BY_BOARD_ID_ERROR("B0001","해당 boardId인 팀이 존재하지 않습니다."), - NOT_AUTH_BY_BOARD_ID_ERROR("B0002","권한이 없습니다."); + NOT_FOUND_BY_BOARD_ID_ERROR("B0001","해당 boardId인 게시글이 존재하지 않습니다."), + NOT_AUTH_BY_BOARD_ID_ERROR("B0002","권한이 없습니다."), + + //게시글 댓글 관련 에러 코드 + NOT_FOUND_BY_BOARD_COMMENT_ID_ERROR("B0001","해당 boardCommentId인 댓글이 존재하지 않습니다."), + NOT_AUTH_BY_BOARD_COMMENT_ID_ERROR("B0002","권한이 없습니다."); private String errorCode; private String message; From 28c40ac14b7a40b233b2911185d4047693468bfd Mon Sep 17 00:00:00 2001 From: Minsu Kim Date: Sat, 30 Sep 2023 23:01:31 +0900 Subject: [PATCH 09/30] feat: Board Comment adoc --- src/docs/asciidoc/BoardComment_API.adoc | 17 ++ .../presentation/BoardControllerTest.java | 2 +- .../BoardCommentControllerTest.java | 186 ++++++++++++++++++ 3 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 src/docs/asciidoc/BoardComment_API.adoc create mode 100644 src/test/java/com/moing/backend/domain/boardComment/presentation/BoardCommentControllerTest.java diff --git a/src/docs/asciidoc/BoardComment_API.adoc b/src/docs/asciidoc/BoardComment_API.adoc new file mode 100644 index 00000000..e3cb904e --- /dev/null +++ b/src/docs/asciidoc/BoardComment_API.adoc @@ -0,0 +1,17 @@ +[[Board-Comment-API]] += Board Comment API + +[[Board-Comment-댓글-생성]] +=== Board Comment 댓글 생성 +operation::board-comment-controller-test/create_board_comment[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] +--- + +[[Board-Comment-게시글-삭제]] +=== Board Comment 게시글 삭제 +operation::board-comment-controller-test/delete_board_comment[snippets='http-request,path-parameters,request-fields,response-fields'] +--- + +[[Board-Comment-댓글-전체-조회]] +=== Board Comment 댓글 전체 조회 +operation::board-comment-controller-test/get_board_comment_all[snippets='http-request,path-parameters,http-response,response-fields'] +--- diff --git a/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java b/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java index 229f067c..1c76633c 100644 --- a/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java +++ b/src/test/java/com/moing/backend/domain/board/presentation/BoardControllerTest.java @@ -308,7 +308,7 @@ public void get_board_detail() throws Exception { ), responseFields( fieldWithPath("isSuccess").description("true"), - fieldWithPath("message").description("게시글 목록을 모두 조회했습니다."), + fieldWithPath("message").description("게시글 상세 조회했습니다."), fieldWithPath("data.boardId").description("게시글 아이디"), fieldWithPath("data.writerNickName").description("작성자 닉네임"), fieldWithPath("data.writerIsLeader").description("작성자 소모임장 여부"), 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 new file mode 100644 index 00000000..c3592fdb --- /dev/null +++ b/src/test/java/com/moing/backend/domain/boardComment/presentation/BoardCommentControllerTest.java @@ -0,0 +1,186 @@ +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.CreateBoardCommentUserCase; +import com.moing.backend.domain.boardComment.application.service.DeleteBoardCommentUserCase; +import com.moing.backend.domain.boardComment.application.service.GetBoardCommentUserCase; +import com.moing.backend.domain.boardComment.presentattion.BoardCommentController; +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(BoardCommentController.class) +public class BoardCommentControllerTest extends CommonControllerTest { + @MockBean + private CreateBoardCommentUserCase createBoardCommentUserCase; + @MockBean + private DeleteBoardCommentUserCase deleteBoardCommentUserCase; + @MockBean + private GetBoardCommentUserCase getBoardCommentUserCase; + + @Test + public void create_board_comment() throws Exception { + + //given + Long teamId = 1L; + Long boardId = 1L; + CreateBoardCommentRequest input = CreateBoardCommentRequest.builder() + .content("게시글 내용") + .build(); + + String body = objectMapper.writeValueAsString(input); + + CreateBoardCommentResponse output = CreateBoardCommentResponse.builder() + .boardCommentId(1L) + .build(); + + given(createBoardCommentUserCase.createBoardComment(any(), any(), any(), any())).willReturn(output); + + + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + post("/api/{teamId}/{boardId}/comment", teamId, boardId) + .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("boardId").description("게시글 아이디") + ), + requestFields( + fieldWithPath("content").description("댓글 내용") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description("댓글을 생성했습니다"), + fieldWithPath("data.boardCommentId").description("생성한 boardCommentId") + ) + ) + ); + } + + @Test + public void delete_board_comment() throws Exception { + + //given + Long teamId = 1L; + Long boardId = 1L; + Long boardCommentId = 1L; + + + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + delete("/api/{teamId}/{boardId}/comment/{boardCommentId}", teamId, boardId, boardCommentId) + .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("boardId").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() + .boardCommentId(1L) + .content("댓글 내용") + .writerIsLeader(true) + .writerNickName("작성자 닉네임") + .writerProfileImage("작성자 프로필 이미지") + .isWriter(true) + .build(); + + commentBlocks.add(commentBlock); + + GetBoardCommentResponse output = new GetBoardCommentResponse(commentBlocks); + + given(getBoardCommentUserCase.getBoardCommentAll(any(), any(), any())).willReturn(output); + + + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + get("/api/{teamId}/{boardId}/comment", 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("boardId").description("게시글 아이디") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description("댓글 목록을 모두 조회했습니다."), + fieldWithPath("data.commentBlocks[0].boardCommentId").description("댓글 아이디"), + fieldWithPath("data.commentBlocks[0].content").description("댓글 내용"), + fieldWithPath("data.commentBlocks[0].writerIsLeader").description("작성자 소모임장 여부"), + fieldWithPath("data.commentBlocks[0].writerNickName").description("작성자 닉네임"), + fieldWithPath("data.commentBlocks[0].writerProfileImage").description("작성자 프로필 이미지"), + fieldWithPath("data.commentBlocks[0].isWriter").description("댓글 작성자 여부") + ) + + ) + ); + } +} From 026b2e4edb9b3e25409e156d36f4588f3df8c391 Mon Sep 17 00:00:00 2001 From: Minsu Kim Date: Sat, 30 Sep 2023 23:04:46 +0900 Subject: [PATCH 10/30] feat: Board Comment adoc --- src/docs/asciidoc/BoardComment_API.adoc | 4 ++-- src/docs/asciidoc/api.adoc | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/docs/asciidoc/BoardComment_API.adoc b/src/docs/asciidoc/BoardComment_API.adoc index e3cb904e..7704d36b 100644 --- a/src/docs/asciidoc/BoardComment_API.adoc +++ b/src/docs/asciidoc/BoardComment_API.adoc @@ -6,8 +6,8 @@ operation::board-comment-controller-test/create_board_comment[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] --- -[[Board-Comment-게시글-삭제]] -=== Board Comment 게시글 삭제 +[[Board-Comment-댓글-삭제]] +=== Board Comment 댓글 삭제 operation::board-comment-controller-test/delete_board_comment[snippets='http-request,path-parameters,request-fields,response-fields'] --- diff --git a/src/docs/asciidoc/api.adoc b/src/docs/asciidoc/api.adoc index 31ab6d71..d8753290 100644 --- a/src/docs/asciidoc/api.adoc +++ b/src/docs/asciidoc/api.adoc @@ -22,4 +22,5 @@ include::MissionArchive-API.adoc[] include::Board-API.adoc[] +include::BoardComment_API.adoc[] From 6faadc4b3b8423565d7f52c8f59b78e1b7fbe6e8 Mon Sep 17 00:00:00 2001 From: Minsu Kim Date: Sat, 30 Sep 2023 23:18:24 +0900 Subject: [PATCH 11/30] =?UTF-8?q?fix:=20=EB=8C=93=EA=B8=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EC=88=AB=EC=9E=90=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/board/domain/service/BoardGetService.java | 2 +- .../application/service/DeleteBoardCommentUserCase.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/moing/backend/domain/board/domain/service/BoardGetService.java b/src/main/java/com/moing/backend/domain/board/domain/service/BoardGetService.java index f1c62e2e..e5db6029 100644 --- a/src/main/java/com/moing/backend/domain/board/domain/service/BoardGetService.java +++ b/src/main/java/com/moing/backend/domain/board/domain/service/BoardGetService.java @@ -19,7 +19,7 @@ public class BoardGetService { private final BoardRepository boardRepository; public Board getBoard(Long boardId){ - return boardRepository.findBoardByBoardId(boardId).orElseThrow(()->new NotFoundByBoardIdException()); + return boardRepository.findBoardByBoardId(boardId).orElseThrow(NotFoundByBoardIdException::new); } public GetAllBoardResponse getBoardAll(Long teamId, Long memberId){ diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java index b9aa1be9..0730f2b9 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java @@ -28,14 +28,17 @@ public class DeleteBoardCommentUserCase { private final TeamMemberGetService teamMemberGetService; private final BoardCommentGetService boardCommentGetService; private final BoardCommentDeleteService boardCommentDeleteService; + private final BoardGetService boardGetService; public void deleteBoardComment(String socialId, Long teamId, Long boardId, Long boardCommentId){ Member member = memberGetService.getMemberBySocialId(socialId); Team team = teamGetService.getTeamByTeamId(teamId); TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); + Board board=boardGetService.getBoard(boardId); BoardComment boardComment=boardCommentGetService.getBoardComment(boardCommentId); if (teamMember == boardComment.getTeamMember()) { boardCommentDeleteService.deleteBoardComment(boardComment); + board.decrComNum(); } else throw new NotAuthByBoardCommentException(); } } From 7977769876ee24bc50ee2a3f6bdff642f22c9564 Mon Sep 17 00:00:00 2001 From: Minsu Kim Date: Sun, 1 Oct 2023 00:52:47 +0900 Subject: [PATCH 12/30] =?UTF-8?q?feat:=20=EA=B3=B5=ED=86=B5=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/CreateBoardUserCase.java | 23 +++++++------ .../service/DeleteBoardUserCase.java | 27 ++++------------ .../application/service/GetBoardUserCase.java | 32 +++++++------------ .../service/UpdateBoardUserCase.java | 27 +++++----------- .../service/CreateBoardCommentUserCase.java | 24 ++++---------- .../service/DeleteBoardCommentUserCase.java | 27 ++++------------ .../service/GetBoardCommentUserCase.java | 21 ++++-------- .../service/CreateBoardReadUserCase.java | 26 +++++++++++++++ .../response/BaseBoardServiceResponse.java | 19 +++++++++++ .../global/response/BaseServiceResponse.java | 17 ++++++++++ .../global/response/SuccessResponse.java | 1 - .../backend/global/util/BaseBoardService.java | 32 +++++++++++++++++++ .../backend/global/util/BaseService.java | 28 ++++++++++++++++ 13 files changed, 178 insertions(+), 126 deletions(-) create mode 100644 src/main/java/com/moing/backend/domain/boardRead/application/service/CreateBoardReadUserCase.java create mode 100644 src/main/java/com/moing/backend/global/response/BaseBoardServiceResponse.java create mode 100644 src/main/java/com/moing/backend/global/response/BaseServiceResponse.java create mode 100644 src/main/java/com/moing/backend/global/util/BaseBoardService.java create mode 100644 src/main/java/com/moing/backend/global/util/BaseService.java diff --git a/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java index 25576f2d..84139ae8 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java @@ -6,6 +6,7 @@ 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; @@ -16,6 +17,8 @@ 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; import org.springframework.stereotype.Service; @@ -25,28 +28,24 @@ @Transactional @RequiredArgsConstructor public class CreateBoardUserCase { - private final MemberGetService memberGetService; + + private final BoardSaveService boardSaveService; private final CheckLeaderUserCase checkLeaderUserCase; - private final TeamGetService teamGetService; private final BoardMapper boardMapper; - private final TeamMemberGetService teamMemberGetService; - private final BoardReadMapper boardReadMapper; - private final BoardReadSaveService boardReadSaveService; + private final CreateBoardReadUserCase createBoardReadUserCase; + private final BaseService baseService; /** * 게시글 생성 */ public CreateBoardResponse createBoard(String socialId, Long teamId, CreateBoardRequest createBoardRequest) { - Member member=memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); - boolean isLeader = checkLeaderUserCase.isTeamLeader(member, team); - Board board=boardSaveService.saveBoard(boardMapper.toBoard(member, teamMember, team, createBoardRequest, isLeader)); + BaseServiceResponse data=baseService.getCommonData(socialId, teamId); + boolean isLeader = checkLeaderUserCase.isTeamLeader(data.getMember(), data.getTeam()); + Board board=boardSaveService.saveBoard(boardMapper.toBoard(data.getMember(), data.getTeamMember(), data.getTeam(), createBoardRequest, isLeader)); //읽음 처리 - BoardRead boardRead = boardReadMapper.toBoardRead(team, member); - boardReadSaveService.saveBoardRead(board, boardRead); + createBoardReadUserCase.createBoardRead(data.getTeam(), data.getMember(), board); return new CreateBoardResponse(board.getBoardId()); } } diff --git a/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java index 6a6cee91..387e17da 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java @@ -1,17 +1,9 @@ package com.moing.backend.domain.board.application.service; -import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; -import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse; -import com.moing.backend.domain.board.domain.entity.Board; import com.moing.backend.domain.board.domain.service.BoardDeleteService; -import com.moing.backend.domain.board.domain.service.BoardGetService; import com.moing.backend.domain.board.exception.NotAuthByBoardException; -import com.moing.backend.domain.member.domain.entity.Member; -import com.moing.backend.domain.member.domain.service.MemberGetService; -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.BaseBoardServiceResponse; +import com.moing.backend.global.util.BaseBoardService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -22,21 +14,16 @@ @RequiredArgsConstructor public class DeleteBoardUserCase { - private final MemberGetService memberGetService; - private final TeamGetService teamGetService; - private final BoardGetService boardGetService; - private final TeamMemberGetService teamMemberGetService; + private final BaseBoardService baseBoardService; private final BoardDeleteService boardDeleteService; + /** * 게시글 삭제 */ public void deleteBoard(String socialId, Long teamId, Long boardId){ - Member member=memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - Board board = boardGetService.getBoard(boardId); - TeamMember teamMember=teamMemberGetService.getTeamMember(member, team); - if (teamMember == board.getTeamMember()) { - boardDeleteService.deleteBoard(board); + BaseBoardServiceResponse data= baseBoardService.getCommonData(socialId,teamId,boardId); + if (data.getTeamMember() == data.getBoard().getTeamMember()) { + boardDeleteService.deleteBoard(data.getBoard()); } else throw new NotAuthByBoardException(); } } diff --git a/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java index c9116f63..56430dcc 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java @@ -3,17 +3,12 @@ import com.moing.backend.domain.board.application.dto.response.GetAllBoardResponse; import com.moing.backend.domain.board.application.dto.response.GetBoardDetailResponse; 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.BoardGetService; -import com.moing.backend.domain.boardRead.application.mapper.BoardReadMapper; -import com.moing.backend.domain.boardRead.domain.entity.BoardRead; -import com.moing.backend.domain.boardRead.domain.service.BoardReadSaveService; +import com.moing.backend.domain.boardRead.application.service.CreateBoardReadUserCase; import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.member.domain.service.MemberGetService; -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.BaseBoardServiceResponse; +import com.moing.backend.global.util.BaseBoardService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -24,27 +19,22 @@ @RequiredArgsConstructor public class GetBoardUserCase { + + private final BaseBoardService baseBoardService; + private final BoardMapper boardMapper; private final MemberGetService memberGetService; + private final CreateBoardReadUserCase createBoardReadUserCase; private final BoardGetService boardGetService; - private final BoardMapper boardMapper; - private final TeamGetService teamGetService; - private final BoardReadMapper boardReadMapper; - private final BoardReadSaveService boardReadSaveService; - private final TeamMemberGetService teamMemberGetService; + /** * 게시글 상세 조회 */ public GetBoardDetailResponse getBoardDetail(String socialId, Long teamId, Long boardId) { - Member member=memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - Board board = boardGetService.getBoard(boardId); - TeamMember teamMember=teamMemberGetService.getTeamMember(member, team); + BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); //읽음 처리 - BoardRead boardRead = boardReadMapper.toBoardRead(team, member); - boardReadSaveService.saveBoardRead(board, boardRead); - - return boardMapper.toBoardDetail(board, teamMember==board.getTeamMember()); + createBoardReadUserCase.createBoardRead(data.getTeam(), data.getMember(), data.getBoard()); + return boardMapper.toBoardDetail(data.getBoard(), data.getTeamMember() == data.getBoard().getTeamMember()); } /** diff --git a/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java index 2643da09..394b34e3 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java @@ -2,15 +2,9 @@ import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse; -import com.moing.backend.domain.board.domain.entity.Board; -import com.moing.backend.domain.board.domain.service.BoardGetService; import com.moing.backend.domain.board.exception.NotAuthByBoardException; -import com.moing.backend.domain.member.domain.entity.Member; -import com.moing.backend.domain.member.domain.service.MemberGetService; -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.BaseBoardServiceResponse; +import com.moing.backend.global.util.BaseBoardService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -20,22 +14,17 @@ @Transactional @RequiredArgsConstructor public class UpdateBoardUserCase { - private final MemberGetService memberGetService; - private final TeamGetService teamGetService; - private final BoardGetService boardGetService; - private final TeamMemberGetService teamMemberGetService; + + private final BaseBoardService baseBoardService; /** * 게시글 수정 */ public UpdateBoardResponse updateBoard(String socialId, Long teamId, Long boardId, UpdateBoardRequest updateBoardRequest){ - Member member=memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - Board board = boardGetService.getBoard(boardId); - TeamMember teamMember=teamMemberGetService.getTeamMember(member, team); - if (teamMember == board.getTeamMember()) { - board.updateBoard(updateBoardRequest); - return new UpdateBoardResponse(board.getBoardId()); + BaseBoardServiceResponse data= baseBoardService.getCommonData(socialId, teamId, boardId); + if (data.getTeamMember() == data.getBoard().getTeamMember()) { + data.getBoard().updateBoard(updateBoardRequest); + return new UpdateBoardResponse(data.getBoard().getBoardId()); } else throw new NotAuthByBoardException(); } } diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java index 6a2cb5ed..759fc5c4 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java @@ -1,18 +1,12 @@ package com.moing.backend.domain.boardComment.application.service; -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.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.member.domain.entity.Member; -import com.moing.backend.domain.member.domain.service.MemberGetService; -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.BaseBoardServiceResponse; +import com.moing.backend.global.util.BaseBoardService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -23,20 +17,14 @@ @Transactional public class CreateBoardCommentUserCase { - private final MemberGetService memberGetService; - private final TeamGetService teamGetService; - private final BoardGetService boardGetService; - private final TeamMemberGetService teamMemberGetService; private final BoardCommentSaveService boardCommentSaveService; private final BoardCommentMapper boardCommentMapper; + private final BaseBoardService baseBoardService; public CreateBoardCommentResponse createBoardComment(String socialId, Long teamId, Long boardId, CreateBoardCommentRequest createBoardCommentRequest) { - Member member = memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - Board board = boardGetService.getBoard(boardId); - TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); - BoardComment boardComment = boardCommentSaveService.saveBoardComment(boardCommentMapper.toBoardComment(teamMember, board, createBoardCommentRequest)); - board.incrComNum(); + BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); + BoardComment boardComment = boardCommentSaveService.saveBoardComment(boardCommentMapper.toBoardComment(data.getTeamMember(), data.getBoard(), createBoardCommentRequest)); + data.getBoard().incrComNum(); return new CreateBoardCommentResponse(boardComment.getBoardCommentId()); } } diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java index 0730f2b9..6201717f 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java @@ -1,19 +1,11 @@ package com.moing.backend.domain.boardComment.application.service; -import com.moing.backend.domain.board.domain.entity.Board; -import com.moing.backend.domain.board.domain.service.BoardGetService; -import com.moing.backend.domain.board.exception.NotAuthByBoardException; import com.moing.backend.domain.boardComment.domain.entity.BoardComment; import com.moing.backend.domain.boardComment.domain.service.BoardCommentDeleteService; import com.moing.backend.domain.boardComment.domain.service.BoardCommentGetService; -import com.moing.backend.domain.boardComment.domain.service.BoardCommentSaveService; import com.moing.backend.domain.boardComment.exception.NotAuthByBoardCommentException; -import com.moing.backend.domain.member.domain.entity.Member; -import com.moing.backend.domain.member.domain.service.MemberGetService; -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.BaseBoardServiceResponse; +import com.moing.backend.global.util.BaseBoardService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -23,22 +15,17 @@ @Transactional @RequiredArgsConstructor public class DeleteBoardCommentUserCase { - private final MemberGetService memberGetService; - private final TeamGetService teamGetService; - private final TeamMemberGetService teamMemberGetService; + private final BoardCommentGetService boardCommentGetService; private final BoardCommentDeleteService boardCommentDeleteService; - private final BoardGetService boardGetService; + private final BaseBoardService baseBoardService; public void deleteBoardComment(String socialId, Long teamId, Long boardId, Long boardCommentId){ - Member member = memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); - Board board=boardGetService.getBoard(boardId); + BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); BoardComment boardComment=boardCommentGetService.getBoardComment(boardCommentId); - if (teamMember == boardComment.getTeamMember()) { + if (data.getTeamMember() == boardComment.getTeamMember()) { boardCommentDeleteService.deleteBoardComment(boardComment); - board.decrComNum(); + data.getBoard().decrComNum(); } else throw new NotAuthByBoardCommentException(); } } diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java index 8763a033..df53c6e1 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java @@ -1,15 +1,9 @@ package com.moing.backend.domain.boardComment.application.service; -import com.moing.backend.domain.board.domain.entity.Board; import com.moing.backend.domain.boardComment.application.dto.response.GetBoardCommentResponse; -import com.moing.backend.domain.boardComment.domain.service.BoardCommentDeleteService; import com.moing.backend.domain.boardComment.domain.service.BoardCommentGetService; -import com.moing.backend.domain.member.domain.entity.Member; -import com.moing.backend.domain.member.domain.service.MemberGetService; -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.BaseBoardServiceResponse; +import com.moing.backend.global.util.BaseBoardService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -19,15 +13,12 @@ @Transactional @RequiredArgsConstructor public class GetBoardCommentUserCase { - private final MemberGetService memberGetService; - private final TeamGetService teamGetService; - private final TeamMemberGetService teamMemberGetService; + private final BoardCommentGetService boardCommentGetService; + private final BaseBoardService baseBoardService; public GetBoardCommentResponse getBoardCommentAll(String socialId, Long teamId, Long boardId){ - Member member = memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); - return boardCommentGetService.getBoardCommentAll(boardId, teamMember); + BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); + return boardCommentGetService.getBoardCommentAll(boardId, data.getTeamMember()); } } diff --git a/src/main/java/com/moing/backend/domain/boardRead/application/service/CreateBoardReadUserCase.java b/src/main/java/com/moing/backend/domain/boardRead/application/service/CreateBoardReadUserCase.java new file mode 100644 index 00000000..9c55a2fc --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardRead/application/service/CreateBoardReadUserCase.java @@ -0,0 +1,26 @@ +package com.moing.backend.domain.boardRead.application.service; + +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.boardRead.application.mapper.BoardReadMapper; +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.team.domain.entity.Team; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class CreateBoardReadUserCase { + + private final BoardReadMapper boardReadMapper; + private final BoardReadSaveService boardReadSaveService; + + public void createBoardRead(Team team, Member member, Board board){ + BoardRead boardRead = boardReadMapper.toBoardRead(team, member); + boardReadSaveService.saveBoardRead(board, boardRead); + } +} diff --git a/src/main/java/com/moing/backend/global/response/BaseBoardServiceResponse.java b/src/main/java/com/moing/backend/global/response/BaseBoardServiceResponse.java new file mode 100644 index 00000000..c65abe5b --- /dev/null +++ b/src/main/java/com/moing/backend/global/response/BaseBoardServiceResponse.java @@ -0,0 +1,19 @@ +package com.moing.backend.global.response; + +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.entity.TeamMember; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class BaseBoardServiceResponse { + private Member member; + private Team team; + private Board board; + private TeamMember teamMember; +} diff --git a/src/main/java/com/moing/backend/global/response/BaseServiceResponse.java b/src/main/java/com/moing/backend/global/response/BaseServiceResponse.java new file mode 100644 index 00000000..1258c29b --- /dev/null +++ b/src/main/java/com/moing/backend/global/response/BaseServiceResponse.java @@ -0,0 +1,17 @@ +package com.moing.backend.global.response; + +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.entity.TeamMember; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class BaseServiceResponse { + private Member member; + private Team team; + private TeamMember teamMember; +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/global/response/SuccessResponse.java b/src/main/java/com/moing/backend/global/response/SuccessResponse.java index 2b787b9d..20353aa0 100644 --- a/src/main/java/com/moing/backend/global/response/SuccessResponse.java +++ b/src/main/java/com/moing/backend/global/response/SuccessResponse.java @@ -8,7 +8,6 @@ @Getter @AllArgsConstructor @NoArgsConstructor - public class SuccessResponse { private Boolean isSuccess; private String message; diff --git a/src/main/java/com/moing/backend/global/util/BaseBoardService.java b/src/main/java/com/moing/backend/global/util/BaseBoardService.java new file mode 100644 index 00000000..c502c37c --- /dev/null +++ b/src/main/java/com/moing/backend/global/util/BaseBoardService.java @@ -0,0 +1,32 @@ +package com.moing.backend.global.util; + +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.board.domain.service.BoardGetService; +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.member.domain.service.MemberGetService; +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.BaseBoardServiceResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class BaseBoardService { + + private final MemberGetService memberGetService; + private final TeamGetService teamGetService; + private final BoardGetService boardGetService; + private final TeamMemberGetService teamMemberGetService; + + public BaseBoardServiceResponse getCommonData(String socialId, Long teamId, Long boardId) { + Member member = memberGetService.getMemberBySocialId(socialId); + Team team = teamGetService.getTeamByTeamId(teamId); + Board board = boardGetService.getBoard(boardId); + TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); + + return new BaseBoardServiceResponse(member, team, board, teamMember); + } +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/global/util/BaseService.java b/src/main/java/com/moing/backend/global/util/BaseService.java new file mode 100644 index 00000000..0926e321 --- /dev/null +++ b/src/main/java/com/moing/backend/global/util/BaseService.java @@ -0,0 +1,28 @@ +package com.moing.backend.global.util; + +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.member.domain.service.MemberGetService; +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.BaseServiceResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class BaseService { + + private final MemberGetService memberGetService; + private final TeamGetService teamGetService; + private final TeamMemberGetService teamMemberGetService; + + public BaseServiceResponse getCommonData(String socialId, Long teamId) { + Member member = memberGetService.getMemberBySocialId(socialId); + Team team = teamGetService.getTeamByTeamId(teamId); + TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); + + return new BaseServiceResponse(member, team, teamMember); + } +} From 78f9e42997f39c5972760ab702614cb9825fc1b0 Mon Sep 17 00:00:00 2001 From: Minsu Kim Date: Sun, 1 Oct 2023 00:52:47 +0900 Subject: [PATCH 13/30] =?UTF-8?q?feat:=20=EA=B3=B5=ED=86=B5=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/CreateBoardUserCase.java | 23 +++++++------ .../service/DeleteBoardUserCase.java | 27 ++++------------ .../application/service/GetBoardUserCase.java | 32 +++++++------------ .../service/UpdateBoardUserCase.java | 27 +++++----------- .../service/CreateBoardCommentUserCase.java | 24 ++++---------- .../service/DeleteBoardCommentUserCase.java | 27 ++++------------ .../service/GetBoardCommentUserCase.java | 21 ++++-------- .../service/CreateBoardReadUserCase.java | 26 +++++++++++++++ .../response/BaseBoardServiceResponse.java | 19 +++++++++++ .../global/response/BaseServiceResponse.java | 17 ++++++++++ .../global/response/SuccessResponse.java | 1 - .../backend/global/util/BaseBoardService.java | 32 +++++++++++++++++++ .../backend/global/util/BaseService.java | 28 ++++++++++++++++ 13 files changed, 178 insertions(+), 126 deletions(-) create mode 100644 src/main/java/com/moing/backend/domain/boardRead/application/service/CreateBoardReadUserCase.java create mode 100644 src/main/java/com/moing/backend/global/response/BaseBoardServiceResponse.java create mode 100644 src/main/java/com/moing/backend/global/response/BaseServiceResponse.java create mode 100644 src/main/java/com/moing/backend/global/util/BaseBoardService.java create mode 100644 src/main/java/com/moing/backend/global/util/BaseService.java diff --git a/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java index 25576f2d..84139ae8 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/CreateBoardUserCase.java @@ -6,6 +6,7 @@ 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; @@ -16,6 +17,8 @@ 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; import org.springframework.stereotype.Service; @@ -25,28 +28,24 @@ @Transactional @RequiredArgsConstructor public class CreateBoardUserCase { - private final MemberGetService memberGetService; + + private final BoardSaveService boardSaveService; private final CheckLeaderUserCase checkLeaderUserCase; - private final TeamGetService teamGetService; private final BoardMapper boardMapper; - private final TeamMemberGetService teamMemberGetService; - private final BoardReadMapper boardReadMapper; - private final BoardReadSaveService boardReadSaveService; + private final CreateBoardReadUserCase createBoardReadUserCase; + private final BaseService baseService; /** * 게시글 생성 */ public CreateBoardResponse createBoard(String socialId, Long teamId, CreateBoardRequest createBoardRequest) { - Member member=memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); - boolean isLeader = checkLeaderUserCase.isTeamLeader(member, team); - Board board=boardSaveService.saveBoard(boardMapper.toBoard(member, teamMember, team, createBoardRequest, isLeader)); + BaseServiceResponse data=baseService.getCommonData(socialId, teamId); + boolean isLeader = checkLeaderUserCase.isTeamLeader(data.getMember(), data.getTeam()); + Board board=boardSaveService.saveBoard(boardMapper.toBoard(data.getMember(), data.getTeamMember(), data.getTeam(), createBoardRequest, isLeader)); //읽음 처리 - BoardRead boardRead = boardReadMapper.toBoardRead(team, member); - boardReadSaveService.saveBoardRead(board, boardRead); + createBoardReadUserCase.createBoardRead(data.getTeam(), data.getMember(), board); return new CreateBoardResponse(board.getBoardId()); } } diff --git a/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java index 6a6cee91..387e17da 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/DeleteBoardUserCase.java @@ -1,17 +1,9 @@ package com.moing.backend.domain.board.application.service; -import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; -import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse; -import com.moing.backend.domain.board.domain.entity.Board; import com.moing.backend.domain.board.domain.service.BoardDeleteService; -import com.moing.backend.domain.board.domain.service.BoardGetService; import com.moing.backend.domain.board.exception.NotAuthByBoardException; -import com.moing.backend.domain.member.domain.entity.Member; -import com.moing.backend.domain.member.domain.service.MemberGetService; -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.BaseBoardServiceResponse; +import com.moing.backend.global.util.BaseBoardService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -22,21 +14,16 @@ @RequiredArgsConstructor public class DeleteBoardUserCase { - private final MemberGetService memberGetService; - private final TeamGetService teamGetService; - private final BoardGetService boardGetService; - private final TeamMemberGetService teamMemberGetService; + private final BaseBoardService baseBoardService; private final BoardDeleteService boardDeleteService; + /** * 게시글 삭제 */ public void deleteBoard(String socialId, Long teamId, Long boardId){ - Member member=memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - Board board = boardGetService.getBoard(boardId); - TeamMember teamMember=teamMemberGetService.getTeamMember(member, team); - if (teamMember == board.getTeamMember()) { - boardDeleteService.deleteBoard(board); + BaseBoardServiceResponse data= baseBoardService.getCommonData(socialId,teamId,boardId); + if (data.getTeamMember() == data.getBoard().getTeamMember()) { + boardDeleteService.deleteBoard(data.getBoard()); } else throw new NotAuthByBoardException(); } } diff --git a/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java index c9116f63..56430dcc 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/GetBoardUserCase.java @@ -3,17 +3,12 @@ import com.moing.backend.domain.board.application.dto.response.GetAllBoardResponse; import com.moing.backend.domain.board.application.dto.response.GetBoardDetailResponse; 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.BoardGetService; -import com.moing.backend.domain.boardRead.application.mapper.BoardReadMapper; -import com.moing.backend.domain.boardRead.domain.entity.BoardRead; -import com.moing.backend.domain.boardRead.domain.service.BoardReadSaveService; +import com.moing.backend.domain.boardRead.application.service.CreateBoardReadUserCase; import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.member.domain.service.MemberGetService; -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.BaseBoardServiceResponse; +import com.moing.backend.global.util.BaseBoardService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -24,27 +19,22 @@ @RequiredArgsConstructor public class GetBoardUserCase { + + private final BaseBoardService baseBoardService; + private final BoardMapper boardMapper; private final MemberGetService memberGetService; + private final CreateBoardReadUserCase createBoardReadUserCase; private final BoardGetService boardGetService; - private final BoardMapper boardMapper; - private final TeamGetService teamGetService; - private final BoardReadMapper boardReadMapper; - private final BoardReadSaveService boardReadSaveService; - private final TeamMemberGetService teamMemberGetService; + /** * 게시글 상세 조회 */ public GetBoardDetailResponse getBoardDetail(String socialId, Long teamId, Long boardId) { - Member member=memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - Board board = boardGetService.getBoard(boardId); - TeamMember teamMember=teamMemberGetService.getTeamMember(member, team); + BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); //읽음 처리 - BoardRead boardRead = boardReadMapper.toBoardRead(team, member); - boardReadSaveService.saveBoardRead(board, boardRead); - - return boardMapper.toBoardDetail(board, teamMember==board.getTeamMember()); + createBoardReadUserCase.createBoardRead(data.getTeam(), data.getMember(), data.getBoard()); + return boardMapper.toBoardDetail(data.getBoard(), data.getTeamMember() == data.getBoard().getTeamMember()); } /** diff --git a/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java b/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java index 2643da09..394b34e3 100644 --- a/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java +++ b/src/main/java/com/moing/backend/domain/board/application/service/UpdateBoardUserCase.java @@ -2,15 +2,9 @@ import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; import com.moing.backend.domain.board.application.dto.response.UpdateBoardResponse; -import com.moing.backend.domain.board.domain.entity.Board; -import com.moing.backend.domain.board.domain.service.BoardGetService; import com.moing.backend.domain.board.exception.NotAuthByBoardException; -import com.moing.backend.domain.member.domain.entity.Member; -import com.moing.backend.domain.member.domain.service.MemberGetService; -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.BaseBoardServiceResponse; +import com.moing.backend.global.util.BaseBoardService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -20,22 +14,17 @@ @Transactional @RequiredArgsConstructor public class UpdateBoardUserCase { - private final MemberGetService memberGetService; - private final TeamGetService teamGetService; - private final BoardGetService boardGetService; - private final TeamMemberGetService teamMemberGetService; + + private final BaseBoardService baseBoardService; /** * 게시글 수정 */ public UpdateBoardResponse updateBoard(String socialId, Long teamId, Long boardId, UpdateBoardRequest updateBoardRequest){ - Member member=memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - Board board = boardGetService.getBoard(boardId); - TeamMember teamMember=teamMemberGetService.getTeamMember(member, team); - if (teamMember == board.getTeamMember()) { - board.updateBoard(updateBoardRequest); - return new UpdateBoardResponse(board.getBoardId()); + BaseBoardServiceResponse data= baseBoardService.getCommonData(socialId, teamId, boardId); + if (data.getTeamMember() == data.getBoard().getTeamMember()) { + data.getBoard().updateBoard(updateBoardRequest); + return new UpdateBoardResponse(data.getBoard().getBoardId()); } else throw new NotAuthByBoardException(); } } diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java index 6a2cb5ed..759fc5c4 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/CreateBoardCommentUserCase.java @@ -1,18 +1,12 @@ package com.moing.backend.domain.boardComment.application.service; -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.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.member.domain.entity.Member; -import com.moing.backend.domain.member.domain.service.MemberGetService; -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.BaseBoardServiceResponse; +import com.moing.backend.global.util.BaseBoardService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -23,20 +17,14 @@ @Transactional public class CreateBoardCommentUserCase { - private final MemberGetService memberGetService; - private final TeamGetService teamGetService; - private final BoardGetService boardGetService; - private final TeamMemberGetService teamMemberGetService; private final BoardCommentSaveService boardCommentSaveService; private final BoardCommentMapper boardCommentMapper; + private final BaseBoardService baseBoardService; public CreateBoardCommentResponse createBoardComment(String socialId, Long teamId, Long boardId, CreateBoardCommentRequest createBoardCommentRequest) { - Member member = memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - Board board = boardGetService.getBoard(boardId); - TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); - BoardComment boardComment = boardCommentSaveService.saveBoardComment(boardCommentMapper.toBoardComment(teamMember, board, createBoardCommentRequest)); - board.incrComNum(); + BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); + BoardComment boardComment = boardCommentSaveService.saveBoardComment(boardCommentMapper.toBoardComment(data.getTeamMember(), data.getBoard(), createBoardCommentRequest)); + data.getBoard().incrComNum(); return new CreateBoardCommentResponse(boardComment.getBoardCommentId()); } } diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java index 0730f2b9..6201717f 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/DeleteBoardCommentUserCase.java @@ -1,19 +1,11 @@ package com.moing.backend.domain.boardComment.application.service; -import com.moing.backend.domain.board.domain.entity.Board; -import com.moing.backend.domain.board.domain.service.BoardGetService; -import com.moing.backend.domain.board.exception.NotAuthByBoardException; import com.moing.backend.domain.boardComment.domain.entity.BoardComment; import com.moing.backend.domain.boardComment.domain.service.BoardCommentDeleteService; import com.moing.backend.domain.boardComment.domain.service.BoardCommentGetService; -import com.moing.backend.domain.boardComment.domain.service.BoardCommentSaveService; import com.moing.backend.domain.boardComment.exception.NotAuthByBoardCommentException; -import com.moing.backend.domain.member.domain.entity.Member; -import com.moing.backend.domain.member.domain.service.MemberGetService; -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.BaseBoardServiceResponse; +import com.moing.backend.global.util.BaseBoardService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -23,22 +15,17 @@ @Transactional @RequiredArgsConstructor public class DeleteBoardCommentUserCase { - private final MemberGetService memberGetService; - private final TeamGetService teamGetService; - private final TeamMemberGetService teamMemberGetService; + private final BoardCommentGetService boardCommentGetService; private final BoardCommentDeleteService boardCommentDeleteService; - private final BoardGetService boardGetService; + private final BaseBoardService baseBoardService; public void deleteBoardComment(String socialId, Long teamId, Long boardId, Long boardCommentId){ - Member member = memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); - Board board=boardGetService.getBoard(boardId); + BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); BoardComment boardComment=boardCommentGetService.getBoardComment(boardCommentId); - if (teamMember == boardComment.getTeamMember()) { + if (data.getTeamMember() == boardComment.getTeamMember()) { boardCommentDeleteService.deleteBoardComment(boardComment); - board.decrComNum(); + data.getBoard().decrComNum(); } else throw new NotAuthByBoardCommentException(); } } diff --git a/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java b/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java index 8763a033..df53c6e1 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java +++ b/src/main/java/com/moing/backend/domain/boardComment/application/service/GetBoardCommentUserCase.java @@ -1,15 +1,9 @@ package com.moing.backend.domain.boardComment.application.service; -import com.moing.backend.domain.board.domain.entity.Board; import com.moing.backend.domain.boardComment.application.dto.response.GetBoardCommentResponse; -import com.moing.backend.domain.boardComment.domain.service.BoardCommentDeleteService; import com.moing.backend.domain.boardComment.domain.service.BoardCommentGetService; -import com.moing.backend.domain.member.domain.entity.Member; -import com.moing.backend.domain.member.domain.service.MemberGetService; -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.BaseBoardServiceResponse; +import com.moing.backend.global.util.BaseBoardService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -19,15 +13,12 @@ @Transactional @RequiredArgsConstructor public class GetBoardCommentUserCase { - private final MemberGetService memberGetService; - private final TeamGetService teamGetService; - private final TeamMemberGetService teamMemberGetService; + private final BoardCommentGetService boardCommentGetService; + private final BaseBoardService baseBoardService; public GetBoardCommentResponse getBoardCommentAll(String socialId, Long teamId, Long boardId){ - Member member = memberGetService.getMemberBySocialId(socialId); - Team team = teamGetService.getTeamByTeamId(teamId); - TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); - return boardCommentGetService.getBoardCommentAll(boardId, teamMember); + BaseBoardServiceResponse data = baseBoardService.getCommonData(socialId, teamId, boardId); + return boardCommentGetService.getBoardCommentAll(boardId, data.getTeamMember()); } } diff --git a/src/main/java/com/moing/backend/domain/boardRead/application/service/CreateBoardReadUserCase.java b/src/main/java/com/moing/backend/domain/boardRead/application/service/CreateBoardReadUserCase.java new file mode 100644 index 00000000..9c55a2fc --- /dev/null +++ b/src/main/java/com/moing/backend/domain/boardRead/application/service/CreateBoardReadUserCase.java @@ -0,0 +1,26 @@ +package com.moing.backend.domain.boardRead.application.service; + +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.boardRead.application.mapper.BoardReadMapper; +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.team.domain.entity.Team; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class CreateBoardReadUserCase { + + private final BoardReadMapper boardReadMapper; + private final BoardReadSaveService boardReadSaveService; + + public void createBoardRead(Team team, Member member, Board board){ + BoardRead boardRead = boardReadMapper.toBoardRead(team, member); + boardReadSaveService.saveBoardRead(board, boardRead); + } +} diff --git a/src/main/java/com/moing/backend/global/response/BaseBoardServiceResponse.java b/src/main/java/com/moing/backend/global/response/BaseBoardServiceResponse.java new file mode 100644 index 00000000..c65abe5b --- /dev/null +++ b/src/main/java/com/moing/backend/global/response/BaseBoardServiceResponse.java @@ -0,0 +1,19 @@ +package com.moing.backend.global.response; + +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.entity.TeamMember; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class BaseBoardServiceResponse { + private Member member; + private Team team; + private Board board; + private TeamMember teamMember; +} diff --git a/src/main/java/com/moing/backend/global/response/BaseServiceResponse.java b/src/main/java/com/moing/backend/global/response/BaseServiceResponse.java new file mode 100644 index 00000000..1258c29b --- /dev/null +++ b/src/main/java/com/moing/backend/global/response/BaseServiceResponse.java @@ -0,0 +1,17 @@ +package com.moing.backend.global.response; + +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.entity.TeamMember; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class BaseServiceResponse { + private Member member; + private Team team; + private TeamMember teamMember; +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/global/response/SuccessResponse.java b/src/main/java/com/moing/backend/global/response/SuccessResponse.java index 2b787b9d..20353aa0 100644 --- a/src/main/java/com/moing/backend/global/response/SuccessResponse.java +++ b/src/main/java/com/moing/backend/global/response/SuccessResponse.java @@ -8,7 +8,6 @@ @Getter @AllArgsConstructor @NoArgsConstructor - public class SuccessResponse { private Boolean isSuccess; private String message; diff --git a/src/main/java/com/moing/backend/global/util/BaseBoardService.java b/src/main/java/com/moing/backend/global/util/BaseBoardService.java new file mode 100644 index 00000000..c502c37c --- /dev/null +++ b/src/main/java/com/moing/backend/global/util/BaseBoardService.java @@ -0,0 +1,32 @@ +package com.moing.backend.global.util; + +import com.moing.backend.domain.board.domain.entity.Board; +import com.moing.backend.domain.board.domain.service.BoardGetService; +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.member.domain.service.MemberGetService; +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.BaseBoardServiceResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class BaseBoardService { + + private final MemberGetService memberGetService; + private final TeamGetService teamGetService; + private final BoardGetService boardGetService; + private final TeamMemberGetService teamMemberGetService; + + public BaseBoardServiceResponse getCommonData(String socialId, Long teamId, Long boardId) { + Member member = memberGetService.getMemberBySocialId(socialId); + Team team = teamGetService.getTeamByTeamId(teamId); + Board board = boardGetService.getBoard(boardId); + TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); + + return new BaseBoardServiceResponse(member, team, board, teamMember); + } +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/global/util/BaseService.java b/src/main/java/com/moing/backend/global/util/BaseService.java new file mode 100644 index 00000000..0926e321 --- /dev/null +++ b/src/main/java/com/moing/backend/global/util/BaseService.java @@ -0,0 +1,28 @@ +package com.moing.backend.global.util; + +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.member.domain.service.MemberGetService; +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.BaseServiceResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class BaseService { + + private final MemberGetService memberGetService; + private final TeamGetService teamGetService; + private final TeamMemberGetService teamMemberGetService; + + public BaseServiceResponse getCommonData(String socialId, Long teamId) { + Member member = memberGetService.getMemberBySocialId(socialId); + Team team = teamGetService.getTeamByTeamId(teamId); + TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); + + return new BaseServiceResponse(member, team, teamMember); + } +} From fc753dc9a00e01ab47f781683f1ee6263a09bba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Sun, 1 Oct 2023 11:20:40 +0900 Subject: [PATCH 14/30] =?UTF-8?q?feat=20:=20=EB=AF=B8=EC=85=98=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=EC=A2=8B=EC=95=84=EC=9A=94,=20=EB=AF=B8=EC=85=98?= =?UTF-8?q?=20=EC=9D=B8=EC=A6=9D=20=EC=9D=B8=EC=9B=90=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20API=20=EB=AC=B8=EC=84=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/MissionArchive-API.adoc | 12 ++++++++++++ src/docs/asciidoc/Overview.adoc | 12 ++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/docs/asciidoc/MissionArchive-API.adoc b/src/docs/asciidoc/MissionArchive-API.adoc index d082b9c8..dc148e22 100644 --- a/src/docs/asciidoc/MissionArchive-API.adoc +++ b/src/docs/asciidoc/MissionArchive-API.adoc @@ -27,3 +27,15 @@ operation::mission-archive-controller-test/모임원_미션_인증_조회[snippe --- +[[MissionArchive-인증성공인원조회]] +=== 인증 성공 인원 조회 ( n/n명 ) +operation::mission-archive-controller-test/인증_성공_인원_조회[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] + +--- + +[[MissionArchive-미션인증물좋아요]] +=== 미션 인증물 좋아요 +operation::mission-archive-controller-test/미션_인증물_좋아요[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] + +--- + diff --git a/src/docs/asciidoc/Overview.adoc b/src/docs/asciidoc/Overview.adoc index 2b9e0a24..5f488cc2 100644 --- a/src/docs/asciidoc/Overview.adoc +++ b/src/docs/asciidoc/Overview.adoc @@ -116,7 +116,15 @@ | 소모임장이 아님 | `M0002` -| API PATH에 missionId가 있으 때 -| missionId가 유요하지 않음 +| API PATH에 missionId가 있을 때 +| missionId가 유효하지 않음 +|=== + +=== MissionArchive ErrorCode +|=== +| ErrorCode | Scope | Description +| `MA0001` +| 미션 인증물 조회할 때 +| 미션 missionId 또는 teamId가 유효하지 않음 |=== From e4c4d61806f5ad042e99f0c869bc226d15332cbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Sun, 1 Oct 2023 11:56:53 +0900 Subject: [PATCH 15/30] =?UTF-8?q?=20feat=20:=20=ED=8C=80=EB=B3=84=20?= =?UTF-8?q?=EB=AF=B8=EC=85=98=20=EA=B0=9C=EC=88=98=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/MissionCustomRepository.java | 5 ++++ .../MissionCustomRepositoryImpl.java | 28 +++++++++++++++++++ .../domain/repository/MissionRepository.java | 2 +- .../domain/service/MissionQueryService.java | 4 +++ .../presentation/MissionController.java | 2 ++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java create mode 100644 src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java diff --git a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java new file mode 100644 index 00000000..9ab4a501 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java @@ -0,0 +1,5 @@ +package com.moing.backend.domain.mission.domain.repository; + +public interface MissionCustomRepository { + Long findMissionsCountByTeam(Long teamId); +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java new file mode 100644 index 00000000..53a7cd60 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java @@ -0,0 +1,28 @@ +package com.moing.backend.domain.mission.domain.repository; + +import com.moing.backend.domain.mission.domain.entity.Mission; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import javax.persistence.EntityManager; + +import static com.moing.backend.domain.mission.domain.entity.QMission.mission; + +public class MissionCustomRepositoryImpl implements MissionCustomRepository{ + + private final JPAQueryFactory queryFactory; + public MissionCustomRepositoryImpl(EntityManager em) { + this.queryFactory = new JPAQueryFactory(em); + } + + + @Override + public Long findMissionsCountByTeam(Long teamId) { + return queryFactory + .select(mission.count()) + .from(mission) + .where( + mission.team.teamId.eq(teamId) + ) + .fetchFirst(); + } +} diff --git a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionRepository.java b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionRepository.java index ec8b779d..5244df48 100644 --- a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionRepository.java +++ b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionRepository.java @@ -3,5 +3,5 @@ import com.moing.backend.domain.mission.domain.entity.Mission; import org.springframework.data.jpa.repository.JpaRepository; -public interface MissionRepository extends JpaRepository { +public interface MissionRepository extends JpaRepository,MissionCustomRepository { } diff --git a/src/main/java/com/moing/backend/domain/mission/domain/service/MissionQueryService.java b/src/main/java/com/moing/backend/domain/mission/domain/service/MissionQueryService.java index 1a591022..961be80e 100644 --- a/src/main/java/com/moing/backend/domain/mission/domain/service/MissionQueryService.java +++ b/src/main/java/com/moing/backend/domain/mission/domain/service/MissionQueryService.java @@ -17,4 +17,8 @@ public class MissionQueryService { public Mission findMissionById(Long missionId) { return missionRepository.findById(missionId).orElseThrow(NotFoundMissionException::new); } + + public Long findMissionsCountByTeam(Long teamId) { + return missionRepository.findMissionsCountByTeam(teamId); + } } diff --git a/src/main/java/com/moing/backend/domain/mission/presentation/MissionController.java b/src/main/java/com/moing/backend/domain/mission/presentation/MissionController.java index f458207b..d66ccf85 100644 --- a/src/main/java/com/moing/backend/domain/mission/presentation/MissionController.java +++ b/src/main/java/com/moing/backend/domain/mission/presentation/MissionController.java @@ -8,6 +8,7 @@ import com.moing.backend.domain.mission.application.service.MissionReadUseCase; import com.moing.backend.domain.mission.application.service.MissionUpdateUseCase; import com.moing.backend.domain.mission.domain.service.MissionDeleteService; +import com.moing.backend.domain.mission.domain.service.MissionQueryService; import com.moing.backend.global.config.security.dto.User; import com.moing.backend.global.response.SuccessResponse; import lombok.AllArgsConstructor; @@ -28,6 +29,7 @@ public class MissionController { private final MissionReadUseCase missionReadUseCase; private final MissionUpdateUseCase missionUpdateUseCase; private final MissionDeleteUseCase missionDeleteUseCase; + private final MissionQueryService missionQueryService; /** * 미션 조회 From e8d977fe4a2a1919d9d133cd49ccb6e945709c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:35:49 +0900 Subject: [PATCH 16/30] =?UTF-8?q?fix=20:=20=EC=86=8C=EB=AA=A8=EC=9E=84?= =?UTF-8?q?=EC=9E=A5=20=ED=99=95=EC=9D=B8=20=EB=A1=9C=EC=A7=81=20equals?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mission/application/service/MissionCreateUseCase.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/moing/backend/domain/mission/application/service/MissionCreateUseCase.java b/src/main/java/com/moing/backend/domain/mission/application/service/MissionCreateUseCase.java index d5343370..dd4756e7 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/service/MissionCreateUseCase.java +++ b/src/main/java/com/moing/backend/domain/mission/application/service/MissionCreateUseCase.java @@ -32,13 +32,12 @@ public MissionCreateRes createMission(String userSocialId, Long teamId, MissionR Member member = memberGetService.getMemberBySocialId(userSocialId); Team team = teamRepository.findById(teamId).orElseThrow(); - // 소모임장 확인 로직 추가 - if (member.getMemberId() == team.getLeaderId()) { + // 소모임 장 확인 + if (member.getMemberId().equals(team.getLeaderId())) { Mission mission = MissionMapper.mapToMission(missionReq, member, MissionStatus.ONGOING); // teamRepository 변경 예정 mission.setTeam(team); missionSaveService.save(mission); - return MissionMapper.mapToMissionCreateRes(mission); } else{ From 236c4fcd663361f3be807cdb03e9e2628a66476c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Mon, 2 Oct 2023 17:23:13 +0900 Subject: [PATCH 17/30] =?UTF-8?q?feat=20:=20=ED=95=9C=EB=B2=88=EB=AF=B8?= =?UTF-8?q?=EC=85=98,=20=EB=B0=98=EB=B3=B5=EB=AF=B8=EC=85=98=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=EA=B3=B5=EC=9C=A0=EB=A5=BC=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=EB=A6=AC=ED=84=B4=20=EA=B0=9D=EC=B2=B4=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20#23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/mapper/MissionArchiveMapper.java | 8 ++++++++ .../service/MissionArchiveCreateUseCase.java | 6 +++--- .../service/SingleMissionArchiveReadUseCase.java | 6 ++---- .../repository/MissionArchiveRepository.java | 2 +- .../presentation/MissionArchiveController.java | 2 +- .../MissionArchiveControllerTest.java | 14 +++++++------- 6 files changed, 22 insertions(+), 16 deletions(-) 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 f191145c..0815ceca 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 @@ -39,6 +39,14 @@ public static MissionArchiveRes mapToMissionArchiveRes(MissionArchive missionArc .build(); } + public static List mapToMissionArchiveResList(List missionArchiveList) { + List missionArchiveResList = new ArrayList<>(); + missionArchiveList.forEach( + missionArchive -> missionArchiveResList.add(MissionArchiveMapper.mapToMissionArchiveRes(missionArchive)) + ); + return missionArchiveResList; + } + public static PersonalArchive mapToPersonalArchive(MissionArchive missionArchive) { Member member = missionArchive.getMember(); diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java index e13eb48b..19115175 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java @@ -52,9 +52,9 @@ public MissionArchiveRes createArchive(String userSocialId, Long missionId, Miss // missionArchive 2개 이상일 때 예외처리 필요 MissionArchive missionArchive = missionArchiveSaveService.save(MissionArchiveMapper.mapToMissionArchive(missionReq, member, mission)); - if (isDoneSingleMission(mission)) { - missionArchiveScoreService.addScore(team); - } +// if (isDoneSingleMission(mission)) { +// missionArchiveScoreService.addScore(team); +// } return MissionArchiveMapper.mapToMissionArchiveRes(missionArchive); diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/SingleMissionArchiveReadUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/SingleMissionArchiveReadUseCase.java index 87204ea6..38c8b683 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/SingleMissionArchiveReadUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/SingleMissionArchiveReadUseCase.java @@ -34,13 +34,11 @@ public class SingleMissionArchiveReadUseCase { // 미션 인증 조회 - public MissionArchiveRes getMyArchive(String userSocialId, Long missionId) { - - List archiveRes = new ArrayList<>(); + public List getMyArchive(String userSocialId, Long missionId) { Member member = memberGetService.getMemberBySocialId(userSocialId); - return MissionArchiveMapper.mapToMissionArchiveRes(missionArchiveQueryService.findMyArchive(member.getMemberId(), missionId).get(0)); + return MissionArchiveMapper.mapToMissionArchiveResList(missionArchiveQueryService.findMyArchive(member.getMemberId(), missionId)); } // 모두의 미션 인증 목록 조회 diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveRepository.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveRepository.java index 10a90ee7..804a5b01 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveRepository.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveRepository.java @@ -16,7 +16,7 @@ public interface MissionArchiveRepository extends JpaRepository> findByMemberId(@Param("memberId") Long memberId); - @Query("select m from MissionArchive as m where m.mission.id = :missionId and m.member.memberId =:memberId") + @Query("select m from MissionArchive as m where m.mission.id = :missionId and m.member.memberId =:memberId order by m.createdDate") Optional> findArchivesByMissionIdAndMemberId(@Param("memberId") Long memberId, @Param("missionId")Long missionId); @Query("select m from MissionArchive as m where m.mission.id = :missionId and m.member.memberId =:memberId") diff --git a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java index 0d5e628a..bb446ce8 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java @@ -67,7 +67,7 @@ public ResponseEntity> updateArchive(@Authent **/ @GetMapping() - public ResponseEntity> getMyArchive(@AuthenticationPrincipal User user, + public ResponseEntity>> getMyArchive(@AuthenticationPrincipal User user, @PathVariable("teamId") Long teamId, @PathVariable("missionId") Long missionId) { return ResponseEntity.ok(SuccessResponse.create(READ_MY_ARCHIVE_SUCCESS.getMessage(), this.singleMissionArchiveReadUseCase.getMyArchive(user.getSocialId(), missionId))); 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 5e35a46b..10625b91 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 @@ -185,13 +185,13 @@ public class MissionArchiveControllerTest extends CommonControllerTest { public void 나의_미션_인증_조회() throws Exception { //given - MissionArchiveRes output = MissionArchiveRes.builder() + List output = Lists.newArrayList(MissionArchiveRes.builder() .archiveId(1L) .archive("content[s3 Link / text / link]") .createdDate("2023-09-03T21:32:33.888") .hearts(0) .status("COMPLETE/SKIP") - .build(); + .build()); given(singleMissionArchiveReadUseCase.getMyArchive(any(),any())).willReturn(output); @@ -220,11 +220,11 @@ public class MissionArchiveControllerTest extends CommonControllerTest { responseFields( fieldWithPath("isSuccess").description("true"), fieldWithPath("message").description(READ_MY_ARCHIVE_SUCCESS.getMessage()), - fieldWithPath("data.archiveId").description("미션 인증 아이디"), - fieldWithPath("data.archive").description("미션 인증물 [s3URL/text/링크]"), - fieldWithPath("data.createdDate").description("미션 제출 시각"), - fieldWithPath("data.hearts").description("미션 인증 좋아요 수"), - fieldWithPath("data.status").description("미션 인증 상태") + fieldWithPath("data[].archiveId").description("미션 인증 아이디"), + fieldWithPath("data[].archive").description("미션 인증물 [s3URL/text/링크]"), + fieldWithPath("data[].createdDate").description("미션 제출 시각"), + fieldWithPath("data[].hearts").description("미션 인증 좋아요 수"), + fieldWithPath("data[].status").description("미션 인증 상태") ) ) From 7abe1034d17e0754c46e1321e65a56c9dd1135f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Mon, 2 Oct 2023 17:50:34 +0900 Subject: [PATCH 18/30] =?UTF-8?q?feat=20:=20=EB=B0=98=EB=B3=B5=EB=AF=B8?= =?UTF-8?q?=EC=85=98=20-=20=EB=82=98=EC=9D=98=20=EC=9D=B8=EC=A6=9D=20?= =?UTF-8?q?=ED=98=84=ED=99=A9=20=EC=A1=B0=ED=9A=8C=20#23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RepeatMissionArchiveReadUseCase.java | 14 +++++++ .../MissionArchiveCustomRepository.java | 1 + .../MissionArchiveCustomRepositoryImpl.java | 14 +++++++ .../service/MissionArchiveQueryService.java | 3 ++ .../MissionArchiveController.java | 38 +++++++++++++------ 5 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java index 7690445a..6a58da93 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java @@ -5,10 +5,12 @@ import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.mission.domain.service.MissionQueryService; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; +import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveStatusRes; import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchive; import com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper; 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 lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -59,5 +61,17 @@ public List getArchive(String userSocialId, Long missionId) { return missionArchiveQueryService.findMyArchive(member.getMemberId(), missionId); } + public MissionArchiveStatusRes getMyMissionDoneStatus(String userSocialId,Long missionId) { + Member member = memberGetService.getMemberBySocialId(userSocialId); + Mission mission = missionQueryService.findMissionById(missionId); + Team team = mission.getTeam(); + + return MissionArchiveStatusRes.builder() + .total(String.valueOf(mission.getNumber())) + .done(missionArchiveQueryService.findMyDoneArchives(member.getMemberId(),missionId).toString()) + .build(); + + } + } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java index 19273667..365fe7f9 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java @@ -15,6 +15,7 @@ public interface MissionArchiveCustomRepository { Optional> findAllMissionArchivesByMemberId(Long memberId, Long teamId, MissionStatus missionStatus); Optional findDonePeopleByMissionId(Long missionId); + Optional findMyDoneCountByMissionId(Long missionId,Long memberId); diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java index 1c4bff6e..2c934479 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java @@ -105,5 +105,19 @@ public Optional findDonePeopleByMissionId(Long missionId) { ); } + @Override + public Optional findMyDoneCountByMissionId(Long missionId,Long memberId){ + return Optional.ofNullable(queryFactory + .select(missionArchive.count()) + .from(missionArchive) + .where( + missionArchive.mission.id.eq(missionId), + missionArchive.member.memberId.eq(memberId) + ) + .fetchFirst() + ); + } + + } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java index 9b3c968c..cded00d4 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java @@ -90,6 +90,9 @@ public List findMyAllMissionArchives(Long memberId, Long teamId, public Long findDoneArchives(Long missionId) { return missionArchiveRepository.findDonePeopleByMissionId(missionId).orElseThrow(NotFoundMissionArchiveException::new); } + public Long findMyDoneArchives(Long memberId,Long missionId) { + return missionArchiveRepository.findMyDoneCountByMissionId(missionId,memberId).orElseThrow(NotFoundMissionArchiveException::new); + } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java index bb446ce8..23b7829b 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java @@ -6,10 +6,7 @@ import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveHeartRes; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveStatusRes; import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchive; -import com.moing.backend.domain.missionArchive.application.service.MissionArchiveCreateUseCase; -import com.moing.backend.domain.missionArchive.application.service.MissionArchiveHeartUseCase; -import com.moing.backend.domain.missionArchive.application.service.MissionArchiveUpdateUseCase; -import com.moing.backend.domain.missionArchive.application.service.SingleMissionArchiveReadUseCase; +import com.moing.backend.domain.missionArchive.application.service.*; import com.moing.backend.global.config.security.dto.User; import com.moing.backend.global.response.SuccessResponse; import lombok.AllArgsConstructor; @@ -30,6 +27,7 @@ public class MissionArchiveController { private final MissionArchiveCreateUseCase missionArchiveCreateUseCase; private final MissionArchiveUpdateUseCase missionArchiveUpdateUseCase; private final SingleMissionArchiveReadUseCase singleMissionArchiveReadUseCase; + private final RepeatMissionArchiveReadUseCase repeatMissionArchiveReadUseCase; private final MissionArchiveHeartUseCase missionArchiveHeartUseCase; /** @@ -85,6 +83,20 @@ public ResponseEntity>> getOtherPeopleArch return ResponseEntity.ok(SuccessResponse.create(READ_TEAM_ARCHIVE_SUCCESS.getMessage(), this.singleMissionArchiveReadUseCase.getPersonalArchive(user.getSocialId(),missionId))); } + /** + * 미션 인증 게시물 좋아요 + * [GET] {teamId}/m원issions/{missionId}/archive/hearts + * 작성자 : 정승연 + **/ + + @PostMapping("/hearts") + public ResponseEntity> pushHeart(@AuthenticationPrincipal User user, + @PathVariable("teamId") Long teamId, + @PathVariable("missionId") Long missionId, + @RequestBody MissionArchiveHeartReq missionArchiveHeartReq) { + return ResponseEntity.ok(SuccessResponse.create(HEART_UPDATE_SUCCESS.getMessage(), this.missionArchiveHeartUseCase.pushHeart(missionArchiveHeartReq))); + } + /** * 인증 성공 인원 조회 * [GET] {teamId}/m원issions/{missionId}/archive/status @@ -98,20 +110,22 @@ public ResponseEntity> getMissionDoneSt return ResponseEntity.ok(SuccessResponse.create(MISSION_ARCHIVE_PEOPLE_STATUS_SUCCESS.getMessage(), this.singleMissionArchiveReadUseCase.getMissionDoneStatus(missionId))); } + + /** - * 미션 인증 게시물 좋아요 - * [GET] {teamId}/m원issions/{missionId}/archive/hearts + * 반복미션 - 나의 성공 횟수 조회 + * [GET] {teamId}/missions/{missionId}/archive/my-status * 작성자 : 정승연 **/ - @PostMapping("/hearts") - public ResponseEntity> pushHeart(@AuthenticationPrincipal User user, - @PathVariable("teamId") Long teamId, - @PathVariable("missionId") Long missionId, - @RequestBody MissionArchiveHeartReq missionArchiveHeartReq) { - return ResponseEntity.ok(SuccessResponse.create(HEART_UPDATE_SUCCESS.getMessage(), this.missionArchiveHeartUseCase.pushHeart(missionArchiveHeartReq))); + @GetMapping("/my-status") + public ResponseEntity> getMyMissionDoneStatus(@AuthenticationPrincipal User user, + @PathVariable("teamId") Long teamId, + @PathVariable("missionId") Long missionId) { + return ResponseEntity.ok(SuccessResponse.create(MISSION_ARCHIVE_PEOPLE_STATUS_SUCCESS.getMessage(), this.repeatMissionArchiveReadUseCase.getMyMissionDoneStatus(user.getSocialId(),missionId))); } + } \ No newline at end of file From 6d029c8cc1f6d1d87e4d5d9616d30253e6ff4dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Mon, 2 Oct 2023 19:36:46 +0900 Subject: [PATCH 19/30] =?UTF-8?q?feat=20:=20=EB=AF=B8=EC=85=98=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=ED=9A=8C=EC=B0=A8=20=EB=A6=AC=ED=84=B4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20#23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/res/MissionArchiveRes.java | 5 +- .../mapper/MissionArchiveMapper.java | 1 + .../service/MissionArchiveCreateUseCase.java | 35 ++++++++--- .../service/MissionArchiveUpdateUseCase.java | 18 +++++- .../RepeatMissionArchiveReadUseCase.java | 58 +++++++++---------- .../domain/entity/MissionArchive.java | 6 ++ .../service/MissionArchiveQueryService.java | 8 +-- .../NoMoreMissionArchiveException.java | 12 ++++ .../NotFoundMissionArchiveException.java | 2 +- .../backend/global/response/ErrorCode.java | 1 + 10 files changed, 96 insertions(+), 50 deletions(-) create mode 100644 src/main/java/com/moing/backend/domain/missionArchive/exception/NoMoreMissionArchiveException.java 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 a9e8d5b1..d025cb70 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 @@ -13,11 +13,10 @@ public class MissionArchiveRes { private Long archiveId; private String archive; - private String createdDate; - private int hearts; - private String status; + private Long count; + } 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 0815ceca..87f411f1 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 @@ -36,6 +36,7 @@ public static MissionArchiveRes mapToMissionArchiveRes(MissionArchive missionArc .createdDate(missionArchive.getCreatedDate().toString()) .hearts(missionArchive.getHearts()) .status(missionArchive.getStatus().name()) + .count(missionArchive.getCount()) .build(); } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java index 19115175..6f09380b 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java @@ -6,6 +6,7 @@ import com.moing.backend.domain.mission.application.dto.req.MissionReq; import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; +import com.moing.backend.domain.mission.domain.entity.constant.MissionType; import com.moing.backend.domain.mission.domain.entity.constant.MissionWay; import com.moing.backend.domain.mission.domain.service.MissionDeleteService; import com.moing.backend.domain.mission.domain.service.MissionQueryService; @@ -17,6 +18,7 @@ import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveDeleteService; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveSaveService; +import com.moing.backend.domain.missionArchive.exception.NoMoreMissionArchiveException; import com.moing.backend.domain.team.domain.entity.Team; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -46,24 +48,39 @@ public class MissionArchiveCreateUseCase { public MissionArchiveRes createArchive(String userSocialId, Long missionId, MissionArchiveReq missionReq) { Member member = memberGetService.getMemberBySocialId(userSocialId); + Long memberId = member.getMemberId(); + Mission mission = missionQueryService.findMissionById(missionId); Team team = mission.getTeam(); - // missionArchive 2개 이상일 때 예외처리 필요 - MissionArchive missionArchive = missionArchiveSaveService.save(MissionArchiveMapper.mapToMissionArchive(missionReq, member, mission)); + MissionArchive newArchive = MissionArchiveMapper.mapToMissionArchive(missionReq, member, mission); -// if (isDoneSingleMission(mission)) { -// missionArchiveScoreService.addScore(team); -// } + if (isDoneMission(memberId,mission)) { + throw new NoMoreMissionArchiveException(); + } - return MissionArchiveMapper.mapToMissionArchiveRes(missionArchive); + if (mission.getType().equals(MissionType.ONCE)) { + // missionArchive 2개 이상일 때 예외처리 +// missionArchiveScoreService.addScore(team); + newArchive.updateCount(1L); + } + else { + newArchive.updateCount(missionArchiveQueryService.findMyDoneArchives(memberId, missionId)+1); + } + return MissionArchiveMapper.mapToMissionArchiveRes(missionArchiveSaveService.save(newArchive)); } - // 모든 모임원이 단일 미션을 완료하였는지 - public Boolean isDoneSingleMission(Mission mission) { + // 이 미션을 완료 했는지 + public Boolean isDoneMission(Long memberId,Mission mission) { + return missionArchiveQueryService.findMyDoneArchives(memberId, mission.getId()) >= mission.getNumber(); + } + + // 이 미션을 완료 했는지 + public Boolean isEndMission(Member member,Mission mission) { Team team = mission.getTeam(); - if (mission.getMissionArchiveList().size() == team.getLeaderId()-1) { + + if (mission.getMissionArchiveList().size() == team.getNumOfMember()-1) { mission.setStatus(MissionStatus.END); return true; } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveUpdateUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveUpdateUseCase.java index de8fa6ae..8c670092 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveUpdateUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveUpdateUseCase.java @@ -5,6 +5,7 @@ import com.moing.backend.domain.member.domain.service.MemberGetService; import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; +import com.moing.backend.domain.mission.domain.entity.constant.MissionType; import com.moing.backend.domain.mission.domain.entity.constant.MissionWay; import com.moing.backend.domain.mission.domain.service.MissionQueryService; import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveReq; @@ -50,11 +51,22 @@ public MissionArchiveRes updateArchive(String userSocialId, Long missionId, Miss } - MissionArchive missionArchive = missionArchiveQueryService.findMyArchive(member.getMemberId(), missionId).get(0); + MissionArchive updateArchive = missionArchiveQueryService.findMyArchive(member.getMemberId(), missionId).get(0); - missionArchive.updateArchive(missionReq); + if (mission.getType().equals(MissionType.ONCE)) { + // missionArchive 2개 이상일 때 예외처리 필요 +// if (isDoneSingleMission(mission)) { +// missionArchiveScoreService.addScore(team); +// } + updateArchive.updateCount(1L); + } + else{ + updateArchive.updateCount(missionArchiveQueryService.findMyDoneArchives(member.getMemberId(), missionId)+1); + } + + updateArchive.updateArchive(missionReq); + return MissionArchiveMapper.mapToMissionArchiveRes(missionArchiveSaveService.save(updateArchive)); - return MissionArchiveMapper.mapToMissionArchiveRes(missionArchive); } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java index 6a58da93..e0f53ca0 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java @@ -31,35 +31,35 @@ public class RepeatMissionArchiveReadUseCase { private final MissionArchiveQueryService missionArchiveQueryService; - // 나의 인증 목록 - public List getMyArchive(String userSocialId, Long missionId) { - List myArchives = getArchive(userSocialId, missionId); - - List archiveRes = new ArrayList<>(); - myArchives.forEach(myArchive -> archiveRes.add(MissionArchiveMapper.mapToMissionArchiveRes(myArchive))); - - return archiveRes; - } - - // 팀원들 인증 목록 - public List getPersonalArchive(String userSocialId, Long missionId) { - Mission mission = missionQueryService.findMissionById(missionId); - - List done = new ArrayList<>(); - - mission.getMissionArchiveList() - .forEach(missionArchive1 -> done.add(mapToPersonalArchive(missionArchive1))); - - return done; - } - - // memberId, missionId로 archive 꺼내기 - public List getArchive(String userSocialId, Long missionId) { - Member member = memberGetService.getMemberBySocialId(userSocialId); - Mission mission = missionQueryService.findMissionById(missionId); - - return missionArchiveQueryService.findMyArchive(member.getMemberId(), missionId); - } +// // 나의 인증 목록 +// public List getMyArchive(String userSocialId, Long missionId) { +// List myArchives = getArchive(userSocialId, missionId); +// +// List archiveRes = new ArrayList<>(); +// myArchives.forEach(myArchive -> archiveRes.add(MissionArchiveMapper.mapToMissionArchiveRes(myArchive))); +// +// return archiveRes; +// } +// +// // 팀원들 인증 목록 +// public List getPersonalArchive(String userSocialId, Long missionId) { +// Mission mission = missionQueryService.findMissionById(missionId); +// +// List done = new ArrayList<>(); +// +// mission.getMissionArchiveList() +// .forEach(missionArchive1 -> done.add(mapToPersonalArchive(missionArchive1))); +// +// return done; +// } +// +// // memberId, missionId로 archive 꺼내기 +// public List getArchive(String userSocialId, Long missionId) { +// Member member = memberGetService.getMemberBySocialId(userSocialId); +// Mission mission = missionQueryService.findMissionById(missionId); +// +// return missionArchiveQueryService.findMyArchive(member.getMemberId(), missionId); +// } public MissionArchiveStatusRes getMyMissionDoneStatus(String userSocialId,Long missionId) { Member member = memberGetService.getMemberBySocialId(userSocialId); 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 add5fd97..eae88c76 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 @@ -41,6 +41,8 @@ public class MissionArchive extends BaseTimeEntity { // 1회 미션을 저장 private int hearts; + private Long count; + public void updateArchive(MissionArchiveReq missionArchiveReq) { this.archive = missionArchiveReq.getArchive(); @@ -53,5 +55,9 @@ public int updateHearts(Boolean status) { return this.hearts -= 1; } + public void updateCount(Long count) { + this.count = count; + } + } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java index cded00d4..2bcb61fa 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java @@ -13,10 +13,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.transaction.annotation.Transactional; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; +import java.util.*; import static com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus.*; import static com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus.INCOMPLETE; @@ -40,7 +37,8 @@ public List findMyArchive(Long memberId, Long missionId) { Optional> optional = missionArchiveRepository.findArchivesByMissionIdAndMemberId(memberId, missionId); if (optional.isPresent() && optional.get().size() == 0) { - throw new NotFoundMissionArchiveException(); + return new ArrayList<>(); +// throw new NotFoundMissionArchiveException(); } else { return optional.get(); } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/exception/NoMoreMissionArchiveException.java b/src/main/java/com/moing/backend/domain/missionArchive/exception/NoMoreMissionArchiveException.java new file mode 100644 index 00000000..cd35fc03 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionArchive/exception/NoMoreMissionArchiveException.java @@ -0,0 +1,12 @@ +package com.moing.backend.domain.missionArchive.exception; + +import com.moing.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public class NoMoreMissionArchiveException extends MissionArchiveException { + + public NoMoreMissionArchiveException() { + super(ErrorCode.NO_MORE_ARCHIVE_ERROR, + HttpStatus.NOT_FOUND); + } +} diff --git a/src/main/java/com/moing/backend/domain/missionArchive/exception/NotFoundMissionArchiveException.java b/src/main/java/com/moing/backend/domain/missionArchive/exception/NotFoundMissionArchiveException.java index db258781..521bb472 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/exception/NotFoundMissionArchiveException.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/exception/NotFoundMissionArchiveException.java @@ -6,7 +6,7 @@ public class NotFoundMissionArchiveException extends MissionArchiveException { public NotFoundMissionArchiveException() { - super(ErrorCode.NOT_FOUND_MISSION, + super(ErrorCode.NOT_FOUND_MISSION_ARCHIVE, HttpStatus.NOT_FOUND); } } 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 31aa29b6..90feb2f4 100644 --- a/src/main/java/com/moing/backend/global/response/ErrorCode.java +++ b/src/main/java/com/moing/backend/global/response/ErrorCode.java @@ -24,6 +24,7 @@ public enum ErrorCode { NO_ACCESS_CREATE_MISSION("M0001", "소모임장만 미션을 생성할 수 있습니다."), NOT_FOUND_MISSION("M0002", "미션을 찾을 수 없습니다."), NOT_FOUND_MISSION_ARCHIVE("MA0001", "아직 미션을 제출하지 않았습니다."), + NO_MORE_ARCHIVE_ERROR("MA0001", "지정한 횟수 이상 미션을 인증할 수 없습니다."), //팀 관련 에러 코드 NOT_FOUND_BY_TEAM_ID_ERROR("T0001", "해당 teamId인 팀이 존재하지 않습니다."), From 2ec6854d1a98e390b4df695efe22b6808e9eb2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Mon, 2 Oct 2023 19:47:29 +0900 Subject: [PATCH 20/30] =?UTF-8?q?fix=20:=20PersonalArchive=20->=20Personal?= =?UTF-8?q?ArchiveRes=20,=20=EB=AA=A8=EC=9E=84=EC=9B=90=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=ED=98=84=ED=99=A9=EC=97=90=20=ED=9A=8C=EC=B0=A8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20#23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rsonalArchive.java => PersonalArchiveRes.java} | 3 ++- .../application/mapper/MissionArchiveMapper.java | 13 ++++++------- .../service/MissionArchiveCreateUseCase.java | 10 ---------- .../service/RepeatMissionArchiveReadUseCase.java | 8 -------- .../service/SingleMissionArchiveReadUseCase.java | 9 +++------ .../presentation/MissionArchiveController.java | 8 ++++---- .../MissionArchiveControllerTest.java | 15 ++------------- 7 files changed, 17 insertions(+), 49 deletions(-) rename src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/{PersonalArchive.java => PersonalArchiveRes.java} (86%) diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/PersonalArchive.java b/src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/PersonalArchiveRes.java similarity index 86% rename from src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/PersonalArchive.java rename to src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/PersonalArchiveRes.java index a534a19e..82d8146d 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/PersonalArchive.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/dto/res/PersonalArchiveRes.java @@ -7,7 +7,7 @@ @Getter @Setter @Builder -public class PersonalArchive { +public class PersonalArchiveRes { private Long archiveId; private String nickname; @@ -19,5 +19,6 @@ public class PersonalArchive { private int hearts; private String status; + private Long count; } 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 87f411f1..0eeec9df 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 @@ -4,14 +4,12 @@ import com.moing.backend.domain.mission.application.dto.res.FinishMissionBoardRes; import com.moing.backend.domain.mission.application.dto.res.SingleMissionBoardRes; 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.missionArchive.application.dto.res.MissionArchiveHeartRes; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; -import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchive; +import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchiveRes; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; -import com.moing.backend.domain.team.domain.entity.Team; import com.moing.backend.global.annotation.Mapper; import java.util.ArrayList; @@ -49,9 +47,9 @@ public static List mapToMissionArchiveResList(List mapToPersonalArchiveList(List missionArchiveList) { - List personalArchiveList = new ArrayList<>(); + public static List mapToPersonalArchiveList(List missionArchiveList) { + List personalArchiveList = new ArrayList<>(); missionArchiveList.forEach( missionArchive -> personalArchiveList.add(MissionArchiveMapper.mapToPersonalArchive(missionArchive)) ); diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java index 6f09380b..5835d28e 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java @@ -1,18 +1,13 @@ package com.moing.backend.domain.missionArchive.application.service; -import com.moing.backend.domain.infra.image.application.service.IssuePresignedUrlUseCase; import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.member.domain.service.MemberGetService; -import com.moing.backend.domain.mission.application.dto.req.MissionReq; import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; import com.moing.backend.domain.mission.domain.entity.constant.MissionType; -import com.moing.backend.domain.mission.domain.entity.constant.MissionWay; -import com.moing.backend.domain.mission.domain.service.MissionDeleteService; import com.moing.backend.domain.mission.domain.service.MissionQueryService; import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveReq; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; -import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchive; import com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveDeleteService; @@ -24,11 +19,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.List; - -import static com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper.mapToPersonalArchive; - @Service @Transactional @RequiredArgsConstructor diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java index e0f53ca0..ff971211 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java @@ -4,21 +4,13 @@ import com.moing.backend.domain.member.domain.service.MemberGetService; import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.mission.domain.service.MissionQueryService; -import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveStatusRes; -import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchive; -import com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper; -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 lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import javax.transaction.Transactional; -import java.util.ArrayList; -import java.util.List; - -import static com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper.mapToPersonalArchive; @Service @Transactional diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/SingleMissionArchiveReadUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/SingleMissionArchiveReadUseCase.java index 38c8b683..95e15e1b 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/SingleMissionArchiveReadUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/SingleMissionArchiveReadUseCase.java @@ -6,9 +6,8 @@ import com.moing.backend.domain.mission.domain.service.MissionQueryService; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveStatusRes; -import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchive; +import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchiveRes; import com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper; -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.repository.TeamRepository; @@ -19,8 +18,6 @@ import java.util.ArrayList; import java.util.List; -import static com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper.mapToPersonalArchive; - @Service @Transactional @RequiredArgsConstructor @@ -42,9 +39,9 @@ public List getMyArchive(String userSocialId, Long missionId) } // 모두의 미션 인증 목록 조회 - public List getPersonalArchive(String userSocialId,Long missionId) { + public List getPersonalArchive(String userSocialId, Long missionId) { - List personalArchives = new ArrayList<>(); + List personalArchives = new ArrayList<>(); Member member = memberGetService.getMemberBySocialId(userSocialId); return MissionArchiveMapper.mapToPersonalArchiveList(missionArchiveQueryService.findOthersArchive(member.getMemberId(), missionId)); diff --git a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java index 23b7829b..f331662d 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionArchiveController.java @@ -5,7 +5,7 @@ import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveHeartRes; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveStatusRes; -import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchive; +import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchiveRes; import com.moing.backend.domain.missionArchive.application.service.*; import com.moing.backend.global.config.security.dto.User; import com.moing.backend.global.response.SuccessResponse; @@ -77,9 +77,9 @@ public ResponseEntity>> getMyArchive(@Au * 작성자 : 정승연 **/ @GetMapping("/others") - public ResponseEntity>> getOtherPeopleArchives(@AuthenticationPrincipal User user, - @PathVariable("teamId") Long teamId, - @PathVariable("missionId") Long missionId) { + public ResponseEntity>> getOtherPeopleArchives(@AuthenticationPrincipal User user, + @PathVariable("teamId") Long teamId, + @PathVariable("missionId") Long missionId) { return ResponseEntity.ok(SuccessResponse.create(READ_TEAM_ARCHIVE_SUCCESS.getMessage(), this.singleMissionArchiveReadUseCase.getPersonalArchive(user.getSocialId(),missionId))); } 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 10625b91..bd651f2c 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 @@ -1,21 +1,12 @@ package com.moing.backend.domain.missionArchive.representation; -import com.google.common.collect.ImmutableList; import com.moing.backend.config.CommonControllerTest; -import com.moing.backend.domain.mission.application.dto.req.MissionReq; -import com.moing.backend.domain.mission.application.dto.res.MissionCreateRes; -import com.moing.backend.domain.mission.application.dto.res.MissionReadRes; -import com.moing.backend.domain.mission.application.service.MissionCreateUseCase; -import com.moing.backend.domain.mission.application.service.MissionDeleteUseCase; -import com.moing.backend.domain.mission.application.service.MissionReadUseCase; -import com.moing.backend.domain.mission.application.service.MissionUpdateUseCase; -import com.moing.backend.domain.mission.presentation.MissionController; import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveHeartReq; import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveReq; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveHeartRes; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveStatusRes; -import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchive; +import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchiveRes; import com.moing.backend.domain.missionArchive.application.service.MissionArchiveCreateUseCase; import com.moing.backend.domain.missionArchive.application.service.MissionArchiveHeartUseCase; import com.moing.backend.domain.missionArchive.application.service.MissionArchiveUpdateUseCase; @@ -30,8 +21,6 @@ import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import java.text.SimpleDateFormat; -import java.time.LocalDateTime; import java.util.List; import static com.moing.backend.domain.missionArchive.domain.constant.MissionArchiveResponseMessage.*; @@ -237,7 +226,7 @@ public class MissionArchiveControllerTest extends CommonControllerTest { public void 모임원_미션_인증_조회() throws Exception { //given - List output = Lists.newArrayList(PersonalArchive.builder() + List output = Lists.newArrayList(PersonalArchiveRes.builder() .archiveId(1L) .nickname("modagbul_tester1") .profileImg("[s3 Link]") From 6b47ff8f3318776708eea5de55b330fa276f0039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Thu, 5 Oct 2023 18:24:54 +0900 Subject: [PATCH 21/30] =?UTF-8?q?feat=20:=20=EC=A7=84=ED=96=89=EC=A4=91?= =?UTF-8?q?=EC=9D=B8=20=EB=B0=98=EB=B3=B5=EB=AF=B8=EC=85=98=20=ED=98=84?= =?UTF-8?q?=ED=99=A9=20=EB=B3=B4=EB=93=9C=20=EC=99=84=EB=A3=8C=20#23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/res/RepeatMissionBoardRes.java | 22 +++++-- .../service/MissionArchiveBoardUseCase.java | 17 +++--- .../repository/MissionCustomRepository.java | 10 ++- .../MissionCustomRepositoryImpl.java | 19 ++++++ .../domain/service/MissionQueryService.java | 7 +++ .../mapper/MissionArchiveMapper.java | 1 + .../service/MissionArchiveCreateUseCase.java | 4 +- .../MissionArchiveCustomRepository.java | 2 + .../MissionArchiveCustomRepositoryImpl.java | 61 +++++++++++++++++-- .../service/MissionArchiveQueryService.java | 7 ++- .../presentation/MissionBoardController.java | 29 +++++++-- 11 files changed, 151 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java b/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java index ddef3b56..1e3b46cf 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java +++ b/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java @@ -1,12 +1,26 @@ package com.moing.backend.domain.mission.application.dto.res; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +//@Builder public class RepeatMissionBoardRes { private Long missionId; - private String dueTo; //요일 private String title; - private String status; - private int num; - private int done; + + private String dueTo; // 요일 상태 넘겨주기 +// private String status; + private Long done; + private int number; + public RepeatMissionBoardRes(Long missionId, String title, Long done,int number) { + this.missionId = missionId; + this.title = title; + this.number = number; + this.done = done; + } } diff --git a/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java b/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java index be0f867b..358c907e 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java +++ b/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java @@ -7,6 +7,7 @@ import com.moing.backend.domain.mission.application.dto.res.SingleMissionBoardRes; import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; +import com.moing.backend.domain.mission.domain.service.MissionQueryService; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; import com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; @@ -28,6 +29,7 @@ public class MissionArchiveBoardUseCase { private final MissionArchiveQueryService missionArchiveQueryService; + private final MissionQueryService missionQueryService; private final MemberGetService memberGetService; private final TeamRepository teamRepository; @@ -57,13 +59,12 @@ public List getFinishMissions(Long teamId, String memberI } -// public List getActiveRepeatMissions(Long teamId, String memberId) { -// -// Team team = teamRepository.findById(teamId).orElseThrow(); -// Member member = memberGetService.getMemberBySocialId(memberId); -// -// missionArchiveQueryService.findRepeatMissionMyArchive(memberId, ); -// } -// + public List getActiveRepeatMissions(Long teamId, String memberId) { + + Member member = memberGetService.getMemberBySocialId(memberId); + + return missionArchiveQueryService.findMyRepeatMissionArchives(member.getMemberId(),teamId,MissionStatus.ONGOING); + + } } diff --git a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java index 9ab4a501..b09cd218 100644 --- a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java @@ -1,5 +1,13 @@ package com.moing.backend.domain.mission.domain.repository; +import com.moing.backend.domain.mission.domain.entity.Mission; +import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; + +import java.util.List; +import java.util.Optional; + public interface MissionCustomRepository { Long findMissionsCountByTeam(Long teamId); -} \ No newline at end of file + Optional> findRepeatMissionByMemberId(Long teamId, MissionStatus status); + + } \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java index 53a7cd60..7ab14a9f 100644 --- a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java @@ -1,10 +1,15 @@ package com.moing.backend.domain.mission.domain.repository; import com.moing.backend.domain.mission.domain.entity.Mission; +import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; +import com.moing.backend.domain.mission.domain.entity.constant.MissionType; import com.querydsl.jpa.impl.JPAQueryFactory; import javax.persistence.EntityManager; +import java.util.List; +import java.util.Optional; + import static com.moing.backend.domain.mission.domain.entity.QMission.mission; public class MissionCustomRepositoryImpl implements MissionCustomRepository{ @@ -25,4 +30,18 @@ public Long findMissionsCountByTeam(Long teamId) { ) .fetchFirst(); } + + @Override + public Optional> findRepeatMissionByMemberId(Long teamId, MissionStatus status) { + + return Optional.ofNullable(queryFactory + .select(mission) + .from(mission) + .where( + mission.team.teamId.eq(teamId), + mission.status.eq(status), + mission.type.eq(MissionType.REPEAT) + ) + .fetch()); + } } diff --git a/src/main/java/com/moing/backend/domain/mission/domain/service/MissionQueryService.java b/src/main/java/com/moing/backend/domain/mission/domain/service/MissionQueryService.java index 961be80e..821c5022 100644 --- a/src/main/java/com/moing/backend/domain/mission/domain/service/MissionQueryService.java +++ b/src/main/java/com/moing/backend/domain/mission/domain/service/MissionQueryService.java @@ -1,12 +1,15 @@ package com.moing.backend.domain.mission.domain.service; import com.moing.backend.domain.mission.domain.entity.Mission; +import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; import com.moing.backend.domain.mission.exception.NotFoundMissionException; import com.moing.backend.domain.mission.domain.repository.MissionRepository; import com.moing.backend.global.annotation.DomainService; import lombok.RequiredArgsConstructor; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @DomainService @Transactional @RequiredArgsConstructor @@ -21,4 +24,8 @@ public Mission findMissionById(Long missionId) { public Long findMissionsCountByTeam(Long teamId) { return missionRepository.findMissionsCountByTeam(teamId); } + + public List findRepeatMissionByTeamId(Long teamId) { + return missionRepository.findRepeatMissionByMemberId(teamId, MissionStatus.ONGOING).orElseThrow(NotFoundMissionException::new); + } } 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 0eeec9df..eafa243c 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 @@ -2,6 +2,7 @@ import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.mission.application.dto.res.FinishMissionBoardRes; +import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes; import com.moing.backend.domain.mission.application.dto.res.SingleMissionBoardRes; import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveReq; diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java index 5835d28e..22ee82de 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java @@ -70,7 +70,9 @@ public Boolean isDoneMission(Long memberId,Mission mission) { public Boolean isEndMission(Member member,Mission mission) { Team team = mission.getTeam(); - if (mission.getMissionArchiveList().size() == team.getNumOfMember()-1) { + Long missionsCountByTeam = missionQueryService.findMissionsCountByTeam(team.getTeamId()); + + if (missionsCountByTeam == team.getNumOfMember()-1) { mission.setStatus(MissionStatus.END); return true; } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java index 365fe7f9..1acd16d5 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java @@ -1,5 +1,6 @@ package com.moing.backend.domain.missionArchive.domain.repository; +import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes; import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; @@ -17,6 +18,7 @@ public interface MissionArchiveCustomRepository { Optional findDonePeopleByMissionId(Long missionId); Optional findMyDoneCountByMissionId(Long missionId,Long memberId); + Optional> findRepeatMissionArchivesByMemberId(Long memberId, Long teamId, MissionStatus status); } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java index 2c934479..eb476116 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java @@ -1,13 +1,17 @@ package com.moing.backend.domain.missionArchive.domain.repository; +import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes; import com.moing.backend.domain.mission.domain.entity.QMission; +import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; +import com.moing.backend.domain.mission.domain.entity.constant.MissionType; 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.entity.QMissionArchive; import com.moing.backend.domain.teamMember.domain.repository.OrderCondition; import com.querydsl.core.types.Order; import com.querydsl.core.types.OrderSpecifier; +import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; import feign.Param; import org.springframework.data.jpa.repository.Query; @@ -19,7 +23,10 @@ import java.util.Objects; import java.util.Optional; +import static com.moing.backend.domain.mission.domain.entity.QMission.mission; import static com.moing.backend.domain.missionArchive.domain.entity.QMissionArchive.*; +import static javax.swing.Spring.constant; +import static org.hibernate.internal.util.NullnessHelper.coalesce; public class MissionArchiveCustomRepositoryImpl implements MissionArchiveCustomRepository { @@ -31,7 +38,7 @@ public MissionArchiveCustomRepositoryImpl(EntityManager em) { @Override public Optional> findSingleMissionArchivesByMemberId(Long memberId, Long teamId, MissionStatus status, - MissionArchiveStatus archiveStatus,OrderCondition orderCondition) { + MissionArchiveStatus archiveStatus, OrderCondition orderCondition) { OrderSpecifier[] orderSpecifiers = createOrderSpecifier(orderCondition); return Optional.ofNullable(queryFactory .select(missionArchive) @@ -51,9 +58,9 @@ private OrderSpecifier[] createOrderSpecifier(OrderCondition orderCondition) { List orderSpecifiers = new ArrayList<>(); - if(orderCondition.equals(OrderCondition.DUETO)){ + if (orderCondition.equals(OrderCondition.DUETO)) { orderSpecifiers.add(new OrderSpecifier(Order.DESC, missionArchive.mission.dueTo)); - }else if(orderCondition.equals(OrderCondition.CREATED)){ + } else if (orderCondition.equals(OrderCondition.CREATED)) { orderSpecifiers.add(new OrderSpecifier(Order.ASC, missionArchive.createdDate)); } return orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]); @@ -79,7 +86,7 @@ public Optional> findOthersArchives(Long memberId, Long mis } @Override - public Optional> findAllMissionArchivesByMemberId(Long memberId, Long teamId, MissionStatus missionStatus){ + public Optional> findAllMissionArchivesByMemberId(Long memberId, Long teamId, MissionStatus missionStatus) { return Optional.ofNullable(queryFactory .selectFrom(missionArchive) @@ -106,7 +113,7 @@ public Optional findDonePeopleByMissionId(Long missionId) { } @Override - public Optional findMyDoneCountByMissionId(Long missionId,Long memberId){ + public Optional findMyDoneCountByMissionId(Long missionId, Long memberId) { return Optional.ofNullable(queryFactory .select(missionArchive.count()) .from(missionArchive) @@ -119,5 +126,49 @@ public Optional findMyDoneCountByMissionId(Long missionId,Long memberId){ } +// @Override +// public Optional> findRepeatMissionArchivesByMemberId(Long memberId, Long teamId, MissionStatus status) { +// return Optional.ofNullable(queryFactory +// .select(Projections.constructor(RepeatMissionBoardRes.class, +// missionArchive.mission.id, +// missionArchive.mission.title, +// missionArchive.count, +// missionArchive.mission.number +// )) +// .from(missionArchive) +// .where( +// missionArchive.mission.team.teamId.eq(teamId), +// missionArchive.mission.type.eq(MissionType.REPEAT), +// missionArchive.member.memberId.eq(memberId), +// missionArchive.mission.status.eq(status) +// ) +// .groupBy(missionArchive.mission.id) +// .fetch()); +// +// +// } + @Override + public Optional> findRepeatMissionArchivesByMemberId(Long memberId, Long teamId, MissionStatus status) { + return Optional.ofNullable(queryFactory + .select(Projections.constructor(RepeatMissionBoardRes.class, + mission.id, + mission.title, + missionArchive.count.coalesce(0L).as("num"), + mission.number + )) + .from(mission) + .leftJoin(mission.missionArchiveList,missionArchive) + .on( missionArchive.member.memberId.eq(memberId), + missionArchive.mission.status.eq(status)) + .where( + mission.team.teamId.eq(teamId), + mission.type.eq(MissionType.REPEAT) +// missionArchive.member.memberId.eq(memberId), +// missionArchive.mission.status.eq(status) + ) + .groupBy(mission.id) + .fetch()); + + } } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java index 2bcb61fa..89a4e5d9 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java @@ -1,5 +1,6 @@ package com.moing.backend.domain.missionArchive.domain.service; +import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes; import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; import com.moing.backend.domain.mission.domain.repository.MissionRepository; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; @@ -77,9 +78,9 @@ public List findMySingleMissionArchives(Long memberId,Long teamI incompleteList.addAll(completeList); return incompleteList; } -// public List findMyRepeatMissionArchives(Long memberId, List missionIds) { -// return missionArchiveRepository.findRepeatMissionArchivesByMission(memberId, missionIds).orElseThrow(NotFoundMissionArchiveException::new); -// } + public List findMyRepeatMissionArchives(Long memberId, Long teamId, MissionStatus missionStatus) { + return missionArchiveRepository.findRepeatMissionArchivesByMemberId(memberId, teamId, missionStatus).orElseThrow(NotFoundMissionArchiveException::new); + } public List findMyAllMissionArchives(Long memberId, Long teamId, MissionStatus missionStatus) { return missionArchiveRepository.findAllMissionArchivesByMemberId(memberId, teamId, missionStatus).orElseThrow(NotFoundMissionArchiveException::new); diff --git a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java index 4a4760b4..066bf683 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java @@ -1,6 +1,7 @@ package com.moing.backend.domain.missionArchive.presentation; import com.moing.backend.domain.mission.application.dto.res.FinishMissionBoardRes; +import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes; import com.moing.backend.domain.mission.application.dto.res.SingleMissionBoardRes; import com.moing.backend.domain.mission.application.service.MissionArchiveBoardUseCase; import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveReq; @@ -18,28 +19,44 @@ @RestController @AllArgsConstructor -@RequestMapping("/api/{teamId}/missions/{missionId}/board") +@RequestMapping("/api/{teamId}/missions/board") public class MissionBoardController { private final MissionArchiveBoardUseCase missionArchiveBoardUseCase; /** * 단일 인증 조회 - * [POST] {teamId}/missions/{missionId}/board + * [POST] {teamId}/missions/board/single * 작성자 : 정승연 */ @GetMapping("/single") public ResponseEntity>> getActiveSingleMission(@AuthenticationPrincipal User user, - @PathVariable("teamId") Long teamId, - @PathVariable("missionId") Long missionId) { + @PathVariable("teamId") Long teamId) { return ResponseEntity.ok(SuccessResponse.create(ACTIVE_SINGLE_MISSION_SUCCESS.getMessage(), this.missionArchiveBoardUseCase.getActiveSingleMissions(teamId, user.getSocialId()))); } + /** + * 종료된 인증 조회 + * [POST] {teamId}/missions/board/finish + * 작성자 : 정승연 + */ + @GetMapping("/finish") public ResponseEntity>> getFinishAllMission(@AuthenticationPrincipal User user, - @PathVariable("teamId") Long teamId, - @PathVariable("missionId") Long missionId) { + @PathVariable("teamId") Long teamId) { return ResponseEntity.ok(SuccessResponse.create(FINISH_ALL_MISSION_SUCCESS.getMessage(), this.missionArchiveBoardUseCase.getFinishMissions(teamId, user.getSocialId()))); } + + /** + * 반복 미션 인증 조회 + * [GET] {teamId}/missions/board/repeat + * 작성자 : 정승연 + */ + @GetMapping("/repeat") + public ResponseEntity>> getActiveRepeatMission(@AuthenticationPrincipal User user, + @PathVariable("teamId") Long teamId) { + return ResponseEntity.ok(SuccessResponse.create(FINISH_ALL_MISSION_SUCCESS.getMessage(), this.missionArchiveBoardUseCase.getActiveRepeatMissions(teamId, user.getSocialId()))); + } + } From 8776afc826ecc8cc7ff22340ded12c533e389e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Thu, 5 Oct 2023 18:35:12 +0900 Subject: [PATCH 22/30] =?UTF-8?q?feat=20:=20=EB=B0=98=EB=B3=B5=EB=AF=B8?= =?UTF-8?q?=EC=85=98=20=EB=B3=B4=EB=93=9C=20'=EB=82=B4=EC=9D=BC=EB=A6=AC?= =?UTF-8?q?=EC=85=8B'=20=EB=A6=AC=ED=84=B4=20(dueTo:True/False)=20#23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/res/RepeatMissionBoardRes.java | 1 + .../service/MissionArchiveBoardUseCase.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java b/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java index 1e3b46cf..9868972b 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java +++ b/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java @@ -20,6 +20,7 @@ public class RepeatMissionBoardRes { public RepeatMissionBoardRes(Long missionId, String title, Long done,int number) { this.missionId = missionId; this.title = title; + this.dueTo="False"; this.number = number; this.done = done; } diff --git a/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java b/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java index 358c907e..1f512d08 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java +++ b/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java @@ -19,6 +19,9 @@ import org.springframework.stereotype.Service; import javax.transaction.Transactional; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -63,7 +66,18 @@ public List getActiveRepeatMissions(Long teamId, String m Member member = memberGetService.getMemberBySocialId(memberId); - return missionArchiveQueryService.findMyRepeatMissionArchives(member.getMemberId(),teamId,MissionStatus.ONGOING); + List myRepeatMissionArchives = missionArchiveQueryService.findMyRepeatMissionArchives(member.getMemberId(), teamId, MissionStatus.ONGOING); + + + LocalDate currentDate = LocalDate.now(); + DayOfWeek currentDayOfWeek = currentDate.getDayOfWeek(); + if (currentDayOfWeek == DayOfWeek.SUNDAY) { + myRepeatMissionArchives.stream().forEach( + repeatMissionBoardRes -> repeatMissionBoardRes.setDueTo("True") + ); + } + + return myRepeatMissionArchives; } From 472ad2e1204083997684148fa2ae544c01a49e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Thu, 5 Oct 2023 18:39:04 +0900 Subject: [PATCH 23/30] =?UTF-8?q?fix=20:=20=ED=95=9C=EB=B2=88=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=EB=AF=B8=EC=85=98=20=EC=A1=B0=ED=9A=8C=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20once=20=EC=88=98=EC=A0=95=20#23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/repository/MissionArchiveCustomRepositoryImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java index eb476116..bfac1e32 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java @@ -47,6 +47,7 @@ public Optional> findSingleMissionArchivesByMemberId(Long m missionArchive.mission.team.teamId.eq(teamId), missionArchive.member.memberId.eq(memberId), missionArchive.mission.status.eq(status), + missionArchive.mission.type.eq(MissionType.ONCE), missionArchive.status.eq(archiveStatus) ) .orderBy(orderSpecifiers) From 96c7ec5c372dc375c6bd8570c63b28aea6dc2491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Fri, 6 Oct 2023 11:32:57 +0900 Subject: [PATCH 24/30] =?UTF-8?q?refactor=20:=20singleMissionArchive=20ret?= =?UTF-8?q?urn=20=EC=97=90=20=EC=93=B0=EC=9D=B4=EB=8A=94=20OrderCondition?= =?UTF-8?q?=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD=20#23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/MissionArchiveCustomRepository.java | 2 -- .../repository/MissionArchiveCustomRepositoryImpl.java | 9 --------- .../missionArchive/domain/repository/OrderCondition.java | 6 ++++++ .../domain/service/MissionArchiveQueryService.java | 5 +---- .../teamMember/domain/repository/OrderCondition.java | 6 ------ 5 files changed, 7 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/moing/backend/domain/missionArchive/domain/repository/OrderCondition.java delete mode 100644 src/main/java/com/moing/backend/domain/teamMember/domain/repository/OrderCondition.java diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java index 1acd16d5..11a5de7e 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java @@ -4,8 +4,6 @@ import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; -import com.moing.backend.domain.teamMember.domain.repository.OrderCondition; -import org.springframework.stereotype.Repository; import java.util.List; import java.util.Optional; diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java index bfac1e32..f862658b 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java @@ -1,32 +1,23 @@ package com.moing.backend.domain.missionArchive.domain.repository; import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes; -import com.moing.backend.domain.mission.domain.entity.QMission; -import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; import com.moing.backend.domain.mission.domain.entity.constant.MissionType; 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.entity.QMissionArchive; -import com.moing.backend.domain.teamMember.domain.repository.OrderCondition; import com.querydsl.core.types.Order; import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; -import feign.Param; -import org.springframework.data.jpa.repository.Query; -import org.springframework.stereotype.Repository; import javax.persistence.EntityManager; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.Optional; import static com.moing.backend.domain.mission.domain.entity.QMission.mission; import static com.moing.backend.domain.missionArchive.domain.entity.QMissionArchive.*; import static javax.swing.Spring.constant; -import static org.hibernate.internal.util.NullnessHelper.coalesce; public class MissionArchiveCustomRepositoryImpl implements MissionArchiveCustomRepository { diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/OrderCondition.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/OrderCondition.java new file mode 100644 index 00000000..ab250eca --- /dev/null +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/OrderCondition.java @@ -0,0 +1,6 @@ +package com.moing.backend.domain.missionArchive.domain.repository; + +public enum OrderCondition { + DUETO,CREATED + +} diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java index 89a4e5d9..c0d1b0b4 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java @@ -4,12 +4,9 @@ import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; import com.moing.backend.domain.mission.domain.repository.MissionRepository; 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.repository.MissionArchiveCustomRepository; import com.moing.backend.domain.missionArchive.domain.repository.MissionArchiveRepository; import com.moing.backend.domain.missionArchive.exception.NotFoundMissionArchiveException; -import com.moing.backend.domain.missionArchive.exception.NotFoundMissionArchiveException; -import com.moing.backend.domain.teamMember.domain.repository.OrderCondition; +import com.moing.backend.domain.missionArchive.domain.repository.OrderCondition; import com.moing.backend.global.annotation.DomainService; import lombok.RequiredArgsConstructor; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/OrderCondition.java b/src/main/java/com/moing/backend/domain/teamMember/domain/repository/OrderCondition.java deleted file mode 100644 index 706b8e5a..00000000 --- a/src/main/java/com/moing/backend/domain/teamMember/domain/repository/OrderCondition.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.moing.backend.domain.teamMember.domain.repository; - -public enum OrderCondition { - DUETO,CREATED - -} From e5ce422617d528020d6a06fd034e7b65cfcc0873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Sat, 7 Oct 2023 01:56:09 +0900 Subject: [PATCH 25/30] =?UTF-8?q?feat=20:=20=EB=82=98=EC=9D=98=20=EC=A2=85?= =?UTF-8?q?=EB=A3=8C=20=EB=AF=B8=EC=85=98=20=EB=B0=98=EB=B3=B5=EB=AF=B8?= =?UTF-8?q?=EC=85=98=20=ED=8F=AC=ED=95=A8=ED=95=B4=EC=84=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=84=B4=ED=95=98=EA=B8=B0=20#23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MissionArchiveCustomRepository.java | 2 ++ .../MissionArchiveCustomRepositoryImpl.java | 6 +++++ .../service/MissionArchiveQueryService.java | 20 +++++++++++----- .../presentation/MissionBoardController.java | 24 +++++++++---------- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java index 11a5de7e..bf7caed9 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java @@ -1,5 +1,6 @@ package com.moing.backend.domain.missionArchive.domain.repository; +import com.moing.backend.domain.mission.application.dto.res.FinishMissionBoardRes; import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes; import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; @@ -18,5 +19,6 @@ public interface MissionArchiveCustomRepository { Optional> findRepeatMissionArchivesByMemberId(Long memberId, Long teamId, MissionStatus status); + Optional> findMyMissionsByStatus(Long memberId, Long teamId, MissionStatus missionStatus); } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java index f862658b..4a719e65 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java @@ -1,5 +1,6 @@ package com.moing.backend.domain.missionArchive.domain.repository; +import com.moing.backend.domain.mission.application.dto.res.FinishMissionBoardRes; import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes; import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; import com.moing.backend.domain.mission.domain.entity.constant.MissionType; @@ -162,5 +163,10 @@ public Optional> findRepeatMissionArchivesByMemberId .fetch()); + } + + @Override + public Optional> findMyMissionsByStatus(Long memberId, Long teamId, MissionStatus missionStatus) { + } } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java index c0d1b0b4..52a3a7fb 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java @@ -1,6 +1,8 @@ package com.moing.backend.domain.missionArchive.domain.service; +import com.moing.backend.domain.mission.application.dto.res.FinishMissionBoardRes; import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes; +import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; import com.moing.backend.domain.mission.domain.repository.MissionRepository; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; @@ -31,6 +33,7 @@ public MissionArchive findByMissionArchiveId(Long missionArchiveId) { public MissionArchive findArchive(Long memberId, Long missionId) { return missionArchiveRepository.findByMissionIdAndMemberId(memberId, missionId).orElseThrow(NotFoundMissionArchiveException::new); } + public List findMyArchive(Long memberId, Long missionId) { Optional> optional = missionArchiveRepository.findArchivesByMissionIdAndMemberId(memberId, missionId); @@ -41,6 +44,7 @@ public List findMyArchive(Long memberId, Long missionId) { return optional.get(); } } + public List findOthersArchive(Long memberId, Long missionId) { return missionArchiveRepository.findOthersArchives(memberId, missionId).orElseThrow(NotFoundMissionArchiveException::new); } @@ -53,8 +57,7 @@ public Boolean isDone(Long memberId, Long missionId) { Optional> byMemberId = missionArchiveRepository.findArchivesByMissionIdAndMemberId(memberId, missionId); if (byMemberId.isPresent()) { return Boolean.TRUE; - } - else{ + } else { return Boolean.FALSE; } } @@ -64,17 +67,18 @@ public Boolean isDone(Long memberId, Long missionId) { /** * mission.getTeam() 팀의 단일미션 미션 인증 보드 */ - public List findMySingleMissionArchives(Long memberId,Long teamId, MissionStatus missionStatus) { + public List findMySingleMissionArchives(Long memberId, Long teamId, MissionStatus missionStatus) { // INCOMPLETE List incompleteList = missionArchiveRepository.findSingleMissionArchivesByMemberId(memberId, teamId, missionStatus, INCOMPLETE, OrderCondition.DUETO) .orElseThrow(NotFoundMissionArchiveException::new); - List completeList = missionArchiveRepository.findSingleMissionArchivesByMemberId(memberId, teamId, missionStatus, COMPLETE,OrderCondition.CREATED) + List completeList = missionArchiveRepository.findSingleMissionArchivesByMemberId(memberId, teamId, missionStatus, COMPLETE, OrderCondition.CREATED) .orElseThrow(NotFoundMissionArchiveException::new); incompleteList.addAll(completeList); return incompleteList; } + public List findMyRepeatMissionArchives(Long memberId, Long teamId, MissionStatus missionStatus) { return missionArchiveRepository.findRepeatMissionArchivesByMemberId(memberId, teamId, missionStatus).orElseThrow(NotFoundMissionArchiveException::new); } @@ -86,11 +90,15 @@ public List findMyAllMissionArchives(Long memberId, Long teamId, public Long findDoneArchives(Long missionId) { return missionArchiveRepository.findDonePeopleByMissionId(missionId).orElseThrow(NotFoundMissionArchiveException::new); } - public Long findMyDoneArchives(Long memberId,Long missionId) { - return missionArchiveRepository.findMyDoneCountByMissionId(missionId,memberId).orElseThrow(NotFoundMissionArchiveException::new); + + public Long findMyDoneArchives(Long memberId, Long missionId) { + return missionArchiveRepository.findMyDoneCountByMissionId(missionId, memberId).orElseThrow(NotFoundMissionArchiveException::new); } + public List findMyFinishMissions(Long memberId, Long teamId, MissionStatus missionStatus) { + return missionArchiveRepository.findMyMissionsByStatus(memberId, teamId, missionStatus).orElseThrow(NotFoundMissionArchiveException::new); + } } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java index 066bf683..3a37836d 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java @@ -36,18 +36,6 @@ public ResponseEntity>> getActiveSin return ResponseEntity.ok(SuccessResponse.create(ACTIVE_SINGLE_MISSION_SUCCESS.getMessage(), this.missionArchiveBoardUseCase.getActiveSingleMissions(teamId, user.getSocialId()))); } - /** - * 종료된 인증 조회 - * [POST] {teamId}/missions/board/finish - * 작성자 : 정승연 - */ - - @GetMapping("/finish") - public ResponseEntity>> getFinishAllMission(@AuthenticationPrincipal User user, - @PathVariable("teamId") Long teamId) { - return ResponseEntity.ok(SuccessResponse.create(FINISH_ALL_MISSION_SUCCESS.getMessage(), this.missionArchiveBoardUseCase.getFinishMissions(teamId, user.getSocialId()))); - } - /** * 반복 미션 인증 조회 * [GET] {teamId}/missions/board/repeat @@ -59,4 +47,16 @@ public ResponseEntity>> getActiveRep return ResponseEntity.ok(SuccessResponse.create(FINISH_ALL_MISSION_SUCCESS.getMessage(), this.missionArchiveBoardUseCase.getActiveRepeatMissions(teamId, user.getSocialId()))); } + /** + * 종료된 인증 조회 + * [POST] {teamId}/missions/board/finish + * 작성자 : 정승연 + */ + + @GetMapping("/finish") + public ResponseEntity>> getFinishAllMission(@AuthenticationPrincipal User user, + @PathVariable("teamId") Long teamId) { + return ResponseEntity.ok(SuccessResponse.create(FINISH_ALL_MISSION_SUCCESS.getMessage(), this.missionArchiveBoardUseCase.getFinishMissions(teamId, user.getSocialId()))); + } + } From 2658f10bbfb1370f458abed866ff4d5ba11c70fc Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Sat, 7 Oct 2023 18:36:41 +0900 Subject: [PATCH 26/30] =?UTF-8?q?feat=20:=20=EC=A2=85=EB=A1=9C=EB=90=9C=20?= =?UTF-8?q?=EB=AF=B8=EC=85=98(=ED=95=9C=EB=B2=88,=EB=B0=98=EB=B3=B5)=20?= =?UTF-8?q?=EB=AA=A8=EB=91=90=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/res/FinishMissionBoardRes.java | 20 +++++++++++++--- .../service/MissionArchiveBoardUseCase.java | 3 +-- .../mapper/MissionArchiveMapper.java | 6 ++--- .../MissionArchiveResponseMessage.java | 1 + .../MissionArchiveCustomRepositoryImpl.java | 24 +++++++++++++++++++ .../presentation/MissionBoardController.java | 2 +- 6 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/moing/backend/domain/mission/application/dto/res/FinishMissionBoardRes.java b/src/main/java/com/moing/backend/domain/mission/application/dto/res/FinishMissionBoardRes.java index fbb5b9c0..de1d37d0 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/dto/res/FinishMissionBoardRes.java +++ b/src/main/java/com/moing/backend/domain/mission/application/dto/res/FinishMissionBoardRes.java @@ -1,15 +1,29 @@ package com.moing.backend.domain.mission.application.dto.res; +import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; +import com.moing.backend.domain.mission.domain.entity.constant.MissionType; +import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; import lombok.Builder; import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; @Builder @Getter +@Setter public class FinishMissionBoardRes { private Long missionId; - private String dueTo; // 날짜 + private LocalDateTime dueTo; // 날짜 private String title; - private String status; - private String missionType; + private MissionArchiveStatus status; + private MissionType missionType; + public FinishMissionBoardRes(Long missionId, LocalDateTime dueTo, String title, MissionArchiveStatus status, MissionType missionType) { + this.missionId = missionId; + this.dueTo = dueTo; + this.title = title; + this.status = status; + this.missionType = missionType; + } } diff --git a/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java b/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java index 1f512d08..7a635373 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java +++ b/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java @@ -57,8 +57,7 @@ public List getFinishMissions(Long teamId, String memberI Team team = teamRepository.findById(teamId).orElseThrow(); Member member = memberGetService.getMemberBySocialId(memberId); - List myAllMissionArchives = missionArchiveQueryService.findMyAllMissionArchives(member.getMemberId(), teamId, MissionStatus.END); - return MissionArchiveMapper.mapToFinishMissionBoardResList(myAllMissionArchives); + return missionArchiveQueryService.findMyFinishMissions(member.getMemberId(), teamId, MissionStatus.END); } 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 eafa243c..552c4971 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 @@ -115,10 +115,10 @@ public static FinishMissionBoardRes mapToFinishMissionBoardRes(MissionArchive mi Mission mission = missionArchive.getMission(); return FinishMissionBoardRes.builder() .missionId(mission.getId()) - .missionType(mission.getType().name()) + .missionType(mission.getType()) .title(mission.getTitle()) - .dueTo(mission.getDueTo().toString()) - .status(missionArchive.getStatus().name()) + .dueTo(mission.getDueTo()) + .status(missionArchive.getStatus()) .build(); } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/constant/MissionArchiveResponseMessage.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/constant/MissionArchiveResponseMessage.java index 5cda14a5..9dec4edf 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/constant/MissionArchiveResponseMessage.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/constant/MissionArchiveResponseMessage.java @@ -13,6 +13,7 @@ public enum MissionArchiveResponseMessage { HEART_UPDATE_SUCCESS("미션 인증 좋아요를 성공적으로 눌렀습니다."), MISSION_ARCHIVE_PEOPLE_STATUS_SUCCESS("미션 인증 성공한 인원 상태 조회를 완료 했습니다."), ACTIVE_SINGLE_MISSION_SUCCESS("진행 중인 한번 인증 미션 조회를 완료 했습니다."), + ACTIVE_REPEAT_MISSION_SUCCESS("진행 중인 반복 인증 미션 조회를 완료 했습니다."), FINISH_ALL_MISSION_SUCCESS("종료된 미션 조회를 완료하였습니다."); private final String message; diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java index 4a719e65..8cfa4b01 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java @@ -6,9 +6,11 @@ import com.moing.backend.domain.mission.domain.entity.constant.MissionType; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; +import com.querydsl.core.types.Expression; import com.querydsl.core.types.Order; import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.Expressions; import com.querydsl.jpa.impl.JPAQueryFactory; import javax.persistence.EntityManager; @@ -168,5 +170,27 @@ public Optional> findRepeatMissionArchivesByMemberId @Override public Optional> findMyMissionsByStatus(Long memberId, Long teamId, MissionStatus missionStatus) { + Expression dueToString = Expressions.stringTemplate("DATE_FORMAT({0}, '%Y-%m-%d %H:%i.%s')", mission.dueTo); + Expression status = Expressions.stringTemplate(String.valueOf(missionArchive.status)); + Expression type = Expressions.stringTemplate(String.valueOf(mission.type)); + + + return Optional.ofNullable(queryFactory + .select(Projections.constructor(FinishMissionBoardRes.class, + mission.id, + mission.dueTo, + mission.title, + missionArchive.status, + mission.type + )) + .from(mission) + .leftJoin(mission.missionArchiveList,missionArchive) + .on(missionArchive.member.memberId.eq(memberId)) + .where( + mission.team.teamId.eq(teamId), + mission.status.eq(missionStatus) + ) + .fetch() + ); } } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java index 3a37836d..64648461 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java @@ -44,7 +44,7 @@ public ResponseEntity>> getActiveSin @GetMapping("/repeat") public ResponseEntity>> getActiveRepeatMission(@AuthenticationPrincipal User user, @PathVariable("teamId") Long teamId) { - return ResponseEntity.ok(SuccessResponse.create(FINISH_ALL_MISSION_SUCCESS.getMessage(), this.missionArchiveBoardUseCase.getActiveRepeatMissions(teamId, user.getSocialId()))); + return ResponseEntity.ok(SuccessResponse.create(ACTIVE_REPEAT_MISSION_SUCCESS.getMessage(), this.missionArchiveBoardUseCase.getActiveRepeatMissions(teamId, user.getSocialId()))); } /** From 561fa03367210e86b01a58eb210187bc795e36ee Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Sat, 7 Oct 2023 18:45:55 +0900 Subject: [PATCH 27/30] fix : FinishMissionBoardRes field Type --- .../application/dto/res/FinishMissionBoardRes.java | 8 ++++---- .../application/mapper/MissionArchiveMapper.java | 6 +++--- .../repository/MissionArchiveCustomRepositoryImpl.java | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/moing/backend/domain/mission/application/dto/res/FinishMissionBoardRes.java b/src/main/java/com/moing/backend/domain/mission/application/dto/res/FinishMissionBoardRes.java index de1d37d0..ecd0c0b3 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/dto/res/FinishMissionBoardRes.java +++ b/src/main/java/com/moing/backend/domain/mission/application/dto/res/FinishMissionBoardRes.java @@ -14,12 +14,12 @@ @Setter public class FinishMissionBoardRes { private Long missionId; - private LocalDateTime dueTo; // 날짜 + private String dueTo; // 날짜 private String title; - private MissionArchiveStatus status; - private MissionType missionType; + private String status; + private String missionType; - public FinishMissionBoardRes(Long missionId, LocalDateTime dueTo, String title, MissionArchiveStatus status, MissionType missionType) { + public FinishMissionBoardRes(Long missionId, String dueTo, String title, String status, String missionType) { this.missionId = missionId; this.dueTo = dueTo; this.title = title; 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 552c4971..eafa243c 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 @@ -115,10 +115,10 @@ public static FinishMissionBoardRes mapToFinishMissionBoardRes(MissionArchive mi Mission mission = missionArchive.getMission(); return FinishMissionBoardRes.builder() .missionId(mission.getId()) - .missionType(mission.getType()) + .missionType(mission.getType().name()) .title(mission.getTitle()) - .dueTo(mission.getDueTo()) - .status(missionArchive.getStatus()) + .dueTo(mission.getDueTo().toString()) + .status(missionArchive.getStatus().name()) .build(); } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java index 8cfa4b01..cc562945 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java @@ -178,10 +178,10 @@ public Optional> findMyMissionsByStatus(Long memberI return Optional.ofNullable(queryFactory .select(Projections.constructor(FinishMissionBoardRes.class, mission.id, - mission.dueTo, + mission.dueTo.stringValue(), mission.title, - missionArchive.status, - mission.type + missionArchive.status.stringValue(), + mission.type.stringValue() )) .from(mission) .leftJoin(mission.missionArchiveList,missionArchive) From 45d629db4dde8a57c400053a64f08415f5eb73c9 Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Sat, 7 Oct 2023 23:01:52 +0900 Subject: [PATCH 28/30] =?UTF-8?q?feat=20:=20=EB=AF=B8=EC=85=98=20=EB=B3=B4?= =?UTF-8?q?=EB=93=9C=20=EA=B4=80=EB=A0=A8=20MissionBoardControllerTest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/res/RepeatMissionBoardRes.java | 9 + .../presentation/MissionBoardController.java | 2 +- .../MissionBoardControllerTest.java | 190 ++++++++++++++++++ 3 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/moing/backend/domain/missionArchive/representation/MissionBoardControllerTest.java diff --git a/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java b/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java index 9868972b..099c187c 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java +++ b/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java @@ -24,4 +24,13 @@ public RepeatMissionBoardRes(Long missionId, String title, Long done,int number) this.number = number; this.done = done; } + + @Builder + public RepeatMissionBoardRes(Long missionId, String title, String dueTo, Long done, int number) { + this.missionId = missionId; + this.title = title; + this.dueTo = "False"; + this.done = done; + this.number = number; + } } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java index 64648461..b48f595b 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/presentation/MissionBoardController.java @@ -26,7 +26,7 @@ public class MissionBoardController { /** * 단일 인증 조회 - * [POST] {teamId}/missions/board/single + * [GET] {teamId}/missions/board/single * 작성자 : 정승연 */ diff --git a/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionBoardControllerTest.java b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionBoardControllerTest.java new file mode 100644 index 00000000..e2361a30 --- /dev/null +++ b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionBoardControllerTest.java @@ -0,0 +1,190 @@ +package com.moing.backend.domain.missionArchive.representation; + +import com.moing.backend.config.CommonControllerTest; +import com.moing.backend.domain.mission.application.dto.res.FinishMissionBoardRes; +import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes; +import com.moing.backend.domain.mission.application.dto.res.SingleMissionBoardRes; +import com.moing.backend.domain.mission.application.service.MissionArchiveBoardUseCase; +import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; +import com.moing.backend.domain.missionArchive.presentation.MissionBoardController; +import org.assertj.core.util.Lists; +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 org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +import java.util.List; + +import static com.moing.backend.domain.missionArchive.domain.constant.MissionArchiveResponseMessage.*; +import static org.junit.jupiter.api.Assertions.*; +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.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; +import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; + +@WebMvcTest(MissionBoardController.class) +public class MissionBoardControllerTest extends CommonControllerTest { + + + @MockBean + private MissionArchiveBoardUseCase missionArchiveBoardUseCase; + + @Test + public void 단일_미션_인증_조회() throws Exception { + //given + + List output = Lists.newArrayList(SingleMissionBoardRes.builder() + .missionId(1L) + .dueTo("2023-09-03T21:32:33.888") + .title("Mission title") + .status("SKIP/COMPLETE") + .missionType("ONCE/REPEAT") + .build()); + + given(missionArchiveBoardUseCase.getActiveSingleMissions(any(),any())).willReturn(output); + + Long teamId = 1L; + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + get("/api/{teamId}/missions/board/single",teamId) + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + + ); + + //then + actions + .andExpect(MockMvcResultMatchers.status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + pathParameters( + parameterWithName("teamId").description("팀 아이디") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description(ACTIVE_SINGLE_MISSION_SUCCESS.getMessage()), + fieldWithPath("data[].missionId").description("미션 아이디"), + fieldWithPath("data[].dueTo").description("미션 마감 시각"), + fieldWithPath("data[].title").description("미션 제목"), + fieldWithPath("data[].status").description("미션 인증 상태"), + fieldWithPath("data[].missionType").description("미션 타입") + + ) + ) + ) + .andReturn(); + + } + + @Test + public void 반복_미션_인증_조회() throws Exception { + //given + + List output = Lists.newArrayList(RepeatMissionBoardRes.builder() + .missionId(1L) + .title("Mission title") + .dueTo("True/False") + .done(1L) + .number(3) + .build()); + + given(missionArchiveBoardUseCase.getActiveRepeatMissions(any(),any())).willReturn(output); + + Long teamId = 1L; + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + get("/api/{teamId}/missions/board/repeat",teamId) + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + + ); + + //then + actions + .andExpect(MockMvcResultMatchers.status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + pathParameters( + parameterWithName("teamId").description("팀 아이디") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description(ACTIVE_REPEAT_MISSION_SUCCESS.getMessage()), + fieldWithPath("data[].missionId").description("미션 아이디"), + fieldWithPath("data[].title").description("미션 제목"), + fieldWithPath("data[].dueTo").description("내일 리셋 상태 리턴, 일요일이면 true[True/False]"), + fieldWithPath("data[].number").description("전체 횟수"), + fieldWithPath("data[].done").description("인증한 횟수") + + ) + ) + ) + .andReturn(); + + } + + @Test + public void 종료된_인증_조회() throws Exception { + //given + + List output = Lists.newArrayList(FinishMissionBoardRes.builder() + .missionId(1L) + .title("Mission title") + .dueTo("2023-09-03T21:32:33.888") + .status("SUCCESS/FAIL") + .missionType("ONCE/REPEAT") + .build()); + + given(missionArchiveBoardUseCase.getFinishMissions(any(),any())).willReturn(output); + + Long teamId = 1L; + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + get("/api/{teamId}/missions/board/finish",teamId) + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + + ); + + //then + actions + .andExpect(MockMvcResultMatchers.status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + pathParameters( + parameterWithName("teamId").description("팀 아이디") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description(FINISH_ALL_MISSION_SUCCESS.getMessage()), + fieldWithPath("data[].missionId").description("미션 아이디"), + fieldWithPath("data[].title").description("미션 제목"), + fieldWithPath("data[].dueTo").description("내일 리셋 상태 리턴, 일요일이면 true[True/False]"), + fieldWithPath("data[].status").description("미션 종료된 상태 (성공/실패)"), + fieldWithPath("data[].missionType").description("미션 타입 (한번/반복)") + + ) + ) + ) + .andReturn(); + + } + + +} \ No newline at end of file From 8d7bbecb6a4e459933ecc51720a822365b6e9f9d Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Sun, 8 Oct 2023 03:46:24 +0900 Subject: [PATCH 29/30] =?UTF-8?q?fix=20:=20MissionStatus=20=ED=95=AD?= =?UTF-8?q?=EB=AA=A9=20END=20->=20SUCCESS,FAIL=20=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/service/MissionArchiveBoardUseCase.java | 2 +- .../domain/mission/domain/entity/constant/MissionStatus.java | 2 ++ .../domain/repository/MissionArchiveCustomRepository.java | 2 +- .../repository/MissionArchiveCustomRepositoryImpl.java | 4 ++-- .../domain/service/MissionArchiveQueryService.java | 5 ++--- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java b/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java index 7a635373..8518976f 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java +++ b/src/main/java/com/moing/backend/domain/mission/application/service/MissionArchiveBoardUseCase.java @@ -57,7 +57,7 @@ public List getFinishMissions(Long teamId, String memberI Team team = teamRepository.findById(teamId).orElseThrow(); Member member = memberGetService.getMemberBySocialId(memberId); - return missionArchiveQueryService.findMyFinishMissions(member.getMemberId(), teamId, MissionStatus.END); + return missionArchiveQueryService.findMyFinishMissions(member.getMemberId(), teamId); } diff --git a/src/main/java/com/moing/backend/domain/mission/domain/entity/constant/MissionStatus.java b/src/main/java/com/moing/backend/domain/mission/domain/entity/constant/MissionStatus.java index e561994a..07007a45 100644 --- a/src/main/java/com/moing/backend/domain/mission/domain/entity/constant/MissionStatus.java +++ b/src/main/java/com/moing/backend/domain/mission/domain/entity/constant/MissionStatus.java @@ -8,4 +8,6 @@ public enum MissionStatus { END, ONGOING, + SUCCESS, + FAIL } \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java index bf7caed9..890c89ea 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java @@ -19,6 +19,6 @@ public interface MissionArchiveCustomRepository { Optional> findRepeatMissionArchivesByMemberId(Long memberId, Long teamId, MissionStatus status); - Optional> findMyMissionsByStatus(Long memberId, Long teamId, MissionStatus missionStatus); + Optional> findFinishMissionsByStatus(Long memberId, Long teamId); } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java index cc562945..95a8dedd 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java @@ -168,7 +168,7 @@ public Optional> findRepeatMissionArchivesByMemberId } @Override - public Optional> findMyMissionsByStatus(Long memberId, Long teamId, MissionStatus missionStatus) { + public Optional> findFinishMissionsByStatus(Long memberId, Long teamId) { Expression dueToString = Expressions.stringTemplate("DATE_FORMAT({0}, '%Y-%m-%d %H:%i.%s')", mission.dueTo); Expression status = Expressions.stringTemplate(String.valueOf(missionArchive.status)); @@ -188,7 +188,7 @@ public Optional> findMyMissionsByStatus(Long memberI .on(missionArchive.member.memberId.eq(memberId)) .where( mission.team.teamId.eq(teamId), - mission.status.eq(missionStatus) + mission.status.eq(MissionStatus.SUCCESS).or(mission.status.eq(MissionStatus.FAIL)) ) .fetch() ); diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java index 52a3a7fb..8b24c4c1 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java @@ -2,7 +2,6 @@ import com.moing.backend.domain.mission.application.dto.res.FinishMissionBoardRes; import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes; -import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; import com.moing.backend.domain.mission.domain.repository.MissionRepository; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; @@ -96,8 +95,8 @@ public Long findMyDoneArchives(Long memberId, Long missionId) { } - public List findMyFinishMissions(Long memberId, Long teamId, MissionStatus missionStatus) { - return missionArchiveRepository.findMyMissionsByStatus(memberId, teamId, missionStatus).orElseThrow(NotFoundMissionArchiveException::new); + public List findMyFinishMissions(Long memberId, Long teamId) { + return missionArchiveRepository.findFinishMissionsByStatus(memberId, teamId).orElseThrow(NotFoundMissionArchiveException::new); } From eb8d2f0d6b6489dfedb68cfc523e03de28bf7d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:13:40 +0900 Subject: [PATCH 30/30] =?UTF-8?q?feat=20:=20MissionBoard-API.adoc=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/MissionArchive-API.adoc | 2 +- src/docs/asciidoc/MissionBoard-API.adoc | 28 +++++++++++++++++ src/docs/asciidoc/api.adoc | 2 ++ .../repository/MissionCustomRepository.java | 2 ++ .../presentation/MissionController.java | 1 - .../RepeatMissionArchiveReadUseCase.java | 31 ------------------- .../MissionArchiveCustomRepository.java | 2 ++ .../MissionArchiveControllerTest.java | 25 ++++++++++----- 8 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 src/docs/asciidoc/MissionBoard-API.adoc diff --git a/src/docs/asciidoc/MissionArchive-API.adoc b/src/docs/asciidoc/MissionArchive-API.adoc index dc148e22..8d287be0 100644 --- a/src/docs/asciidoc/MissionArchive-API.adoc +++ b/src/docs/asciidoc/MissionArchive-API.adoc @@ -11,7 +11,7 @@ operation::mission-archive-controller-test/미션_인증하기[snippets='http-re [[MissionArchive-재인증하기]] === 미션 재인증하기 -operation::mission-archive-controller-test/미션_재인증하기[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] +operation::mission-archive-controller-test/미션_재인증하기[snipipets='http-request,path-parameters,request-fields,http-response,response-fields'] --- diff --git a/src/docs/asciidoc/MissionBoard-API.adoc b/src/docs/asciidoc/MissionBoard-API.adoc new file mode 100644 index 00000000..fb985bf0 --- /dev/null +++ b/src/docs/asciidoc/MissionBoard-API.adoc @@ -0,0 +1,28 @@ + + +[[MissionBoard-API]] += MissionBoard API + +[[MissionBoard-단일미션인증조회]] +=== 단일 미션 인증 조회 +operation::mission-board-controller-test/단일_미션_인증_조회[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] + +--- + +[[MissionBoard-반복미션인증조회]] +=== 반복 미션 인증 조회 +operation::mission-board-controller-test/반복 미션 인증 조회[snipipets='http-request,path-parameters,request-fields,http-response,response-fields'] + +--- + +[[MissionBoard-나의미션인증조회]] +=== 나의 미션 인증 조회 +operation::mission-archive-controller-test/나의_미션_인증_조회[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] + +--- + +[[MissionBoard-종료된인증조회]] +=== 종료된 인증 조회 +operation::mission-board-controller-test/종료된_인증_조회[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] + +--- diff --git a/src/docs/asciidoc/api.adoc b/src/docs/asciidoc/api.adoc index d8753290..d103ef14 100644 --- a/src/docs/asciidoc/api.adoc +++ b/src/docs/asciidoc/api.adoc @@ -20,6 +20,8 @@ include::Mission-API.adoc[] include::MissionArchive-API.adoc[] +include::MissionBoard-API.adoc[] + include::Board-API.adoc[] include::BoardComment_API.adoc[] diff --git a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java index b09cd218..f46913d5 100644 --- a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepository.java @@ -2,10 +2,12 @@ import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; +import org.springframework.stereotype.Repository; import java.util.List; import java.util.Optional; +@Repository public interface MissionCustomRepository { Long findMissionsCountByTeam(Long teamId); Optional> findRepeatMissionByMemberId(Long teamId, MissionStatus status); diff --git a/src/main/java/com/moing/backend/domain/mission/presentation/MissionController.java b/src/main/java/com/moing/backend/domain/mission/presentation/MissionController.java index d66ccf85..1aa19a20 100644 --- a/src/main/java/com/moing/backend/domain/mission/presentation/MissionController.java +++ b/src/main/java/com/moing/backend/domain/mission/presentation/MissionController.java @@ -29,7 +29,6 @@ public class MissionController { private final MissionReadUseCase missionReadUseCase; private final MissionUpdateUseCase missionUpdateUseCase; private final MissionDeleteUseCase missionDeleteUseCase; - private final MissionQueryService missionQueryService; /** * 미션 조회 diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java index ff971211..02a17034 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/RepeatMissionArchiveReadUseCase.java @@ -22,37 +22,6 @@ public class RepeatMissionArchiveReadUseCase { private final MissionQueryService missionQueryService; private final MissionArchiveQueryService missionArchiveQueryService; - -// // 나의 인증 목록 -// public List getMyArchive(String userSocialId, Long missionId) { -// List myArchives = getArchive(userSocialId, missionId); -// -// List archiveRes = new ArrayList<>(); -// myArchives.forEach(myArchive -> archiveRes.add(MissionArchiveMapper.mapToMissionArchiveRes(myArchive))); -// -// return archiveRes; -// } -// -// // 팀원들 인증 목록 -// public List getPersonalArchive(String userSocialId, Long missionId) { -// Mission mission = missionQueryService.findMissionById(missionId); -// -// List done = new ArrayList<>(); -// -// mission.getMissionArchiveList() -// .forEach(missionArchive1 -> done.add(mapToPersonalArchive(missionArchive1))); -// -// return done; -// } -// -// // memberId, missionId로 archive 꺼내기 -// public List getArchive(String userSocialId, Long missionId) { -// Member member = memberGetService.getMemberBySocialId(userSocialId); -// Mission mission = missionQueryService.findMissionById(missionId); -// -// return missionArchiveQueryService.findMyArchive(member.getMemberId(), missionId); -// } - public MissionArchiveStatusRes getMyMissionDoneStatus(String userSocialId,Long missionId) { Member member = memberGetService.getMemberBySocialId(userSocialId); Mission mission = missionQueryService.findMissionById(missionId); diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java index 890c89ea..9ddb0af8 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java @@ -5,9 +5,11 @@ import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; +import org.springframework.stereotype.Repository; import java.util.List; import java.util.Optional; +@Repository public interface MissionArchiveCustomRepository { Optional> findSingleMissionArchivesByMemberId(Long memberId, Long teamId, MissionStatus status, MissionArchiveStatus archiveStatus, OrderCondition orderCondition); Optional> findOthersArchives(Long memberId, Long missionId) ; 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 bd651f2c..7cb3d752 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 @@ -7,10 +7,7 @@ import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveStatusRes; import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchiveRes; -import com.moing.backend.domain.missionArchive.application.service.MissionArchiveCreateUseCase; -import com.moing.backend.domain.missionArchive.application.service.MissionArchiveHeartUseCase; -import com.moing.backend.domain.missionArchive.application.service.MissionArchiveUpdateUseCase; -import com.moing.backend.domain.missionArchive.application.service.SingleMissionArchiveReadUseCase; +import com.moing.backend.domain.missionArchive.application.service.*; import com.moing.backend.domain.missionArchive.presentation.MissionArchiveController; import org.assertj.core.util.Lists; import org.junit.jupiter.api.Test; @@ -42,6 +39,8 @@ public class MissionArchiveControllerTest extends CommonControllerTest { @MockBean private SingleMissionArchiveReadUseCase singleMissionArchiveReadUseCase; @MockBean + private RepeatMissionArchiveReadUseCase repeatMissionArchiveReadUseCase; + @MockBean private MissionArchiveHeartUseCase missionArchiveHeartUseCase; @@ -62,6 +61,7 @@ public class MissionArchiveControllerTest extends CommonControllerTest { .createdDate("2023-09-03T21:32:33.888") .hearts(3) .status("COMPLETE/SKIP") + .count(1L) .build(); given(missionArchiveCreateUseCase.createArchive(any(),any(),any())).willReturn(output); @@ -99,7 +99,8 @@ public class MissionArchiveControllerTest extends CommonControllerTest { fieldWithPath("data.archive").description("미션 인증물 [s3URL/text/링크]"), fieldWithPath("data.createdDate").description("미션 제출 시각"), fieldWithPath("data.hearts").description("미션 인증 좋아요 수"), - fieldWithPath("data.status").description("미션 인증 상태") + fieldWithPath("data.status").description("미션 인증 상태"), + fieldWithPath("data.count").description("미션 인증 횟수") // fieldWithPath("data.heartsStatus").description("미션 인증 좋아요 상태"), ) ) @@ -124,6 +125,7 @@ public class MissionArchiveControllerTest extends CommonControllerTest { .createdDate("2023-09-03T21:32:33.888") .hearts(3) .status("COMPLETE/SKIP") + .count(1L) .build(); given(missionArchiveUpdateUseCase.updateArchive(any(),any(),any())).willReturn(output); @@ -161,7 +163,8 @@ public class MissionArchiveControllerTest extends CommonControllerTest { fieldWithPath("data.archive").description("미션 인증물 [s3URL/text/링크]"), fieldWithPath("data.createdDate").description("미션 제출 시각"), fieldWithPath("data.hearts").description("미션 인증 좋아요 수"), - fieldWithPath("data.status").description("미션 인증 상태") + fieldWithPath("data.status").description("미션 인증 상태"), + fieldWithPath("data.count").description("미션 인증 횟수") // fieldWithPath("data.heartsStatus").description("미션 인증 좋아요 상태"), ) ) @@ -180,6 +183,7 @@ public class MissionArchiveControllerTest extends CommonControllerTest { .createdDate("2023-09-03T21:32:33.888") .hearts(0) .status("COMPLETE/SKIP") + .count(1L) .build()); given(singleMissionArchiveReadUseCase.getMyArchive(any(),any())).willReturn(output); @@ -213,7 +217,8 @@ public class MissionArchiveControllerTest extends CommonControllerTest { fieldWithPath("data[].archive").description("미션 인증물 [s3URL/text/링크]"), fieldWithPath("data[].createdDate").description("미션 제출 시각"), fieldWithPath("data[].hearts").description("미션 인증 좋아요 수"), - fieldWithPath("data[].status").description("미션 인증 상태") + fieldWithPath("data[].status").description("미션 인증 상태"), + fieldWithPath("data[].count").description("미션 인증 횟수") ) ) @@ -234,6 +239,7 @@ public class MissionArchiveControllerTest extends CommonControllerTest { .createdDate("2023-09-03T21:32:33.888") .hearts(3) .status("COMPLETE/SKIP") + .count(1L) .build()); given(singleMissionArchiveReadUseCase.getPersonalArchive(any(),any())).willReturn(output); @@ -269,7 +275,8 @@ public class MissionArchiveControllerTest extends CommonControllerTest { fieldWithPath("data[].archive").description("미션 인증물 [s3URL/text/링크] "), fieldWithPath("data[].createdDate").description("미션 인증 날짜 "), fieldWithPath("data[].hearts").description("미션 인증 좋아요 수 "), - fieldWithPath("data[].status").description("미션 인증 상태") + fieldWithPath("data[].status").description("미션 인증 상태"), + fieldWithPath("data[].count").description("미션 인증 횟수") ) ) @@ -383,4 +390,6 @@ public class MissionArchiveControllerTest extends CommonControllerTest { + + }