fix minor bugs and UI inconsistancy

This commit is contained in:
Alex
2026-04-08 00:22:25 -06:00
parent b3ff789f1b
commit 526650bd98
23 changed files with 665 additions and 246 deletions

View File

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

View File

@@ -14,10 +14,13 @@ import java.util.List;
public interface SaleRepository extends JpaRepository<Sale, Long> {
@Query("SELECT s FROM Sale s WHERE " +
"(:q IS NULL OR (" +
"LOWER(s.employee.firstName) LIKE LOWER(CONCAT('%', :q, '%')) OR " +
"LOWER(s.employee.lastName) LIKE LOWER(CONCAT('%', :q, '%')) OR " +
"LOWER(s.store.storeName) LIKE LOWER(CONCAT('%', :q, '%'))")
Page<Sale> searchSales(@Param("q") String query, Pageable pageable);
"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);
List<Sale> findByOriginalSaleSaleId(Long originalSaleId);
}

View File

@@ -39,13 +39,8 @@ public class SaleService {
}
@Transactional(readOnly = true)
public Page<SaleResponse> getAllSales(String query, Pageable pageable) {
Page<Sale> sales;
if (query != null && !query.trim().isEmpty()) {
sales = saleRepository.searchSales(query, pageable);
} else {
sales = saleRepository.findAll(pageable);
}
public Page<SaleResponse> getAllSales(String query, String paymentMethod, Pageable pageable) {
Page<Sale> sales = saleRepository.searchSales(normalizeFilter(query), normalizeFilter(paymentMethod), pageable);
return sales.map(this::mapToResponse);
}
@@ -236,6 +231,14 @@ public class SaleService {
return response;
}
private String normalizeFilter(String value) {
if (value == null) {
return null;
}
String trimmed = value.trim();
return trimmed.isEmpty() ? null : trimmed;
}
String normalizePaymentMethod(String paymentMethod) {
if (paymentMethod == null) {
return null;