Added filter by store for inventory in back end and added search to inventory

This commit is contained in:
Alex
2026-04-07 05:24:25 -06:00
parent 6c832e01f3
commit cbd038d8fb
8 changed files with 181 additions and 68 deletions

View File

@@ -22,8 +22,9 @@ public class PurchaseOrderController {
@GetMapping
public ResponseEntity<Page<PurchaseOrderResponse>> getAllPurchaseOrders(
@RequestParam(required = false) String q,
@RequestParam(required = false) Long storeId,
Pageable pageable) {
return ResponseEntity.ok(purchaseOrderService.getAllPurchaseOrders(q, pageable));
return ResponseEntity.ok(purchaseOrderService.getAllPurchaseOrders(q, storeId, pageable));
}
@GetMapping("/{id}")

View File

@@ -12,6 +12,7 @@ import org.springframework.stereotype.Repository;
public interface PurchaseOrderRepository extends JpaRepository<PurchaseOrder, Long> {
@Query("SELECT po FROM PurchaseOrder po WHERE " +
"LOWER(po.supplier.supCompany) LIKE LOWER(CONCAT('%', :q, '%'))")
Page<PurchaseOrder> searchPurchaseOrders(@Param("q") String query, Pageable pageable);
"(:q IS NULL OR LOWER(po.supplier.supCompany) LIKE LOWER(CONCAT('%', :q, '%'))) AND " +
"(:storeId IS NULL OR po.store.storeId = :storeId)")
Page<PurchaseOrder> searchPurchaseOrders(@Param("q") String query, @Param("storeId") Long storeId, Pageable pageable);
}

View File

@@ -18,13 +18,9 @@ public class PurchaseOrderService {
this.purchaseOrderRepository = purchaseOrderRepository;
}
public Page<PurchaseOrderResponse> getAllPurchaseOrders(String query, Pageable pageable) {
Page<PurchaseOrder> purchaseOrders;
if (query != null && !query.trim().isEmpty()) {
purchaseOrders = purchaseOrderRepository.searchPurchaseOrders(query, pageable);
} else {
purchaseOrders = purchaseOrderRepository.findAll(pageable);
}
public Page<PurchaseOrderResponse> getAllPurchaseOrders(String query, Long storeId, Pageable pageable) {
String normalizedQuery = normalizeFilter(query);
Page<PurchaseOrder> purchaseOrders = purchaseOrderRepository.searchPurchaseOrders(normalizedQuery, storeId, pageable);
return purchaseOrders.map(this::mapToResponse);
}
@@ -34,6 +30,14 @@ public class PurchaseOrderService {
return mapToResponse(purchaseOrder);
}
private String normalizeFilter(String value) {
if (value == null) {
return null;
}
String trimmed = value.trim();
return trimmed.isEmpty() ? null : trimmed;
}
private PurchaseOrderResponse mapToResponse(PurchaseOrder purchaseOrder) {
StoreLocation store = purchaseOrder.getStore();
return new PurchaseOrderResponse(