the whole inventory can be called now by one class. Inventory Overview Row. Returns the whole inventory
This commit is contained in:
@@ -2,4 +2,4 @@
|
|||||||
# https://curl.se/docs/http-cookies.html
|
# https://curl.se/docs/http-cookies.html
|
||||||
# This file was generated by libcurl! Edit at your own risk.
|
# 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
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.voyage.workspace.products.SkuRepository;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/inventory")
|
@RequestMapping("/api/inventory")
|
||||||
public class InventoryController {
|
public class InventoryController {
|
||||||
@@ -34,4 +36,12 @@ public class InventoryController {
|
|||||||
public int getCurrentStock(@PathVariable Long skuId) {
|
public int getCurrentStock(@PathVariable Long skuId) {
|
||||||
return movementRepo.currentStock(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
) {}
|
||||||
@@ -39,4 +39,4 @@ public class SkuController {
|
|||||||
|
|
||||||
return ResponseEntity.ok(skuRepo.save(sku));
|
return ResponseEntity.ok(skuRepo.save(sku));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,39 @@
|
|||||||
package com.voyage.workspace.products;
|
package com.voyage.workspace.products;
|
||||||
|
|
||||||
|
import com.voyage.workspace.inventory.InventoryOverviewRow;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
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.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface SkuRepository extends JpaRepository<Sku, Long> {
|
public interface SkuRepository extends JpaRepository<Sku, Long> {
|
||||||
|
|
||||||
List<Sku> findByProductId(Long productId);
|
List<Sku> findByProductId(Long productId);
|
||||||
Optional<Sku> findBySkuCode(String skuCode);
|
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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user