Ignore:
Timestamp:
10/18/21 00:19:16 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
188ee53
Parents:
fa375fe
Message:

editing location-form on frontend and backend

Location:
trip-planner/src/main/java/finki/diplomska/tripplanner
Files:
4 edited

Legend:

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

    rfa375fe reed0bf8  
    4444            "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)
    4545    List<Location> findLocationsFromCountry(@Param("locName") String ime, @Param("companion") String companion, @Param("region") String region, @Param("categories") List<String> categories);
     46
     47    @Query(value = "SELECT  * FROM locations AS l  " +
     48            "LEFT JOIN recommended_companion AS rc ON l.id_location = rc.id_location " +
     49            "LEFT JOIN companions AS com ON rc.id_companion = com.id_companion " +
     50            "LEFT JOIN locations_belong lb ON l.id_location = lb.id_location " +
     51            "LEFT JOIN categories AS cate ON lb.id_category = cate.id_category " +
     52            "LEFT JOIN regions AS r" +
     53            " ON l.id_region = r.id_region" +
     54            " LEFT JOIN cities AS cit" +
     55            " ON r.id_region = cit.id_region AND cit.id_city = l.id_city " +
     56            "WHERE cit.id_city = :locationId and com.id_companion = :companionId and cate.id_category in (:categories) " +
     57            "GROUP BY l.id_location " +
     58            "ORDER BY CASE l.priority WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 END", nativeQuery = true)
     59    List<Location> findLocationsFromForm(@Param("locationId") Long locationId, @Param("companionId") Long companionId, @Param("categories") List<Long> categories);
    4660}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/LocationService.java

    rfa375fe reed0bf8  
    1515    List<Location> scheduleLocations(String locName, String companion,String region, List<String> categories, int numberOfDays);
    1616    Optional<Location> findById(Long id);
     17
     18    List<Location> findLocations(Long locationId, Long companionId, Long lengthOfStay, String categoryIds);
    1719}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/LocationServiceImpl.java

    rfa375fe reed0bf8  
    88
    99import java.util.*;
     10import java.util.stream.Collectors;
    1011
    1112
     
    4647    public Optional<Location> findById(Long id) {
    4748        return this.locationRepository.findById(id);
     49    }
     50
     51    @Override
     52    public List<Location> findLocations(Long locationId, Long companionId, Long lengthOfStay, String categoryIds) {
     53        List<Long> categories = null;
     54        if(categoryIds != null && !categoryIds.isEmpty()){
     55            List<String> ids = Arrays.asList(categoryIds.split(","));
     56            categories = ids.stream().map(Long::valueOf).collect(Collectors.toList());
     57        }
     58        List<Location> foundLocations = locationRepository.findLocationsFromForm(locationId, companionId, categories);
     59        return foundLocations;
    4860    }
    4961
  • trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/LocationRestController.java

    rfa375fe reed0bf8  
    3434    }
    3535
    36     @PostMapping(value = "/trip/locations")
    37     public List<Location> allLocationsAfterSubmittedForm(@RequestParam(required = false) String locName,
    38                                                          @RequestParam(required = false)  String companion,
    39                                                          @RequestParam(required = false) String region,
    40                                                          @RequestParam(required = false) List<String> categories,
    41                                                          @RequestParam(required = false)  int numberOfDays)  {
    42         List<Location> generatedLocations = this.locationService.scheduleLocations(locName, companion, region, categories, numberOfDays);
     36    @GetMapping(value = "/trip/locations")
     37    public List<Location> allLocationsAfterSubmittedForm(@RequestParam(required = false) Long locationId,
     38                                                         @RequestParam(required = false)  Long companionId,
     39                                                         @RequestParam(required = false) Long lengthOfStay,
     40                                                         @RequestParam(required = false) String categoryIds)  {
     41        return this.locationService.findLocations(locationId, companionId, lengthOfStay, categoryIds);
     42        /* List<Location> generatedLocations = this.locationService.scheduleLocations(locName, companion, region, categories, numberOfDays);
    4343        if(locName.equals("Macedonia")){
    4444            return generatedLocations;
    4545        }else{
    4646            return generatedLocations;
    47         }
     47        }*/
    4848    }
    4949}
Note: See TracChangeset for help on using the changeset viewer.