Ignore:
Timestamp:
01/28/22 18:45:54 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
6fe77af
Parents:
b738035
Message:

search all locations by city or region

Location:
trip-planner/src/main/java/finki/diplomska/tripplanner/repository/jpa
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trip-planner/src/main/java/finki/diplomska/tripplanner/repository/jpa/JpaLocationRepository.java

    rb738035 r76712b2  
    109109    List<Location> getVillages();
    110110
    111     @Query(value = "SELECT * FROM locations AS l WHERE l.id_city = :cityId", nativeQuery = true)
    112     List<Location> getLocationsForCity(@Param("cityId") Long cityId);
     111    @Query(value = "SELECT * FROM locations AS l " +
     112            "LEFT JOIN cities AS c " +
     113            "ON l.id_city = c.id_city " +
     114            "LEFT JOIN regions AS r " +
     115            "ON l.id_region = r.id_region " +
     116            "WHERE c.city_name = :place OR r.region_name = :place", nativeQuery = true)
     117    List<Location> getAllLocations(@Param("place") String place);
    113118}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/repository/jpa/JpaRegionRepository.java

    rb738035 r76712b2  
    33import finki.diplomska.tripplanner.models.Region;
    44import org.springframework.data.jpa.repository.JpaRepository;
     5import org.springframework.data.jpa.repository.Query;
    56import org.springframework.stereotype.Repository;
     7
     8import java.util.List;
    69
    710@Repository
    811public interface JpaRegionRepository extends JpaRepository<Region, Long> {
     12
     13    @Query(value="SELECT r.region_name " +
     14            "FROM regions AS r " +
     15            "UNION all " +
     16            "SELECT c.city_name FROM cities AS c", nativeQuery = true)
     17    List<String> getAllCitiesAndRegions();
    918}
Note: See TracChangeset for help on using the changeset viewer.