source: trip-planner/src/main/java/finki/diplomska/tripplanner/repository/jpa/JpaLocationRepository.java@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.6 KB
Line 
1package finki.diplomska.tripplanner.repository.jpa;
2
3import finki.diplomska.tripplanner.models.Location;
4import org.springframework.data.jpa.repository.JpaRepository;
5import org.springframework.data.jpa.repository.Query;
6import org.springframework.data.repository.query.Param;
7import org.springframework.stereotype.Repository;
8
9
10import java.util.List;
11
12@Repository
13public interface JpaLocationRepository extends JpaRepository<Location, Long> {
14
15 @Query(value = "SELECT * FROM locations AS l " +
16 "LEFT JOIN recommended_companion AS rc ON l.id_location = rc.id_location " +
17 "LEFT JOIN companions AS com ON rc.id_companion = com.id_companion " +
18 "LEFT JOIN locations_belong lb ON l.id_location = lb.id_location " +
19 "LEFT JOIN categories AS cate ON lb.id_category = cate.id_category " +
20 "LEFT JOIN regions AS r" +
21 " ON l.id_region = r.id_region" +
22 " LEFT JOIN cities AS cit" +
23 " ON r.id_region = cit.id_region AND cit.id_city = l.id_city " +
24 "WHERE cit.city_name = :locName and com.type = :companion and cate.category_name in (:categories) " +
25 "GROUP BY l.id_location " +
26 "ORDER BY CASE l.priority WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 END", nativeQuery = true)
27 List<Location> findLocationsFromCity(@Param("locName") String locName, @Param("companion") String companion, @Param("categories") List<String> categories);
28
29 @Query(value = "SELECT * FROM locations AS l " +
30 "LEFT JOIN recommended_companion AS rc ON l.id_location = rc.id_location " +
31 "LEFT JOIN companions AS com " +
32 "ON rc.id_companion = com.id_companion " +
33 "LEFT JOIN locations_belong lb " +
34 "ON l.id_location = lb.id_location " +
35 "LEFT JOIN categories AS cate " +
36 "ON lb.id_category = cate.id_category " +
37 "LEFT JOIN regions AS r " +
38 "ON l.id_region = r.id_region " +
39 "LEFT JOIN countries AS country " +
40 "ON r.id_country = country.id_country " +
41 "LEFT JOIN cities AS c " +
42 "ON r.id_region = c.id_region AND c.id_city = l.id_city" +
43 " WHERE country.country_name = :locName and com.type = :companion and cate.category_name in (:categories) AND r.region_name = :region " +
44 "GROUP BY l.id_location ORDER BY CASE l.priority WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 END", nativeQuery = true)
45 List<Location> findLocationsFromCountry(@Param("locName") String ime, @Param("companion") String companion, @Param("region") String region, @Param("categories") List<String> categories);
46}
Note: See TracBrowser for help on using the repository browser.