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()); } }