Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public ResponseEntity<ApiResponse<PostStatsResponseDTO>> getPostStats(

@Operation(
summary = "카테고리별 기록 리스트 조회 API (마이페이지 기록장 상세)",
description = "특정 카테고리에 작성된 기록들을 조회합니다. 최신순, 오래된순, 평점 높은순, 평점 낮은순으로 정렬할 수 있습니다." +
description = "특정 카테고리에 작성된 기록들을 조회합니다. userId 쿼리 파라미터가 없으면 본인, 있으면 해당 사용자의 기록을 조회합니다. " +
"최신순, 오래된순, 평점 높은순, 평점 낮은순으로 정렬할 수 있습니다." +
"<br><br>[enum] 정렬 옵션 (sortBy):" +
"<br>- LATEST: 최신순 (기본값)" +
"<br>- OLDEST: 오래된순" +
Expand All @@ -125,12 +126,15 @@ public ResponseEntity<ApiResponse<PostStatsResponseDTO>> getPostStats(
})
@GetMapping("/post-stats/{categoryId}")
public ResponseEntity<ApiResponse<CategoryPostListResponseDTO>> getCategoryPostList(
@AuthenticationPrincipal UserDetails userDetails,
@PathVariable Long categoryId,
@RequestParam(required = false) Long userId,
@RequestParam(defaultValue = "LATEST") String sortBy,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size) {

CategoryPostListResponseDTO categoryPostListResponseDTO = memberService.getCategoryPostList(categoryId, sortBy, page, size);
CategoryPostListResponseDTO categoryPostListResponseDTO =
memberService.getCategoryPostList(userDetails.getUsername(), userId, categoryId, sortBy, page, size);
return ApiResponse.success(SuccessStatus.GET_CATEGORY_POST_LIST_SUCCESS, categoryPostListResponseDTO);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,23 @@ public NicknameCheckResponseDTO checkNicknameDuplicate(String nickname) {

// 카테고리별 기록 리스트 조회
@Transactional(readOnly = true)
public CategoryPostListResponseDTO getCategoryPostList(Long categoryId, String sortBy, Integer page, Integer size) {
public CategoryPostListResponseDTO getCategoryPostList(String email, Long userId, Long categoryId, String sortBy, Integer page, Integer size) {

Member currentMember = getMemberByEmail(email);
Member targetMember = (userId == null)
? currentMember
: memberRepository.findById(userId)
.orElseThrow(() -> new NotFoundException(ErrorStatus.USER_NOTFOUND_EXCEPTION.getMessage()));

// 카테고리 존재 여부 확인
categoryRepository.findById(categoryId)
Category category = categoryRepository.findById(categoryId)
.orElseThrow(() -> new NotFoundException(ErrorStatus.CATEGORY_NOTFOUND_EXCEPTION.getMessage()));

// 카테고리 소유자 확인 (userId가 없으면 본인 기준)
if (!category.getMember().getId().equals(targetMember.getId())) {
throw new NotFoundException(ErrorStatus.CATEGORY_NOTFOUND_EXCEPTION.getMessage());
}

Pageable pageable = PageRequest.of(page - 1, size);

// 정렬 조건에 따라 조회
Expand All @@ -318,8 +329,8 @@ public CategoryPostListResponseDTO getCategoryPostList(Long categoryId, String s
.map(this::convertToCategoryPostDetailDTO)
.collect(Collectors.toList());

log.info("카테고리별 기록 리스트 조회 완료 - 카테고리 ID: {}, 정렬: {}, 페이지: {}, 결과 수: {}",
categoryId, sortBy, page, postList.size());
log.info("카테고리별 기록 리스트 조회 완료 - 카테고리 ID: {}, 사용자 ID: {}, 정렬: {}, 페이지: {}, 결과 수: {}",
categoryId, targetMember.getId(), sortBy, page, postList.size());

return CategoryPostListResponseDTO.builder()
.total(postPage.getTotalElements())
Expand Down