Skip to content

Commit

Permalink
Merge pull request #47 from Modagbul/feat/마이페이지
Browse files Browse the repository at this point in the history
feat: 소모임 삭제 전 조회 API 추가
  • Loading branch information
minsu20 authored Oct 29, 2023
2 parents e29c7a8 + 69fff58 commit a12dbbd
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ data.sql

#### docs ####
!**/src/main/resources/static/docs/
*.html
*.html
2 changes: 1 addition & 1 deletion src/docs/asciidoc/Auth-API.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ operation::auth-controller-test/google_소셜_로그인_회원가입_후[snippet


[[Auth-회원가입]]
=== Auth 회원가입
== Auth 회원가입
|===
| 성별
| `MAN`
Expand Down
4 changes: 4 additions & 0 deletions src/docs/asciidoc/Team-API.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; //불꽃 레벨
}
Original file line number Diff line number Diff line change
@@ -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; //불꽃 레벨
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class TeamController {
private final DisbandTeamUserCase disbandTeamUserCase;
private final WithdrawTeamUserCase withdrawTeamUserCase;
private final UpdateTeamUserCase updateTeamUserCase;
private final ReviewTeamUserCase reviewTeamUserCase;

/**
* 소모임 생성 (only 개설만)
Expand Down Expand Up @@ -92,6 +93,18 @@ public ResponseEntity<SuccessResponse<DeleteTeamResponse>> 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<SuccessResponse<ReviewTeamResponse>> 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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("[소모임원 권한] 소모임을 탈퇴하였습니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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("소모임과 함께한 시간"),
Expand All @@ -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);
Expand All @@ -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")
)
)
);
Expand Down

0 comments on commit a12dbbd

Please sign in to comment.