completed repositories

This commit is contained in:
2026-06-12 17:06:46 +03:00
parent 6fcd2bdd85
commit a9ee067897
4 changed files with 83 additions and 0 deletions
@@ -0,0 +1,46 @@
package com.andwati.orders.repository;
import com.andwati.orders.model.InventoryItem;
import jakarta.persistence.LockModeType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public interface InventoryItemRepository extends JpaRepository<InventoryItem, UUID> {
@Query("""
select inventory
from InventoryItem inventory
join fetch inventory.product product
order by product.name asc
""")
List<InventoryItem> findAllWithProducts();
@Query("""
select inventory
from InventoryItem inventory
join fetch inventory.product product
where inventory.availableQuantity < :threshold
order by inventory.availableQuantity asc, product.name asc
""")
List<InventoryItem> findLowStockItems(@Param("threshold") int threshold);
Optional<InventoryItem> findByProduct_Id(UUID productId);
List<InventoryItem> findByProduct_IdIn(Collection<UUID> productIds);
@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("""
select inventory
from InventoryItem inventory
join fetch inventory.product product
where product.id in :productIds
""")
List<InventoryItem> findByProductIdsForUpdate(@Param("productIds") Collection<UUID> productIds);
}
@@ -0,0 +1,9 @@
package com.andwati.orders.repository;
import com.andwati.orders.model.OrderItem;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.UUID;
public interface OrderItemRepository extends JpaRepository<OrderItem, UUID> {
}
@@ -0,0 +1,15 @@
package com.andwati.orders.repository;
import com.andwati.orders.model.Order;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.Optional;
import java.util.UUID;
public interface OrderRepository extends JpaRepository<Order, UUID>, JpaSpecificationExecutor<Order> {
@EntityGraph(attributePaths = {"items", "items.product"})
Optional<Order> findWithItemsById(UUID id);
}
@@ -0,0 +1,13 @@
package com.andwati.orders.repository;
import com.andwati.orders.model.Product;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
public interface ProductRepository extends JpaRepository<Product, UUID> {
List<Product> findByIdIn(Collection<UUID> ids);
}