From f3e433c7e0979537e01f2626bebff2537fe439fa Mon Sep 17 00:00:00 2001 From: jainefer Date: Thu, 21 Nov 2024 20:47:49 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EA=B2=8C=EC=8B=9C=EB=AC=BC=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../borrowPosts/controller/PostsController.java | 17 +++++++++++++++-- .../borrowPosts/ItemDslRepositoryImpl.java | 10 +++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/site/billbill/apiserver/api/borrowPosts/controller/PostsController.java b/src/main/java/site/billbill/apiserver/api/borrowPosts/controller/PostsController.java index 0b26855..55e2962 100644 --- a/src/main/java/site/billbill/apiserver/api/borrowPosts/controller/PostsController.java +++ b/src/main/java/site/billbill/apiserver/api/borrowPosts/controller/PostsController.java @@ -1,11 +1,15 @@ package site.billbill.apiserver.api.borrowPosts.controller; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.jboss.logging.MDC; import org.springframework.data.domain.Sort; +import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import site.billbill.apiserver.api.borrowPosts.dto.request.PostsRequest; import site.billbill.apiserver.api.borrowPosts.dto.response.PostsResponse; @@ -31,9 +35,18 @@ public BaseResponse uploadPostsController(@Request return new BaseResponse<>(postsService.uploadPostService(request,userId)); } + @Operation(summary = "게시물리스트", description = "게시물 리스트 조회 API") + @ResponseStatus(HttpStatus.OK) @GetMapping("") - public BaseResponse getPostsController(@RequestParam(value ="category",required = false,defaultValue = "entire") String category, - @RequestParam(value ="page",required = false,defaultValue = "1") int page, @RequestParam(value ="order",required = false,defaultValue = "desc") String order,@RequestParam(value="sortBy",required = true,defaultValue = "accuracy") String sortBy){ + public BaseResponse getPostsController( + @Parameter(name = "category", description = "카테고리 필터 (예: entire, camp, sports,tools )", example = "entire", in = ParameterIn.QUERY, required = false) + @RequestParam(value ="category",required = false,defaultValue = "entire") String category, + @Parameter(name = "page", description = "페이지 번호 (1부터 시작)", example = "1", in = ParameterIn.QUERY, required = false) + @RequestParam(value ="page",required = false,defaultValue = "1") int page, + @Parameter(name = "order", description = "정렬 방향 (asc: 오름차순, desc: 내림차순)", example = "desc", in = ParameterIn.QUERY, required = false) + @RequestParam(value ="order",required = false,defaultValue = "desc") String order, + @Parameter(name = "sortBy", description = "정렬 기준 (예: price, createdAt, likeCount)", example = "createdAt", in = ParameterIn.QUERY, required = true) + @RequestParam(value="sortBy",required = true,defaultValue = "accuracy") String sortBy){ Sort.Direction direction = "asc".equalsIgnoreCase(order) ? Sort.Direction.ASC : Sort.Direction.DESC; diff --git a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepositoryImpl.java b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepositoryImpl.java index c58f394..a9722b9 100644 --- a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepositoryImpl.java +++ b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepositoryImpl.java @@ -46,31 +46,31 @@ public Page findItemsWithConditions(String category, Pageable pa } // 정렬 조건 - if (sortField != null && !"price".equals(sortField)) { // price 테스트 제외 + if (sortField != null) { OrderSpecifier orderSpecifier = getOrderSpecifier(sortField, pageable.getSort().getOrderFor(sortField)); if (orderSpecifier != null) { query.orderBy(orderSpecifier); } else { log.warn("Invalid sort field: {}, no sorting applied.", sortField); } - } +} // 페이징 처리 List content = query.offset(pageable.getOffset()) .limit(pageable.getPageSize()) .fetch(); - log.info("Fetched Content Size: {}", content.size()); + log.info("얻은 콘텐츠 사이즈: {}", content.size()); long total = queryFactory.selectFrom(items) .where(items.delYn.isFalse()) .fetchCount(); - log.info("Total Items Count: {}", total); + log.info("아이템의 사이즈: {}", total); // 페이징 초과 방지 if (pageable.getOffset() >= total) { - log.warn("Requested page exceeds total items. Returning empty result."); + log.warn("전체 아이템보다 요구 페이지가 많습빈다."); return new PageImpl<>(List.of(), pageable, total); }