Skip to content

Commit

Permalink
feat: 재고 검색어 조회 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
djdongjae committed May 29, 2024
1 parent f032744 commit 335fadf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Optional;

@Slf4j
@RequiredArgsConstructor
Expand Down Expand Up @@ -41,8 +42,10 @@ public BaseResponse<InventoryResponseDto> findInventory(@PathVariable Long id) {

@GetMapping
@ResponseStatus(HttpStatus.OK)
public BaseResponse<List<InventoryResponseDto>> findAllInventory() {
final List<InventoryResponseDto> data = inventoryService.findAllInventory();
public BaseResponse<List<InventoryResponseDto>> findAllByNameContaining(
@RequestParam(name = "srchText", required = false) Optional<String> srchText
) {
final List<InventoryResponseDto> data = inventoryService.findAllByNameContaining(srchText.orElse(""));
return BaseResponse.success(SuccessCode.INVENTORY_GET_SUCCESS, data);
}
}
Original file line number Diff line number Diff line change
@@ -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<Inventory, Long> {
List<Inventory> findAllByNameContaining(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public InventoryResponseDto findInventory(Long id) {
return InventoryResponseDto.from(inventory);
}

public List<InventoryResponseDto> findAllInventory() {
List<Inventory> inventoryList = inventoryRepository.findAll();
public List<InventoryResponseDto> findAllByNameContaining(String srchText) {
List<Inventory> inventoryList = inventoryRepository.findAllByNameContaining(srchText);
return inventoryList.stream().map(InventoryResponseDto::from).collect(Collectors.toList());
}
}

0 comments on commit 335fadf

Please sign in to comment.