package org.marsik.elshelves.backend.repositories;

import org.marsik.elshelves.backend.entities.Lot;
import org.marsik.elshelves.backend.repositories.results.LotMetric;
import org.springframework.data.jpa.repository.Query;

public interface LotRepository extends BaseOwnedEntityRepository<Lot> {
    @Query("SELECT NEW org.marsik.elshelves.backend.repositories.results.LotMetric(" +
            " count(l.id)," +
            " SUM(CASE l.used WHEN true THEN 1 ELSE 0 END)," +
            " SUM(CASE l.usedInPast WHEN true THEN 1 ELSE 0 END)" +
            " ) " +
            " FROM Lot l" +
            " WHERE l.valid = true")
    LotMetric lotCount();
}

@@ -395,18 +395,19 @@
   %22 
+SUM(l.
 count
-(l.id
 ),%22 
@@ -445,33 +445,39 @@
  WHEN true THEN 
-1
+l.count
  ELSE 0 END),%22 +
@@ -532,9 +532,15 @@
 HEN 
-1
+l.count
  ELS

Fix part count metric