From 335fadffed048b6e51732fc4cfc7bf0e85ef8de7 Mon Sep 17 00:00:00 2001 From: djdongjae Date: Wed, 29 May 2024 09:05:05 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9E=AC=EA=B3=A0=20=EA=B2=80=EC=83=89?= =?UTF-8?q?=EC=96=B4=20=EC=A1=B0=ED=9A=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/inventory/InventoryController.java | 7 +++++-- .../domain/inventory/InventoryRepository.java | 2 ++ .../skhu/tastyinventory_be/service/InventoryService.java | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/skhu/tastyinventory_be/controller/inventory/InventoryController.java b/src/main/java/net/skhu/tastyinventory_be/controller/inventory/InventoryController.java index 3d4719a..f2a226c 100644 --- a/src/main/java/net/skhu/tastyinventory_be/controller/inventory/InventoryController.java +++ b/src/main/java/net/skhu/tastyinventory_be/controller/inventory/InventoryController.java @@ -13,6 +13,7 @@ import org.springframework.web.multipart.MultipartFile; import java.util.List; +import java.util.Optional; @Slf4j @RequiredArgsConstructor @@ -41,8 +42,10 @@ public BaseResponse findInventory(@PathVariable Long id) { @GetMapping @ResponseStatus(HttpStatus.OK) - public BaseResponse> findAllInventory() { - final List data = inventoryService.findAllInventory(); + public BaseResponse> findAllByNameContaining( + @RequestParam(name = "srchText", required = false) Optional srchText + ) { + final List data = inventoryService.findAllByNameContaining(srchText.orElse("")); return BaseResponse.success(SuccessCode.INVENTORY_GET_SUCCESS, data); } } diff --git a/src/main/java/net/skhu/tastyinventory_be/domain/inventory/InventoryRepository.java b/src/main/java/net/skhu/tastyinventory_be/domain/inventory/InventoryRepository.java index 8fb2fcd..170df3a 100644 --- a/src/main/java/net/skhu/tastyinventory_be/domain/inventory/InventoryRepository.java +++ b/src/main/java/net/skhu/tastyinventory_be/domain/inventory/InventoryRepository.java @@ -1,6 +1,8 @@ package net.skhu.tastyinventory_be.domain.inventory; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; public interface InventoryRepository extends JpaRepository { + List findAllByNameContaining(String name); } diff --git a/src/main/java/net/skhu/tastyinventory_be/service/InventoryService.java b/src/main/java/net/skhu/tastyinventory_be/service/InventoryService.java index 918c9c7..0f11ea2 100644 --- a/src/main/java/net/skhu/tastyinventory_be/service/InventoryService.java +++ b/src/main/java/net/skhu/tastyinventory_be/service/InventoryService.java @@ -42,8 +42,8 @@ public InventoryResponseDto findInventory(Long id) { return InventoryResponseDto.from(inventory); } - public List findAllInventory() { - List inventoryList = inventoryRepository.findAll(); + public List findAllByNameContaining(String srchText) { + List inventoryList = inventoryRepository.findAllByNameContaining(srchText); return inventoryList.stream().map(InventoryResponseDto::from).collect(Collectors.toList()); } }