Changeset 8d391a1 for trip-planner/src


Ignore:
Timestamp:
11/26/21 20:07:18 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
1ad8e64
Parents:
e29cc2e
Message:

disabling to add location if it already exists in the planner

Location:
trip-planner/src
Files:
5 edited

Legend:

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

    re29cc2e r8d391a1  
    8484    List<Location> getAllLocationsForPlanner(@Param("plannerId") Long plannerId);
    8585
     86
     87    @Query(value = "SELECT l.id_location " +
     88            "FROM locations AS l " +
     89            "WHERE l.id_location IN " +
     90            "(SELECT pl.id_location FROM planners_contain AS pl WHERE pl.id_planner = :plannerId)", nativeQuery = true)
     91    List<Long> getAllLocationIdsForPlanner(@Param("plannerId") Long plannerId);
     92
    8693    @Query(value = "SELECT *, if(l.id_city is NOT NULL, c.city_name, l.location_name) as result " +
    8794            "FROM locations AS l " +
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/LocationService.java

    re29cc2e r8d391a1  
    55import finki.diplomska.tripplanner.models.Planner;
    66import finki.diplomska.tripplanner.models.dto.PlannerLocationDto;
     7import org.springframework.data.repository.query.Param;
    78
    89import java.util.List;
     
    2324    List<Location> getWeekendGetaways();
    2425    List<Location> getVillages();
     26    List<Long> getAllLocationIdsForPlanner(Long plannerId);
    2527}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/LocationServiceImpl.java

    re29cc2e r8d391a1  
    179179    }
    180180
     181    @Override
     182    public List<Long> getAllLocationIdsForPlanner(Long plannerId) {
     183        return this.locationRepository.getAllLocationIdsForPlanner(plannerId);
     184    }
     185
    181186
    182187}
  • trip-planner/src/main/java/finki/diplomska/tripplanner/web/rest/LocationRestController.java

    re29cc2e r8d391a1  
    55import finki.diplomska.tripplanner.service.LocationService;
    66import finki.diplomska.tripplanner.service.PlannerService;
     7import org.springframework.data.repository.query.Param;
    78import org.springframework.http.ResponseEntity;
    89import org.springframework.web.bind.annotation.*;
     
    7172        return this.locationService.getVillages();
    7273    }
     74
     75    @GetMapping(value = "/planner/locationIds")
     76    public List<Long> getAllLocationIdsForPlanner(@RequestParam Long plannerId){
     77        return this.locationService.getAllLocationIdsForPlanner(plannerId);
     78    }
    7379}
  • trip-planner/src/test/api.http

    re29cc2e r8d391a1  
    6161
    6262###
     63GET http://localhost:8080/api/planner/locationIds?plannerId=2
     64Content-Type: application/x-www-form-urlencoded
     65
     66###
    6367GET http://localhost:8080/api/weekend
    6468Content-Type: application/x-www-form-urlencoded
Note: See TracChangeset for help on using the changeset viewer.