Skip to content

Commit 49b1fab

Browse files
committed
feat: 소모임 개수와 이름 조회 기능 추가
1 parent 3c03f17 commit 49b1fab

File tree

10 files changed

+105
-1
lines changed

10 files changed

+105
-1
lines changed

src/docs/asciidoc/Team-API.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ operation::team-controller-test/disband_team[snippets='http-request,path-paramet
6060
[[Team-소모임-탈퇴]]
6161
== Team 소모임원 강제종료
6262
operation::team-controller-test/withdraw_team[snippets='http-request,path-parameters,http-response,response-fields']
63+
64+
[[Team-소모임-개수_이름-조회]]
65+
== Team 소모임 개수 이름 조회
66+
operation::team-controller-test/get_team_count[snippets='http-request,path-parameters,http-response,response-fields']
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.moing.backend.domain.team.application.dto.response;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
7+
@Getter
8+
@Builder
9+
@AllArgsConstructor
10+
public class GetTeamCountResponse {
11+
12+
private String teamName;
13+
private Long numOfTeam;
14+
15+
}

src/main/java/com/moing/backend/domain/team/application/dto/response/TeamBlock.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@Builder
1919
@NoArgsConstructor
2020
public class TeamBlock {
21+
2122
private Long teamId;
2223
private Long duration; //걸린시간(단위:날짜)
2324
private Integer levelOfFire; //불꽃 레벨

src/main/java/com/moing/backend/domain/team/application/service/GetTeamUseCase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@ public GetCurrentStatusResponse getCurrentStatus(Long teamId) {
4747
public Page<GetNewTeamResponse> getNewTeam(String dateSort, Pageable pageable) {
4848
return teamGetService.getNewTeams(dateSort, pageable);
4949
}
50+
51+
public GetTeamCountResponse getTeamCount(String socialId, Long teamId) {
52+
Member member = memberGetService.getMemberBySocialId(socialId);
53+
return teamGetService.getTeamCountAndName(teamId, member.getMemberId());
54+
}
5055
}

src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.moing.backend.domain.mypage.application.dto.response.GetMyPageTeamBlock;
55
import com.moing.backend.domain.team.application.dto.response.GetLeaderInfoResponse;
66
import com.moing.backend.domain.team.application.dto.response.GetNewTeamResponse;
7+
import com.moing.backend.domain.team.application.dto.response.GetTeamCountResponse;
78
import com.moing.backend.domain.team.application.dto.response.GetTeamResponse;
89
import com.moing.backend.domain.team.domain.entity.Team;
910
import org.springframework.data.domain.Page;
@@ -21,4 +22,5 @@ public interface TeamCustomRepository {
2122
void updateTeamStatus(boolean isApproved, List<Long> teamIds);
2223
List<GetLeaderInfoResponse> findLeaderInfoByTeamIds(List<Long> teamIds);
2324
Page<GetNewTeamResponse> findNewTeam(String dateSort, Pageable pageable);
25+
Long findTeamCount(Long memberId);
2426
}

src/main/java/com/moing/backend/domain/team/domain/repository/TeamCustomRepositoryImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,21 @@ public Page<GetNewTeamResponse> findNewTeam(String dateSort, Pageable pageable)
177177
return PageableExecutionUtils.getPage(teams, pageable, () -> count);
178178
}
179179

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

181197
}

src/main/java/com/moing/backend/domain/team/domain/service/TeamGetService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.moing.backend.domain.mypage.application.dto.response.GetMyPageTeamBlock;
66
import com.moing.backend.domain.team.application.dto.response.GetLeaderInfoResponse;
77
import com.moing.backend.domain.team.application.dto.response.GetNewTeamResponse;
8+
import com.moing.backend.domain.team.application.dto.response.GetTeamCountResponse;
89
import com.moing.backend.domain.team.application.dto.response.GetTeamResponse;
910
import com.moing.backend.domain.team.domain.entity.Team;
1011
import com.moing.backend.domain.team.domain.repository.TeamRepository;
@@ -55,4 +56,10 @@ public Page<GetNewTeamResponse> getNewTeams(String dateSort, Pageable pageable)
5556
return teamRepository.findNewTeam(dateSort, pageable);
5657
}
5758

59+
public GetTeamCountResponse getTeamCountAndName(Long teamId, Long memberId) {
60+
String teamName = getTeamByTeamId(teamId).getName();
61+
Long numOfTeam = teamRepository.findTeamCount(memberId);
62+
return new GetTeamCountResponse(teamName, numOfTeam);
63+
}
64+
5865
}

src/main/java/com/moing/backend/domain/team/presentation/TeamController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,14 @@ public ResponseEntity<SuccessResponse<GetCurrentStatusResponse>> getCurrentStatu
127127
return ResponseEntity.ok(SuccessResponse.create(GET_CURRENT_STATUS_SUCCESS.getMessage(), this.getTeamUseCase.getCurrentStatus(teamId)));
128128
}
129129

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

src/main/java/com/moing/backend/domain/team/presentation/constant/TeamResponseMessage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public enum TeamResponseMessage {
1717
WITHDRAW_TEAM_SUCCESS("[소모임원 권한] 소모임을 탈퇴하였습니다"),
1818
SEND_APPROVAL_ALARM_SUCCESS("소모임들이 승인되었습니다."),
1919
SEND_REJECTION_ALARM_SUCCESS("소모임들이 반려되었습니다."),
20-
GET_NEW_TEAM_SUCCESS("새로운 소모임들을 조회했습니다.");
20+
GET_NEW_TEAM_SUCCESS("새로운 소모임들을 조회했습니다."),
21+
GET_TEAM_COUNT_SUCCESS("소모임의 개수와 닉네임을 조회했습니다.");
2122
private final String message;
2223
}

src/test/java/com/moing/backend/domain/team/presentation/TeamControllerTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,4 +507,47 @@ public void get_current_status() throws Exception {
507507
);
508508
}
509509

510+
@Test
511+
public void get_team_count() throws Exception {
512+
513+
// given
514+
Long teamId = 1L;
515+
516+
GetTeamCountResponse output = GetTeamCountResponse.builder()
517+
.teamName("소모임 이름")
518+
.numOfTeam(2L)
519+
.build();
520+
521+
given(getTeamUseCase.getTeamCount(any(), any())).willReturn(output);
522+
523+
524+
//when
525+
ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders.
526+
get("/api/team/{teamId}/count", teamId)
527+
.header("Authorization", "Bearer ACCESS_TOKEN")
528+
.contentType(MediaType.APPLICATION_JSON)
529+
);
530+
531+
532+
//then
533+
actions
534+
.andExpect(status().isOk())
535+
.andDo(
536+
restDocs.document(
537+
requestHeaders(
538+
headerWithName("Authorization").description("접근 토큰")
539+
),
540+
pathParameters(
541+
parameterWithName("teamId").description("팀 아이디")
542+
),
543+
responseFields(
544+
fieldWithPath("isSuccess").description("true"),
545+
fieldWithPath("message").description("소모임을 수정했습니다."),
546+
fieldWithPath("data.teamName").description("소모임 이름"),
547+
fieldWithPath("data.numOfTeam").description("지금까지 가입한 소모임 개수")
548+
)
549+
)
550+
);
551+
}
552+
510553
}

0 commit comments

Comments
 (0)