Skip to content

Commit 63b11a9

Browse files
authored
AIM-76-서버-2차-리팩토링 (#68)
* refact: 챌린지 목록 조회 최적화 * refact: 게시글 목록 조회 최적화
1 parent e0397dc commit 63b11a9

32 files changed

+1650
-3024
lines changed

src/main/java/targeter/aim/domain/challenge/controller/ChallengeController.java

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
import jakarta.validation.Valid;
77
import lombok.RequiredArgsConstructor;
88
import org.springdoc.core.annotations.ParameterObject;
9-
import org.springframework.data.domain.Pageable;
10-
import org.springframework.data.web.PageableDefault;
119
import org.springframework.http.HttpStatus;
1210
import org.springframework.http.MediaType;
1311
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1412
import org.springframework.web.bind.annotation.*;
1513
import targeter.aim.domain.challenge.dto.ChallengeDto;
1614
import targeter.aim.domain.challenge.entity.ChallengeMode;
17-
import targeter.aim.domain.challenge.repository.AllChallengeSortType;
18-
import targeter.aim.domain.challenge.repository.SortOrder;
1915
import targeter.aim.domain.challenge.service.ChallengeService;
2016
import targeter.aim.system.security.annotation.NoJwtAuth;
2117
import targeter.aim.system.security.model.UserDetails;
@@ -44,33 +40,6 @@ public ChallengeDto.ChallengeIdResponse createChallenge(
4440
return challengeService.createChallenge(userDetails, request);
4541
}
4642

47-
@NoJwtAuth
48-
@GetMapping("/vs")
49-
@Operation(
50-
summary = "VS 챌린지 목록 조회",
51-
description = "VS 챌린지 목록을 탭(ALL/MY)과 정렬 조건에 따라 페이지네이션 조회합니다."
52-
)
53-
public ChallengeDto.ChallengePageResponse getVsChallenges(
54-
@ModelAttribute @ParameterObject ChallengeDto.ListSearchCondition condition,
55-
@PageableDefault(size = 16) @ParameterObject Pageable pageable,
56-
@AuthenticationPrincipal UserDetails userDetails
57-
) {
58-
return challengeService.getVsChallenges(condition, userDetails, pageable);
59-
}
60-
61-
@NoJwtAuth("VS 챌린지 상세 조회는 인증을 필요로 하지 않음")
62-
@GetMapping("/vs/{challengeId}/overview")
63-
@Operation(
64-
summary = "VS 챌린지 상세 Overview 조회",
65-
description = "특정 VS 챌린지의 상세 정보와 우세현황 및 챌린지 멤버 정보를 조회합니다."
66-
)
67-
public ChallengeDto.VsChallengeOverviewResponse getVsChallengeOverview(
68-
@PathVariable Long challengeId,
69-
@AuthenticationPrincipal UserDetails userDetails
70-
) {
71-
return challengeService.getVsChallengeOverview(challengeId, userDetails);
72-
}
73-
7443
@NoJwtAuth("VS 결과는 비로그인 유저도 열람 가능")
7544
@GetMapping("/vs/{challengeId}/result")
7645
@Operation(
@@ -83,30 +52,6 @@ public ChallengeDto.VsResultResponse getVsResult(
8352
return challengeService.getVsChallengeResult(challengeId);
8453
}
8554

86-
@GetMapping("/solo")
87-
@Operation(
88-
summary = "SOLO 챌린지 목록 조회",
89-
description = "로그인한 사용자가 SOLO 챌린지 목록을 탭(진행 중/진행 완료)과 정렬 조건에 따라 페이지네이션 조회합니다."
90-
)
91-
public ChallengeDto.ChallengePageResponse getSoloChallenges(
92-
@ModelAttribute @ParameterObject ChallengeDto.SoloChallengeListRequest request,
93-
@AuthenticationPrincipal UserDetails userDetails
94-
) {
95-
return challengeService.getSoloChallenges(request, userDetails);
96-
}
97-
98-
@GetMapping("/solo/{challengeId}/overview")
99-
@Operation(
100-
summary = "SOLO 챌린지 상세 Overview 조회",
101-
description = "로그인한 사용자가 특정 SOLO 챌린지의 상세 정보와 주최자 진행 현황을 조회합니다."
102-
)
103-
public ChallengeDto.SoloChallengeOverviewResponse getSoloChallengeOverview(
104-
@PathVariable Long challengeId,
105-
@AuthenticationPrincipal UserDetails userDetails
106-
) {
107-
return challengeService.getSoloChallengeOverview(challengeId, userDetails);
108-
}
109-
11055
@PatchMapping(value = "/{challengeId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
11156
@Operation(
11257
summary = "챌린지 수정",
@@ -146,27 +91,6 @@ public List<ChallengeDto.ChallengeToPostResponse> getChallengeForPost(
14691
return challengeService.getChallengeToPost(mode, userDetails);
14792
}
14893

149-
@GetMapping("/all")
150-
@Operation(
151-
summary = "ALL 챌린지 목록 조회",
152-
description = "로그인한 사용자가 참여한 모든 SOLO/VS 챌린지를 정렬 조건과 함께 조회합니다."
153-
)
154-
public ChallengeDto.ChallengePageResponse getAllChallenges(
155-
@AuthenticationPrincipal UserDetails userDetails,
156-
@RequestParam(defaultValue = "CREATED_AT") AllChallengeSortType sort,
157-
@RequestParam(defaultValue = "DESC") SortOrder order,
158-
@PageableDefault(size = 8) @ParameterObject Pageable pageable
159-
) {
160-
var page = challengeService.getAllChallenges(
161-
userDetails,
162-
pageable,
163-
sort,
164-
order
165-
);
166-
167-
return ChallengeDto.ChallengePageResponse.from(page);
168-
}
169-
17094
@GetMapping("/records")
17195
@Operation(
17296
summary = "유저 챌린지 기록 조회",
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package targeter.aim.domain.challenge.controller;
2+
3+
import io.swagger.v3.oas.annotations.Operation;
4+
import io.swagger.v3.oas.annotations.tags.Tag;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springdoc.core.annotations.ParameterObject;
7+
import org.springframework.data.domain.Pageable;
8+
import org.springframework.data.web.PageableDefault;
9+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
10+
import org.springframework.web.bind.annotation.*;
11+
import targeter.aim.domain.challenge.dto.ChallengeDto;
12+
import targeter.aim.domain.challenge.service.ChallengeReadService;
13+
import targeter.aim.system.security.annotation.NoJwtAuth;
14+
import targeter.aim.system.security.model.UserDetails;
15+
16+
@RestController
17+
@RequiredArgsConstructor
18+
@RequestMapping("/api/challenges")
19+
@Tag(name = "Challenge (Read)", description = "챌린지 조회 및 검색 관련 API")
20+
public class ChallengeReadController {
21+
22+
private final ChallengeReadService challengeService;
23+
24+
@NoJwtAuth
25+
@GetMapping("/vs")
26+
@Operation(
27+
summary = "VS 챌린지 목록 조회",
28+
description = "VS 챌린지 목록을 탭(ALL/MY)과 정렬 조건에 따라 페이지네이션 조회합니다."
29+
)
30+
public ChallengeDto.ChallengePageResponse getVsChallenges(
31+
@ModelAttribute @ParameterObject ChallengeDto.VsListSearchCondition condition,
32+
@PageableDefault(size = 16) @ParameterObject Pageable pageable,
33+
@AuthenticationPrincipal UserDetails userDetails
34+
) {
35+
return challengeService.getVsChallenges(condition, userDetails, pageable);
36+
}
37+
38+
@NoJwtAuth("VS 챌린지 상세 조회는 인증을 필요로 하지 않음")
39+
@GetMapping("/vs/{challengeId}/overview")
40+
@Operation(
41+
summary = "VS 챌린지 상세 Overview 조회",
42+
description = "특정 VS 챌린지의 상세 정보와 우세현황 및 챌린지 멤버 정보를 조회합니다."
43+
)
44+
public ChallengeDto.VsChallengeOverviewResponse getVsChallengeOverview(
45+
@PathVariable Long challengeId,
46+
@AuthenticationPrincipal UserDetails userDetails
47+
) {
48+
return challengeService.getVsChallengeOverview(challengeId, userDetails);
49+
}
50+
51+
@GetMapping("/solo")
52+
@Operation(
53+
summary = "SOLO 챌린지 목록 조회",
54+
description = "로그인한 사용자가 SOLO 챌린지 목록을 탭(진행 중/진행 완료)과 정렬 조건에 따라 페이지네이션 조회합니다."
55+
)
56+
public ChallengeDto.ChallengePageResponse getSoloChallenges(
57+
@ModelAttribute @ParameterObject ChallengeDto.SoloListSearchCondition request,
58+
@PageableDefault(size = 16) @ParameterObject Pageable pageable,
59+
@AuthenticationPrincipal UserDetails userDetails
60+
) {
61+
return challengeService.getSoloChallenges(request, userDetails, pageable);
62+
}
63+
64+
@GetMapping("/solo/{challengeId}/overview")
65+
@Operation(
66+
summary = "SOLO 챌린지 상세 Overview 조회",
67+
description = "로그인한 사용자가 특정 SOLO 챌린지의 상세 정보와 주최자 진행 현황을 조회합니다."
68+
)
69+
public ChallengeDto.SoloChallengeOverviewResponse getSoloChallengeOverview(
70+
@PathVariable Long challengeId,
71+
@AuthenticationPrincipal UserDetails userDetails
72+
) {
73+
return challengeService.getSoloChallengeOverview(challengeId, userDetails);
74+
}
75+
76+
@GetMapping("/all")
77+
@Operation(
78+
summary = "ALL 챌린지 목록 조회",
79+
description = "로그인한 사용자가 참여한 모든 SOLO/VS 챌린지를 정렬 조건과 함께 조회합니다."
80+
)
81+
public ChallengeDto.ChallengePageResponse getAllChallenges(
82+
@ModelAttribute @ParameterObject ChallengeDto.AllListSearchCondition request,
83+
@PageableDefault(size = 16) @ParameterObject Pageable pageable,
84+
@AuthenticationPrincipal UserDetails userDetails
85+
) {
86+
return challengeService.getAllChallenges(request, userDetails, pageable);
87+
}
88+
}

src/main/java/targeter/aim/domain/challenge/controller/WeeklyCommentController.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88
import org.springframework.http.MediaType;
99
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1010
import org.springframework.web.bind.annotation.*;
11-
import org.springframework.web.multipart.MultipartFile;
1211
import targeter.aim.domain.challenge.dto.WeeklyCommentDto;
1312
import targeter.aim.domain.challenge.repository.CommentSortType;
14-
import targeter.aim.domain.challenge.repository.SortOrder;
1513
import targeter.aim.domain.challenge.service.WeeklyCommentService;
1614
import targeter.aim.system.security.model.UserDetails;
1715

18-
import java.util.List;
19-
2016
@RestController
2117
@RequiredArgsConstructor
2218
@RequestMapping("/api/challenges/{challengeId}/weeks/{weeksId}/comments")
@@ -41,26 +37,26 @@ public WeeklyCommentDto.WeeklyCommentCreateResponse createWeeklyComment(
4137
);
4238
}
4339

44-
@GetMapping
45-
@Operation(
46-
summary = "챌린지 주차별 댓글 목록 조회",
47-
description = "챌린지의 특정 주차(weeks)에 작성된 댓글 목록(부모/대댓글)을 최신순으로 조회합니다."
48-
)
49-
public WeeklyCommentDto.WeeklyCommentListResponse getWeeklyComments(
50-
@PathVariable Long challengeId,
51-
@PathVariable Long weeksId,
52-
@Parameter(description = "정렬 기준", example = "LATEST")
53-
@RequestParam(defaultValue = "LATEST") CommentSortType sort,
54-
@Parameter(description = "정렬 방향", example = "DESC")
55-
@RequestParam(defaultValue = "DESC") SortOrder order,
56-
@Parameter(description = "페이지 번호(0부터 시작)", example = "0")
57-
@RequestParam(defaultValue = "0") int page,
58-
@Parameter(description = "페이지 크기", example = "10")
59-
@RequestParam(defaultValue = "10") int size,
60-
@AuthenticationPrincipal UserDetails userDetails
61-
) {
62-
return weeklyCommentService.getWeeklyComments(
63-
challengeId, weeksId, sort, order, page, size, userDetails
64-
);
65-
}
40+
// @GetMapping
41+
// @Operation(
42+
// summary = "챌린지 주차별 댓글 목록 조회",
43+
// description = "챌린지의 특정 주차(weeks)에 작성된 댓글 목록(부모/대댓글)을 최신순으로 조회합니다."
44+
// )
45+
// public WeeklyCommentDto.WeeklyCommentListResponse getWeeklyComments(
46+
// @PathVariable Long challengeId,
47+
// @PathVariable Long weeksId,
48+
// @Parameter(description = "정렬 기준", example = "LATEST")
49+
// @RequestParam(defaultValue = "LATEST") CommentSortType sort,
50+
// @Parameter(description = "정렬 방향", example = "DESC")
51+
// @RequestParam(defaultValue = "DESC") SortOrder order,
52+
// @Parameter(description = "페이지 번호(0부터 시작)", example = "0")
53+
// @RequestParam(defaultValue = "0") int page,
54+
// @Parameter(description = "페이지 크기", example = "10")
55+
// @RequestParam(defaultValue = "10") int size,
56+
// @AuthenticationPrincipal UserDetails userDetails
57+
// ) {
58+
// return weeklyCommentService.getWeeklyComments(
59+
// challengeId, weeksId, sort, order, page, size, userDetails
60+
// );
61+
// }
6662
}

0 commit comments

Comments
 (0)