Package com.proyecto.jpa.repository
Interface OrderRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<Order,,Long> org.springframework.data.jpa.repository.JpaRepository<Order,,Long> org.springframework.data.repository.ListCrudRepository<Order,,Long> org.springframework.data.repository.ListPagingAndSortingRepository<Order,,Long> org.springframework.data.repository.PagingAndSortingRepository<Order,,Long> org.springframework.data.repository.query.QueryByExampleExecutor<Order>,org.springframework.data.repository.Repository<Order,Long>
@Repository
public interface OrderRepository
extends org.springframework.data.jpa.repository.JpaRepository<Order,Long>
Repositorio JPA para la entidad Order.
-
Method Summary
Modifier and TypeMethodDescriptionfindByCustomerId(Long customerId) Busca todos los pedidos de un cliente.findByOrderDateBetween(LocalDateTime startDate, LocalDateTime endDate) Busca pedidos realizados en un rango de fechas.findByOrderNumber(String orderNumber) Busca un pedido por su número de orden.findByStatus(Order.OrderStatus status) Busca pedidos por estado.findOrdersWithItemsByCustomer(Long customerId) Consulta personalizada para obtener pedidos de un cliente con sus items.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findByOrderNumber
Busca un pedido por su número de orden.- Parameters:
orderNumber- número de orden- Returns:
- Optional con el pedido si existe
-
findByCustomerId
Busca todos los pedidos de un cliente.- Parameters:
customerId- ID del cliente- Returns:
- lista de pedidos del cliente
-
findByStatus
Busca pedidos por estado.- Parameters:
status- estado del pedido- Returns:
- lista de pedidos con ese estado
-
findByOrderDateBetween
Busca pedidos realizados en un rango de fechas.- Parameters:
startDate- fecha inicialendDate- fecha final- Returns:
- lista de pedidos en ese rango
-
findOrdersWithItemsByCustomer
@Query("SELECT DISTINCT o FROM Order o LEFT JOIN FETCH o.orderItems WHERE o.customer.id = :customerId") List<Order> findOrdersWithItemsByCustomer(@Param("customerId") Long customerId) Consulta personalizada para obtener pedidos de un cliente con sus items. Usa JOIN FETCH para evitar el problema N+1 (carga eager de relaciones).- Parameters:
customerId- ID del cliente- Returns:
- lista de pedidos con items cargados
-