mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 00:48:49 +00:00
50 lines
1.5 KiB
Java
50 lines
1.5 KiB
Java
package com.imprimelibros.erp.direcciones;
|
|
|
|
import org.springframework.data.jpa.repository.JpaRepository;
|
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|
import org.springframework.data.jpa.repository.Query;
|
|
import org.springframework.data.repository.query.Param;
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
public interface DireccionRepository
|
|
extends JpaRepository<Direccion, Long>,
|
|
JpaSpecificationExecutor<Direccion> {
|
|
|
|
|
|
@Query("""
|
|
select d from Direccion d
|
|
left join fetch d.user
|
|
left join fetch d.pais
|
|
where d.user.id = :id
|
|
""")
|
|
List<DireccionView> findAllWithPaisAndUser(@Param("userId") Long userId);
|
|
|
|
@Query("""
|
|
select d from Direccion d
|
|
left join fetch d.user
|
|
left join fetch d.pais
|
|
where d.id = :id
|
|
""")
|
|
Optional<Direccion> findByIdWithPaisAndUser(@Param("id") Long id);
|
|
|
|
|
|
|
|
@Query(value = "SELECT * FROM direcciones", nativeQuery = true)
|
|
List<DireccionView> findAllWithDeleted();
|
|
|
|
// find by user_id
|
|
List<Direccion> findByUserId(Long userId);
|
|
|
|
// find by user_id and direccion_facturacion = true
|
|
@Query("SELECT d FROM Direccion d WHERE (:userId IS NULL OR d.user.id = :userId) AND d.direccionFacturacion = true")
|
|
List<Direccion> findByUserIdAndDireccionFacturacion(@Param("userId") Long userId);
|
|
|
|
// find by user_id with deleted
|
|
@Query(value = "SELECT * FROM direcciones WHERE user_id = :userId", nativeQuery = true)
|
|
List<Direccion> findByUserIdWithDeleted(@Param("userId") Long userId);
|
|
|
|
}
|