added filtering for Sales and added helper method for setting up filtertoggle andriod

This commit is contained in:
Alex
2026-04-08 01:32:34 -06:00
parent 4fc33fedf4
commit 3e01ad07cd
21 changed files with 151 additions and 155 deletions

View File

@@ -26,8 +26,9 @@ public class SaleController {
public ResponseEntity<Page<SaleResponse>> getAllSales(
@RequestParam(required = false) String q,
@RequestParam(required = false) String paymentMethod,
@RequestParam(required = false) Long storeId,
Pageable pageable) {
return ResponseEntity.ok(saleService.getAllSales(q, paymentMethod, pageable));
return ResponseEntity.ok(saleService.getAllSales(q, paymentMethod, storeId, pageable));
}
@GetMapping("/{id}")

View File

@@ -19,8 +19,9 @@ public interface SaleRepository extends JpaRepository<Sale, Long> {
"LOWER(s.employee.lastName) LIKE LOWER(CONCAT('%', :q, '%')) OR " +
"LOWER(s.store.storeName) LIKE LOWER(CONCAT('%', :q, '%'))" +
")) AND " +
"(:paymentMethod IS NULL OR LOWER(s.paymentMethod) = LOWER(:paymentMethod))")
Page<Sale> searchSales(@Param("q") String query, @Param("paymentMethod") String paymentMethod, Pageable pageable);
"(:paymentMethod IS NULL OR LOWER(s.paymentMethod) = LOWER(:paymentMethod)) AND " +
"(:storeId IS NULL OR s.store.storeId = :storeId)")
Page<Sale> searchSales(@Param("q") String query, @Param("paymentMethod") String paymentMethod, @Param("storeId") Long storeId, Pageable pageable);
List<Sale> findByOriginalSaleSaleId(Long originalSaleId);
}

View File

@@ -39,8 +39,8 @@ public class SaleService {
}
@Transactional(readOnly = true)
public Page<SaleResponse> getAllSales(String query, String paymentMethod, Pageable pageable) {
Page<Sale> sales = saleRepository.searchSales(normalizeFilter(query), normalizeFilter(paymentMethod), pageable);
public Page<SaleResponse> getAllSales(String query, String paymentMethod, Long storeId, Pageable pageable) {
Page<Sale> sales = saleRepository.searchSales(normalizeFilter(query), normalizeFilter(paymentMethod), storeId, pageable);
return sales.map(this::mapToResponse);
}