Skip to content

Commit

Permalink
Merge branch 'feature/borrowPosts' of https://github.com/billbill-pro…
Browse files Browse the repository at this point in the history
…ject/bill-api-server into feature/borrowPosts
  • Loading branch information
jainefer committed Nov 22, 2024
2 parents 50629de + f3e433c commit ca2b178
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -31,9 +35,18 @@ public BaseResponse<PostsResponse.UploadResponse> uploadPostsController(@Request
return new BaseResponse<>(postsService.uploadPostService(request,userId));

}
@Operation(summary = "게시물리스트", description = "게시물 리스트 조회 API")
@ResponseStatus(HttpStatus.OK)
@GetMapping("")
public BaseResponse<PostsResponse.ViewAllResultResponse> 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<PostsResponse.ViewAllResultResponse> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,31 @@ public Page<ItemsJpaEntity> 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<ItemsJpaEntity> 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);
}

Expand Down

0 comments on commit ca2b178

Please sign in to comment.