the whole inventory can be called now by one class. Inventory Overview Row. Returns the whole inventory

This commit is contained in:
Domonkos
2026-01-20 23:28:48 +01:00
parent 32279cde3f
commit 0a90b5102a
5 changed files with 54 additions and 2 deletions

View File

@@ -2,4 +2,4 @@
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
#HttpOnly_localhost FALSE / FALSE 0 JSESSIONID 2DEB364C8E88DCC03042A328A4610233
#HttpOnly_localhost FALSE / FALSE 0 JSESSIONID 1D763BECEF84ECD1D335BF07E96D3691

View File

@@ -4,6 +4,8 @@ import com.voyage.workspace.products.SkuRepository;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/inventory")
public class InventoryController {
@@ -34,4 +36,12 @@ public class InventoryController {
public int getCurrentStock(@PathVariable Long skuId) {
return movementRepo.currentStock(skuId);
}
@GetMapping("/overview")
public List<InventoryOverviewRow> overview(
@RequestParam(required = false) String category,
@RequestParam(required = false) Boolean active
) {
return skuRepo.inventoryOverview(category, active);
}
}

View File

@@ -0,0 +1,14 @@
package com.voyage.workspace.inventory;
import java.math.BigDecimal;
public record InventoryOverviewRow(
Long skuId,
String skuCode,
String productName,
String category,
String size,
String color,
BigDecimal price,
long currentStock
) {}

View File

@@ -39,4 +39,4 @@ public class SkuController {
return ResponseEntity.ok(skuRepo.save(sku));
}
}
}

View File

@@ -1,11 +1,39 @@
package com.voyage.workspace.products;
import com.voyage.workspace.inventory.InventoryOverviewRow;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.Optional;
public interface SkuRepository extends JpaRepository<Sku, Long> {
List<Sku> findByProductId(Long productId);
Optional<Sku> findBySkuCode(String skuCode);
@Query("""
select new com.voyage.workspace.inventory.InventoryOverviewRow(
s.id,
s.skuCode,
p.name,
p.category,
s.size,
s.color,
s.price,
coalesce(sum(m.delta), 0L)
)
from Sku s
join s.product p
left join InventoryMovement m on m.sku = s
where (:category is null or p.category = :category)
and (:active is null or s.active = :active)
group by s.id, s.skuCode, p.name, p.category, s.size, s.color, s.price
order by p.name asc, s.skuCode asc
""")
List<InventoryOverviewRow> inventoryOverview(
@Param("category") String category,
@Param("active") Boolean active
);
}