diff --git a/src/main/java/com/helpmeCookies/global/exception/GlobalExceptionHandler.java b/src/main/java/com/helpmeCookies/global/exception/GlobalExceptionHandler.java index 8dc9206..8884333 100644 --- a/src/main/java/com/helpmeCookies/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/helpmeCookies/global/exception/GlobalExceptionHandler.java @@ -22,4 +22,9 @@ public ResponseEntity> handleResourceNotFoundException(Resourc public ResponseEntity> handleDuplicateRequestException(DuplicateResourceException e) { return ResponseEntity.badRequest().body(ApiResponse.error(HttpStatus.BAD_REQUEST, e.getMessage())); } + + @ExceptionHandler(IllegalArgumentException.class) + public ResponseEntity> handleIllegalArgumentException(IllegalArgumentException e) { + return ResponseEntity.badRequest().body(ApiResponse.error(HttpStatus.BAD_REQUEST, e.getMessage())); + } } diff --git a/src/main/java/com/helpmeCookies/product/controller/ProductController.java b/src/main/java/com/helpmeCookies/product/controller/ProductController.java index 2ccdffe..c1f34f6 100644 --- a/src/main/java/com/helpmeCookies/product/controller/ProductController.java +++ b/src/main/java/com/helpmeCookies/product/controller/ProductController.java @@ -88,7 +88,7 @@ public ResponseEntity deleteProduct(@PathVariable("productId") Long produc } @GetMapping - public ResponseEntity getProductsByPage( + public ResponseEntity> getProductsByPage( @RequestParam("query") String query, @RequestParam(name = "size", required = false, defaultValue = "20") int size, @RequestParam("page") int page, @@ -97,7 +97,7 @@ public ResponseEntity getProductsByPage( var sort = convertProductSort(productSort); var pageable = PageRequest.of(page, size, sort); - return ResponseEntity.ok(productService.getProductsByPage(query, pageable)); + return ResponseEntity.ok(ApiResponse.success(SuccessCode.OK,productService.getProductsByPage(query, pageable))); } @GetMapping("/feed") diff --git a/src/main/java/com/helpmeCookies/product/controller/docs/ProductApiDocs.java b/src/main/java/com/helpmeCookies/product/controller/docs/ProductApiDocs.java index e0097b5..3483a0b 100644 --- a/src/main/java/com/helpmeCookies/product/controller/docs/ProductApiDocs.java +++ b/src/main/java/com/helpmeCookies/product/controller/docs/ProductApiDocs.java @@ -1,21 +1,25 @@ package com.helpmeCookies.product.controller.docs; +import com.helpmeCookies.global.ApiResponse.ApiResponse; +import com.helpmeCookies.product.dto.ProductPage; import com.helpmeCookies.product.dto.ProductPage.Paging; import com.helpmeCookies.product.util.ProductSort; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; @Tag(name = "상품 관련 기능", description = "상품 관련 API") public interface ProductApiDocs { @Operation(summary = "상품 검색") - ResponseEntity getProductsByPage( - String query, - @Parameter(description = "default value 20") int size, - int page, - ProductSort productSort - ); - + @GetMapping + public ResponseEntity> getProductsByPage( + @RequestParam("query") String query, + @RequestParam(name = "size", required = false, defaultValue = "20") int size, + @RequestParam("page") int page, + @RequestParam("sort") ProductSort productSort + ) }