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 Type
    Method
    Description
    findByCustomerId(Long customerId)
    Busca todos los pedidos de un cliente.
    Busca pedidos realizados en un rango de fechas.
    Busca un pedido por su número de orden.
    Busca pedidos por estado.
    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, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • findByOrderNumber

      Optional<Order> findByOrderNumber(String orderNumber)
      Busca un pedido por su número de orden.
      Parameters:
      orderNumber - número de orden
      Returns:
      Optional con el pedido si existe
    • findByCustomerId

      List<Order> findByCustomerId(Long customerId)
      Busca todos los pedidos de un cliente.
      Parameters:
      customerId - ID del cliente
      Returns:
      lista de pedidos del cliente
    • findByStatus

      List<Order> findByStatus(Order.OrderStatus status)
      Busca pedidos por estado.
      Parameters:
      status - estado del pedido
      Returns:
      lista de pedidos con ese estado
    • findByOrderDateBetween

      List<Order> findByOrderDateBetween(LocalDateTime startDate, LocalDateTime endDate)
      Busca pedidos realizados en un rango de fechas.
      Parameters:
      startDate - fecha inicial
      endDate - 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