From 69fff58ebfa595c26e01a73737c871a2a275c97f Mon Sep 17 00:00:00 2001 From: minsu20 Date: Sun, 29 Oct 2023 23:04:21 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=86=8C=EB=AA=A8=EC=9E=84=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EC=A0=84=20=EC=A1=B0=ED=9A=8C=20API=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- src/docs/asciidoc/Auth-API.adoc | 2 +- src/docs/asciidoc/Team-API.adoc | 4 ++ .../dto/response/DeleteTeamResponse.java | 5 -- .../dto/response/ReviewTeamResponse.java | 19 ++++++ .../team/application/mapper/TeamMapper.java | 5 +- .../service/DisbandTeamUserCase.java | 4 +- .../service/ReviewTeamUserCase.java | 27 ++++++++ .../service/WithdrawTeamUserCase.java | 4 +- .../team/presentation/TeamController.java | 13 ++++ .../constant/TeamResponseMessage.java | 1 + .../filter/JwtAuthenticationEntryPoint.java | 38 +++++++---- .../team/presentation/TeamControllerTest.java | 67 +++++++++++++------ 13 files changed, 143 insertions(+), 48 deletions(-) create mode 100644 src/main/java/com/moing/backend/domain/team/application/dto/response/ReviewTeamResponse.java create mode 100644 src/main/java/com/moing/backend/domain/team/application/service/ReviewTeamUserCase.java diff --git a/.gitignore b/.gitignore index 7554674c..b603f75b 100644 --- a/.gitignore +++ b/.gitignore @@ -48,4 +48,4 @@ data.sql #### docs #### !**/src/main/resources/static/docs/ -*.html +*.html \ No newline at end of file diff --git a/src/docs/asciidoc/Auth-API.adoc b/src/docs/asciidoc/Auth-API.adoc index 7c5b3d49..40d5aec1 100644 --- a/src/docs/asciidoc/Auth-API.adoc +++ b/src/docs/asciidoc/Auth-API.adoc @@ -24,7 +24,7 @@ operation::auth-controller-test/google_소셜_로그인_회원가입_후[snippet [[Auth-회원가입]] -=== Auth 회원가입 +== Auth 회원가입 |=== | 성별 | `MAN` diff --git a/src/docs/asciidoc/Team-API.adoc b/src/docs/asciidoc/Team-API.adoc index db7316f9..b6e71d0d 100644 --- a/src/docs/asciidoc/Team-API.adoc +++ b/src/docs/asciidoc/Team-API.adoc @@ -49,6 +49,10 @@ operation::team-controller-test/update_team[snippets='http-request,path-paramete == Team 소모임 수정 전 조회 operation::team-controller-test/get_current_status[snippets='http-request,path-parameters,http-response,response-fields'] +[[Team-소모임-삭제전-조회]] +== Team 소모임 삭제 전 조회 +operation::team-controller-test/review_team[snippets='http-request,path-parameters,http-response,response-fields'] + [[Team-소모임-강제종료]] == Team 소모임 강제종료 operation::team-controller-test/disband_team[snippets='http-request,path-parameters,http-response,response-fields'] diff --git a/src/main/java/com/moing/backend/domain/team/application/dto/response/DeleteTeamResponse.java b/src/main/java/com/moing/backend/domain/team/application/dto/response/DeleteTeamResponse.java index 8cc78bb2..92ed9017 100644 --- a/src/main/java/com/moing/backend/domain/team/application/dto/response/DeleteTeamResponse.java +++ b/src/main/java/com/moing/backend/domain/team/application/dto/response/DeleteTeamResponse.java @@ -11,9 +11,4 @@ @NoArgsConstructor public class DeleteTeamResponse { private Long teamId; - private String teamName; - private Integer numOfMember; - private Long duration; //걸린시간(단위:날짜) - private Long numOfMission; - private Integer levelOfFire; //불꽃 레벨 } diff --git a/src/main/java/com/moing/backend/domain/team/application/dto/response/ReviewTeamResponse.java b/src/main/java/com/moing/backend/domain/team/application/dto/response/ReviewTeamResponse.java new file mode 100644 index 00000000..f3b86539 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/team/application/dto/response/ReviewTeamResponse.java @@ -0,0 +1,19 @@ +package com.moing.backend.domain.team.application.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class ReviewTeamResponse { + private Long teamId; + private String teamName; + private Integer numOfMember; + private Long duration; //걸린시간(단위:날짜) + private Long numOfMission; + private Integer levelOfFire; //불꽃 레벨 +} \ No newline at end of file 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 7b8ce92d..be62dc70 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 @@ -38,8 +38,9 @@ public GetTeamDetailResponse toTeamDetailResponse(Team team, Integer boardNum, L .build(); } - public DeleteTeamResponse toDeleteTeamResponse(Long numOfMission, Team team){ - return DeleteTeamResponse.builder() + public ReviewTeamResponse toReviewTeamResponse(Long numOfMission, Team team){ + return ReviewTeamResponse + .builder() .teamId(team.getTeamId()) .teamName(team.getName()) .numOfMember(team.getNumOfMember()) 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 f0e88b2e..82fdae48 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 @@ -21,8 +21,6 @@ public class DisbandTeamUserCase { private final MemberGetService memberGetService; private final TeamGetService teamGetService; private final CheckLeaderUserCase checkLeaderUserCase; - private final MissionQueryService missionQueryService; - private final TeamMapper teamMapper; public DeleteTeamResponse disbandTeam(String socialId, Long teamId) { Member member = memberGetService.getMemberBySocialId(socialId); @@ -33,6 +31,6 @@ public DeleteTeamResponse disbandTeam(String socialId, Long teamId) { } else { throw new NotAuthByTeamException(); } - return teamMapper.toDeleteTeamResponse(missionQueryService.findMissionsCountByTeam(team.getTeamId()), team); + return new DeleteTeamResponse(teamId); } } diff --git a/src/main/java/com/moing/backend/domain/team/application/service/ReviewTeamUserCase.java b/src/main/java/com/moing/backend/domain/team/application/service/ReviewTeamUserCase.java new file mode 100644 index 00000000..3c7c477e --- /dev/null +++ b/src/main/java/com/moing/backend/domain/team/application/service/ReviewTeamUserCase.java @@ -0,0 +1,27 @@ +package com.moing.backend.domain.team.application.service; + +import com.moing.backend.domain.mission.domain.service.MissionQueryService; +import com.moing.backend.domain.team.application.dto.response.ReviewTeamResponse; +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.TeamGetService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class ReviewTeamUserCase { + + private final TeamGetService teamGetService; + private final TeamMapper teamMapper; + private final MissionQueryService missionQueryService; + + + public ReviewTeamResponse reviewTeam(String socialId, Long teamId){ + Team team=teamGetService.getTeamByTeamId(teamId); + return teamMapper.toReviewTeamResponse(missionQueryService.findMissionsCountByTeam(team.getTeamId()),team); + } +} diff --git a/src/main/java/com/moing/backend/domain/team/application/service/WithdrawTeamUserCase.java b/src/main/java/com/moing/backend/domain/team/application/service/WithdrawTeamUserCase.java index 15538b62..3e3a162d 100644 --- a/src/main/java/com/moing/backend/domain/team/application/service/WithdrawTeamUserCase.java +++ b/src/main/java/com/moing/backend/domain/team/application/service/WithdrawTeamUserCase.java @@ -22,14 +22,12 @@ public class WithdrawTeamUserCase { private final TeamMemberGetService teamMemberGetService; private final MemberGetService memberGetService; private final TeamGetService teamGetService; - private final MissionQueryService missionQueryService; - private final TeamMapper teamMapper; public DeleteTeamResponse withdrawTeam(String socialId, Long teamId) { Member member = memberGetService.getMemberBySocialId(socialId); Team team = teamGetService.getTeamByTeamId(teamId); TeamMember teamMember = teamMemberGetService.getTeamMember(member, team); teamMember.deleteMember(team); - return teamMapper.toDeleteTeamResponse(missionQueryService.findMissionsCountByTeam(team.getTeamId()),team); + return new DeleteTeamResponse(teamId); } } diff --git a/src/main/java/com/moing/backend/domain/team/presentation/TeamController.java b/src/main/java/com/moing/backend/domain/team/presentation/TeamController.java index 21675d8a..137cc77b 100644 --- a/src/main/java/com/moing/backend/domain/team/presentation/TeamController.java +++ b/src/main/java/com/moing/backend/domain/team/presentation/TeamController.java @@ -25,6 +25,7 @@ public class TeamController { private final DisbandTeamUserCase disbandTeamUserCase; private final WithdrawTeamUserCase withdrawTeamUserCase; private final UpdateTeamUserCase updateTeamUserCase; + private final ReviewTeamUserCase reviewTeamUserCase; /** * 소모임 생성 (only 개설만) @@ -92,6 +93,18 @@ public ResponseEntity> withdrawTeam(@Authent return ResponseEntity.ok(SuccessResponse.create(WITHDRAW_TEAM_SUCCESS.getMessage(), this.withdrawTeamUserCase.withdrawTeam(user.getSocialId(),teamId))); } + /** + * 소모임 강제 종료, 탈퇴 전 정보 보여주기 + * [GET] api/team/{teamId}/review + * 작성자: 김민수 + */ + @GetMapping("/{teamId}/review") + public ResponseEntity> reviewTeam(@AuthenticationPrincipal User user, + @PathVariable Long teamId) { + return ResponseEntity.ok(SuccessResponse.create(REVIEW_TEAM_SUCCESS.getMessage(), this.reviewTeamUserCase.reviewTeam(user.getSocialId(), teamId))); + } + + /** * 소모임 수정 (소모임장) * [POST] api/team/{teamId} diff --git a/src/main/java/com/moing/backend/domain/team/presentation/constant/TeamResponseMessage.java b/src/main/java/com/moing/backend/domain/team/presentation/constant/TeamResponseMessage.java index 6a9846e6..d400e9f4 100644 --- a/src/main/java/com/moing/backend/domain/team/presentation/constant/TeamResponseMessage.java +++ b/src/main/java/com/moing/backend/domain/team/presentation/constant/TeamResponseMessage.java @@ -11,6 +11,7 @@ public enum TeamResponseMessage { GET_TEAM_DETAIL_SUCCESS("목표보드를 조회했습니다."), SIGNIN_TEAM_SUCCESS("소모임에 가입하였습니다."), GET_CURRENT_STATUS_SUCCESS("소모임 수정 전 조회했습니다."), + REVIEW_TEAM_SUCCESS("소모임 삭제 전 조회했습니다."), DISBAND_TEAM_SUCCESS("[소모임장 권한] 소모임을 강제 종료했습니다."), UPDATE_TEAM_SUCCESS("[소모임장 권한] 소모임을 수정했습니다"), WITHDRAW_TEAM_SUCCESS("[소모임원 권한] 소모임을 탈퇴하였습니다"), diff --git a/src/main/java/com/moing/backend/global/config/security/filter/JwtAuthenticationEntryPoint.java b/src/main/java/com/moing/backend/global/config/security/filter/JwtAuthenticationEntryPoint.java index 89133842..eef927a8 100644 --- a/src/main/java/com/moing/backend/global/config/security/filter/JwtAuthenticationEntryPoint.java +++ b/src/main/java/com/moing/backend/global/config/security/filter/JwtAuthenticationEntryPoint.java @@ -22,27 +22,37 @@ public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { String exception = String.valueOf(request.getAttribute("exception")); - log.info("commonce:" + exception); + log.info("commence:" + exception); - if (exception.equals(JwtExceptionList.ADDITIONAL_REQUIRED_TOKEN.getErrorCode())) - setResponse(response, JwtExceptionList.ADDITIONAL_REQUIRED_TOKEN); + switch (exception) { + case "J0007": + setResponse(response, JwtExceptionList.ADDITIONAL_REQUIRED_TOKEN); + break; - else if (exception.equals(JwtExceptionList.UNKNOWN_ERROR.getErrorCode())) - setResponse(response, JwtExceptionList.UNKNOWN_ERROR); + case "J0001": + setResponse(response, JwtExceptionList.UNKNOWN_ERROR); + break; - else if (exception.equals(JwtExceptionList.MAL_FORMED_TOKEN.getErrorCode())) - setResponse(response, JwtExceptionList.MAL_FORMED_TOKEN); + case "J0002": + setResponse(response, JwtExceptionList.MAL_FORMED_TOKEN); + break; - else if (exception.equals(JwtExceptionList.ILLEGAL_TOKEN.getErrorCode())) - setResponse(response, JwtExceptionList.ILLEGAL_TOKEN); + case "J0006": + setResponse(response, JwtExceptionList.ILLEGAL_TOKEN); + break; - else if (exception.equals(JwtExceptionList.EXPIRED_TOKEN.getErrorCode())) - setResponse(response, JwtExceptionList.EXPIRED_TOKEN); + case "J0003": + setResponse(response, JwtExceptionList.EXPIRED_TOKEN); + break; - else if (exception.equals(JwtExceptionList.UNSUPPORTED_TOKEN.getErrorCode())) - setResponse(response, JwtExceptionList.UNSUPPORTED_TOKEN); + case "J0004": + setResponse(response, JwtExceptionList.UNSUPPORTED_TOKEN); + break; - else setResponse(response, JwtExceptionList.ACCESS_DENIED); + default: + setResponse(response, JwtExceptionList.ACCESS_DENIED); + break; + } } 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 0b807654..869e763c 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 @@ -42,6 +42,8 @@ public class TeamControllerTest extends CommonControllerTest { private SignInTeamUserCase signInTeamUserCase; @MockBean private UpdateTeamUserCase updateTeamUserCase; + @MockBean + private ReviewTeamUserCase reviewTeamUserCase; @Test public void create_team() throws Exception { @@ -245,10 +247,10 @@ public void get_team_detail() throws Exception { } @Test - public void disband_team() throws Exception { + public void review_team() throws Exception { //given Long teamId = 1L; // 예시 ID - DeleteTeamResponse output = DeleteTeamResponse.builder() + ReviewTeamResponse output = ReviewTeamResponse.builder() .teamId(teamId) .teamName("팀 이름") .numOfMember(9) @@ -257,13 +259,13 @@ public void disband_team() throws Exception { .levelOfFire(3) .build(); - given(disbandTeamUserCase.disbandTeam(any(), any())).willReturn(output); + given(reviewTeamUserCase.reviewTeam(any(), any())).willReturn(output); //when ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. - delete("/api/team/{teamId}/disband", teamId) - .header("Authorization", "Bearer ACCESS_TOKEN") - .contentType(MediaType.APPLICATION_JSON) + get("/api/team/{teamId}/review", teamId) + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) ); //then @@ -279,8 +281,8 @@ public void disband_team() throws Exception { ), responseFields( fieldWithPath("isSuccess").description("true"), - fieldWithPath("message").description("[소모임장 권한] 소모임을 강제 종료했습니다."), - fieldWithPath("data.teamId").description("강제종료한 소모임 id"), + fieldWithPath("message").description("소모임 삭제 전 조회했습니다."), + fieldWithPath("data.teamId").description("삭제할 소모임 id"), fieldWithPath("data.teamName").description("소모임 이름"), fieldWithPath("data.numOfMember").description("모임원 명 수"), fieldWithPath("data.duration").description("소모임과 함께한 시간"), @@ -290,17 +292,49 @@ public void disband_team() throws Exception { ) ); } + + @Test + public void disband_team() throws Exception { + //given + Long teamId = 1L; // 예시 ID + DeleteTeamResponse output = DeleteTeamResponse.builder() + .teamId(teamId) + .build(); + + given(disbandTeamUserCase.disbandTeam(any(), any())).willReturn(output); + + //when + ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. + delete("/api/team/{teamId}/disband", 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.teamId").description("강제종료한 소모임 id") + ) + ) + ); + } @Test public void withdraw_team() throws Exception { //given Long teamId = 1L; // 예시 ID DeleteTeamResponse output = DeleteTeamResponse.builder() .teamId(teamId) - .teamName("팀 이름") - .numOfMember(9) - .duration(30L) - .numOfMission(90L) - .levelOfFire(3) .build(); given(withdrawTeamUserCase.withdrawTeam(any(), any())).willReturn(output); @@ -326,12 +360,7 @@ public void withdraw_team() throws Exception { responseFields( fieldWithPath("isSuccess").description("true"), fieldWithPath("message").description("[소모임원 권한] 소모임을 탈퇴하였습니다"), - fieldWithPath("data.teamId").description("탈퇴한 소모임 id"), - fieldWithPath("data.teamName").description("소모임 이름"), - fieldWithPath("data.numOfMember").description("모임원 명 수"), - fieldWithPath("data.duration").description("소모임과 함께한 시간"), - fieldWithPath("data.levelOfFire").description("소모임 불꽃 레벨"), - fieldWithPath("data.numOfMission").description("미션 총 개수") + fieldWithPath("data.teamId").description("탈퇴한 소모임 id") ) ) );