Dashboard bug fixed
This commit is contained in:
@@ -42,6 +42,13 @@ public class ProductController {
|
||||
return productRepository.findByIsDraftTrue();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<Product> getProductById(@PathVariable Long id) {
|
||||
return productRepository.findByIdWithStalls(id)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@GetMapping("/category/{categoryName}")
|
||||
public List<Product> getProductsByCategory(@PathVariable String categoryName) {
|
||||
return productRepository.findByCategory(categoryName);
|
||||
|
||||
@@ -30,6 +30,9 @@ public interface ProductRepository extends JpaRepository<Product, Long> {
|
||||
|
||||
@Query("SELECT p FROM Product p WHERE p.productId = :productId AND (p.isDraft = false OR p.isDraft IS NULL)")
|
||||
java.util.Optional<Product> findByProductIdRobust(@org.springframework.data.repository.query.Param("productId") String productId);
|
||||
|
||||
@Query("SELECT p FROM Product p LEFT JOIN FETCH p.stalls WHERE p.id = :id")
|
||||
java.util.Optional<Product> findByIdWithStalls(@org.springframework.data.repository.query.Param("id") Long id);
|
||||
|
||||
boolean existsByNameAndCategory(String name, String category);
|
||||
@org.springframework.data.jpa.repository.Modifying
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.rit.canteen.sales.repository.OrderRepository;
|
||||
import com.rit.canteen.sales.repository.PurchaseOrderRepository;
|
||||
import com.rit.canteen.sales.repository.VendorRepository;
|
||||
import com.rit.canteen.sales.repository.TokenTransactionRepository;
|
||||
import com.rit.canteen.sales.repository.UserRepository;
|
||||
import com.rit.canteen.sales.model.ProcurementDashboardData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -34,6 +35,9 @@ public class DashboardService {
|
||||
@Autowired
|
||||
private TokenTransactionRepository tokenTransactionRepository;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
public GeneralDashboardData getGeneralDashboardData(LocalDateTime from, LocalDateTime to) {
|
||||
java.time.ZoneId zone = java.time.ZoneId.of("Asia/Kolkata");
|
||||
if (from == null) from = java.time.LocalDate.now(zone).atStartOfDay();
|
||||
@@ -168,6 +172,8 @@ public class DashboardService {
|
||||
BigDecimal periodExpensesRaw = purchaseOrderRepository.getTotalPurchaseAmountInRange(from, to);
|
||||
long periodExpenses = periodExpensesRaw != null ? periodExpensesRaw.longValue() : 0;
|
||||
|
||||
long suspendedUserCount = userRepository.countByIsSuspended(true);
|
||||
|
||||
double growth = 0;
|
||||
if (yesterdayRevenue != null && yesterdayRevenue.compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal today = todayRevenue != null ? todayRevenue : BigDecimal.ZERO;
|
||||
@@ -179,7 +185,7 @@ public class DashboardService {
|
||||
growth = 100.0;
|
||||
}
|
||||
|
||||
return new DashboardStats(totalSales, periodRevenue, activeOrders, dailyCustomers, growth, totalExpenses, periodExpenses);
|
||||
return new DashboardStats(totalSales, periodRevenue, activeOrders, dailyCustomers, growth, totalExpenses, periodExpenses, suspendedUserCount);
|
||||
}
|
||||
|
||||
public ProcurementDashboardData getProcurementDashboardData() {
|
||||
|
||||
Reference in New Issue
Block a user