Skip to content

Commit

Permalink
Merge pull request #92 from Modagbul/fix/auth
Browse files Browse the repository at this point in the history
feat: 소모임 개수와 이름 조회 기능 추가
  • Loading branch information
minsu20 authored Nov 26, 2023
2 parents f4d9356 + 49b1fab commit f85fcb3
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/docs/asciidoc/Team-API.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ operation::team-controller-test/disband_team[snippets='http-request,path-paramet
[[Team-소모임-탈퇴]]
== Team 소모임원 강제종료
operation::team-controller-test/withdraw_team[snippets='http-request,path-parameters,http-response,response-fields']

[[Team-소모임-개수_이름-조회]]
== Team 소모임 개수 이름 조회
operation::team-controller-test/get_team_count[snippets='http-request,path-parameters,http-response,response-fields']
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.moing.backend.domain.team.application.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class GetTeamCountResponse {

private String teamName;
private Long numOfTeam;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@Builder
@NoArgsConstructor
public class TeamBlock {

private Long teamId;
private Long duration; //걸린시간(단위:날짜)
private Integer levelOfFire; //불꽃 레벨
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ public GetCurrentStatusResponse getCurrentStatus(Long teamId) {
public Page<GetNewTeamResponse> getNewTeam(String dateSort, Pageable pageable) {
return teamGetService.getNewTeams(dateSort, pageable);
}

public GetTeamCountResponse getTeamCount(String socialId, Long teamId) {
Member member = memberGetService.getMemberBySocialId(socialId);
return teamGetService.getTeamCountAndName(teamId, member.getMemberId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.moing.backend.domain.mypage.application.dto.response.GetMyPageTeamBlock;
import com.moing.backend.domain.team.application.dto.response.GetLeaderInfoResponse;
import com.moing.backend.domain.team.application.dto.response.GetNewTeamResponse;
import com.moing.backend.domain.team.application.dto.response.GetTeamCountResponse;
import com.moing.backend.domain.team.application.dto.response.GetTeamResponse;
import com.moing.backend.domain.team.domain.entity.Team;
import org.springframework.data.domain.Page;
Expand All @@ -21,4 +22,5 @@ public interface TeamCustomRepository {
void updateTeamStatus(boolean isApproved, List<Long> teamIds);
List<GetLeaderInfoResponse> findLeaderInfoByTeamIds(List<Long> teamIds);
Page<GetNewTeamResponse> findNewTeam(String dateSort, Pageable pageable);
Long findTeamCount(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,21 @@ public Page<GetNewTeamResponse> findNewTeam(String dateSort, Pageable pageable)
return PageableExecutionUtils.getPage(teams, pageable, () -> count);
}

@Override
public Long findTeamCount(Long memberId) {
LocalDateTime threeDaysAgo = LocalDateTime.now().minusDays(3);
return queryFactory
.select(team.count()) // 팀의 개수를 세기 위해 수정
.from(teamMember)
.innerJoin(teamMember.team, team)
.on(teamMember.member.memberId.eq(memberId))
.where(team.approvalStatus.eq(ApprovalStatus.APPROVAL)) // 승인 되었고
.where(teamMember.isDeleted.eq(false) // 탈퇴하지 않았다면
.and(team.isDeleted.eq(false) // 강제종료되지 않았거나
.or(team.deletionTime.after(threeDaysAgo)))) // 강제종료된 경우 3일이 지나지 않았다면
.fetchOne(); // 단일 결과 (개수) 반환

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.moing.backend.domain.mypage.application.dto.response.GetMyPageTeamBlock;
import com.moing.backend.domain.team.application.dto.response.GetLeaderInfoResponse;
import com.moing.backend.domain.team.application.dto.response.GetNewTeamResponse;
import com.moing.backend.domain.team.application.dto.response.GetTeamCountResponse;
import com.moing.backend.domain.team.application.dto.response.GetTeamResponse;
import com.moing.backend.domain.team.domain.entity.Team;
import com.moing.backend.domain.team.domain.repository.TeamRepository;
Expand Down Expand Up @@ -55,4 +56,10 @@ public Page<GetNewTeamResponse> getNewTeams(String dateSort, Pageable pageable)
return teamRepository.findNewTeam(dateSort, pageable);
}

public GetTeamCountResponse getTeamCountAndName(Long teamId, Long memberId) {
String teamName = getTeamByTeamId(teamId).getName();
Long numOfTeam = teamRepository.findTeamCount(memberId);
return new GetTeamCountResponse(teamName, numOfTeam);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,14 @@ public ResponseEntity<SuccessResponse<GetCurrentStatusResponse>> getCurrentStatu
return ResponseEntity.ok(SuccessResponse.create(GET_CURRENT_STATUS_SUCCESS.getMessage(), this.getTeamUseCase.getCurrentStatus(teamId)));
}

/**
* 소모임 닉네임과 소모임 개수 조회
* [GET] api/team/{teamId}/count
*/
@GetMapping("/{teamId}/count")
public ResponseEntity<SuccessResponse<GetTeamCountResponse>> getTeamCount(@AuthenticationPrincipal User user,
@PathVariable Long teamId){
return ResponseEntity.ok(SuccessResponse.create(GET_TEAM_COUNT_SUCCESS.getMessage(), this.getTeamUseCase.getTeamCount(user.getSocialId(),teamId)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum TeamResponseMessage {
WITHDRAW_TEAM_SUCCESS("[소모임원 권한] 소모임을 탈퇴하였습니다"),
SEND_APPROVAL_ALARM_SUCCESS("소모임들이 승인되었습니다."),
SEND_REJECTION_ALARM_SUCCESS("소모임들이 반려되었습니다."),
GET_NEW_TEAM_SUCCESS("새로운 소모임들을 조회했습니다.");
GET_NEW_TEAM_SUCCESS("새로운 소모임들을 조회했습니다."),
GET_TEAM_COUNT_SUCCESS("소모임의 개수와 닉네임을 조회했습니다.");
private final String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,47 @@ public void get_current_status() throws Exception {
);
}

@Test
public void get_team_count() throws Exception {

// given
Long teamId = 1L;

GetTeamCountResponse output = GetTeamCountResponse.builder()
.teamName("소모임 이름")
.numOfTeam(2L)
.build();

given(getTeamUseCase.getTeamCount(any(), any())).willReturn(output);


//when
ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders.
get("/api/team/{teamId}/count", 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.teamName").description("소모임 이름"),
fieldWithPath("data.numOfTeam").description("지금까지 가입한 소모임 개수")
)
)
);
}

}

0 comments on commit f85fcb3

Please sign in to comment.