fix minor bugs and UI inconsistancy
This commit is contained in:
@@ -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}")
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user