diff --git a/src/main/java/com/example/WebOrder/controller/ItemController.java b/src/main/java/com/example/WebOrder/controller/ItemController.java index 00fd06bf64..9b335554bf 100644 --- a/src/main/java/com/example/WebOrder/controller/ItemController.java +++ b/src/main/java/com/example/WebOrder/controller/ItemController.java @@ -43,9 +43,10 @@ public String getWholeMenuByOwner(Model model){ //메뉴 상세보기 @GetMapping("/admin/item/detail/{itemId}") - public String getMenuByOwner(@PathVariable("itemId") Long itemId, Model model) { + public String getMenuByOwner(@PathVariable("itemId") Long itemId, Model model, @RequestParam(name="page", defaultValue = "1") Integer page) { model.addAttribute("itemInfo", itemService.getItemInfoById(itemId)); - model.addAttribute("reviewList", reviewService.getReviewsOfItem(itemId, PageRequest.of(0, 10, Sort.Direction.DESC, "id"))); + model.addAttribute("reviewList", reviewService.getReviewsOfItem(itemId, PageRequest.of(page - 1, 10, Sort.Direction.DESC, "id"))); + model.addAttribute("totalPage", reviewService.getNumberOfPages(itemId)); return "item/itemDetail"; } diff --git a/src/main/java/com/example/WebOrder/controller/ReviewController.java b/src/main/java/com/example/WebOrder/controller/ReviewController.java index 06da5248e3..9352d07224 100644 --- a/src/main/java/com/example/WebOrder/controller/ReviewController.java +++ b/src/main/java/com/example/WebOrder/controller/ReviewController.java @@ -39,6 +39,16 @@ public List getReviewOfItem( @PathVariable("itemId") Long itemId, @Re return reviewsOfItem; } + @ResponseBody + @GetMapping("/review/page/{itemId}") + public Integer getReviewPageNumberOfItem( @PathVariable("itemId") Long itemId, @RequestParam(name="page", defaultValue = "1") Integer page){ + Pageable pageable = PageRequest.of(page - 1, 10, Sort.Direction.DESC, "id"); + + Integer pageNumber = reviewService.getReviewPageOfItem(itemId, pageable).getTotalPages(); + + return pageNumber; + } + // 쿠키를 분석해서 주문한 메뉴의 리스트를 보여주는 페이지 @GetMapping("/review/menu/{userId}") public String getReviewMenuPage(HttpServletRequest request, Model model, @PathVariable("userId") Long userId){ diff --git a/src/main/java/com/example/WebOrder/service/ReviewService.java b/src/main/java/com/example/WebOrder/service/ReviewService.java index f36e83c2e5..f14bdc113d 100644 --- a/src/main/java/com/example/WebOrder/service/ReviewService.java +++ b/src/main/java/com/example/WebOrder/service/ReviewService.java @@ -13,6 +13,7 @@ import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -59,6 +60,10 @@ public List getReviewsOfItem(Long itemId, Pageable pageable){ return reviews.stream().map(ReviewDto::fromEntity).toList(); } + public Page getReviewPageOfItem(Long itemId, Pageable pageable){ + return reviewRepository.findByItemId(itemId, pageable); + } + // 주문할 때, 주문 내역에 해당하는 item id를 쿠키로 생성하는 코드. // 리뷰 서비스에 활용 됨. diff --git a/src/main/resources/static/css/itemDetail.css b/src/main/resources/static/css/itemDetail.css index 956d5ea4aa..0bb970ce6c 100644 --- a/src/main/resources/static/css/itemDetail.css +++ b/src/main/resources/static/css/itemDetail.css @@ -131,4 +131,35 @@ background-color: #ffffff; border-radius: 10px; padding: 20px; +} + + +.pagination { + display: flex; + justify-content: center; + list-style: none; + padding: 0; +} + +.page-item { + margin: 0 5px; +} + +.page-link { + display: inline-block; + padding: 5px 10px; + color: #030302; /* 기본 색상 설정 */ + text-decoration: none; + border: 1px solid #f9ea85; /* 테두리 설정 */ + border-radius: 3px; + cursor: pointer; +} + +.page-link:hover { + background-color: #f9ea85; /* 호버 시 배경색 변경 */ + color: #333; /* 호버 시 텍스트 색상 변경 */ +} + +#pagedown, #pageup { + margin-right: 5px; /* 좌우 마진 설정 */ } \ No newline at end of file diff --git a/src/main/resources/static/css/orderForm.css b/src/main/resources/static/css/orderForm.css index 60621b579c..b1e225527f 100644 --- a/src/main/resources/static/css/orderForm.css +++ b/src/main/resources/static/css/orderForm.css @@ -433,3 +433,36 @@ button.order-btn { opacity: 1; visibility: visible; } + + +/* Pagination 스타일 */ +.pagination { + display: flex; + justify-content: center; + margin-top: 20%; +} + +.page-item { + list-style: none; + margin: 0 5px; +} + +.page-link { + color: #f9ea85; + text-decoration: none; + padding: 8px 12px; + border: 1px solid #f9ea85; + border-radius: 5px; + transition: background-color 0.3s; +} + +.page-link:hover { + background-color: #f9ea85; + color: #fff; +} + +.page-item.active .page-link { + background-color: #f9ea85; + color: #fff; + border-color: #f9ea85; +} \ No newline at end of file diff --git a/src/main/resources/templates/item/itemDetail.html b/src/main/resources/templates/item/itemDetail.html index 14fa16893e..292227e29b 100644 --- a/src/main/resources/templates/item/itemDetail.html +++ b/src/main/resources/templates/item/itemDetail.html @@ -42,8 +42,48 @@ +
    +
  • + < + > +
  • +
+ +