- Timestamp:
- 11/11/21 12:59:26 (3 years ago)
- Branches:
- master
- Children:
- 59329aa
- Parents:
- 6c1585f
- Location:
- trip-planner/src/main/java/finki/diplomska/tripplanner/service
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner/src/main/java/finki/diplomska/tripplanner/service/LocationService.java
r6c1585f rceaed42 3 3 4 4 import finki.diplomska.tripplanner.models.Location; 5 import finki.diplomska.tripplanner.models.Planner; 6 import finki.diplomska.tripplanner.models.dto.PlannerLocationDto; 5 7 6 8 import java.util.List; … … 17 19 List<Location> findLocationsFromCityForm(Long cityId, Long companionId, Long lengthOfStay, String categoryIds); 18 20 List<Location> findLocationsFromRegionForm(Long regionId, Long companionId, Long lengthOfStay, String categoryIds); 21 Location addLocationToPlanner(PlannerLocationDto plannerLocationDto); 22 List<Location> getAllLocationsForPlanner(Long plannerId); 23 19 24 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/service/PlannerService.java
r6c1585f rceaed42 14 14 List<Planner> getAllPlaners(); 15 15 Optional<Planner> findById(Long id); 16 Planner addLocationToPlanner(Long plannerId, Long locationId);17 16 Planner editPlannerWithRequestParams(Long id, String description, String name, List<Location> locationList); 18 17 Optional<Planner> newPlanner(PlannerDto plannerDto); -
trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/LocationServiceImpl.java
r6c1585f rceaed42 2 2 3 3 import finki.diplomska.tripplanner.models.Location; 4 import finki.diplomska.tripplanner.models.Planner; 5 import finki.diplomska.tripplanner.models.dto.PlannerLocationDto; 4 6 import finki.diplomska.tripplanner.models.exceptions.LocationNotFoundException; 5 7 import finki.diplomska.tripplanner.repository.jpa.JpaLocationRepository; 8 import finki.diplomska.tripplanner.repository.jpa.JpaPlannerRepository; 6 9 import finki.diplomska.tripplanner.service.LocationService; 7 10 import org.springframework.stereotype.Service; … … 15 18 16 19 private final JpaLocationRepository locationRepository; 20 private final JpaPlannerRepository plannerRepository; 17 21 18 public LocationServiceImpl(JpaLocationRepository locationRepository ) {22 public LocationServiceImpl(JpaLocationRepository locationRepository, JpaPlannerRepository plannerRepository) { 19 23 this.locationRepository = locationRepository; 24 this.plannerRepository = plannerRepository; 20 25 } 21 26 … … 150 155 } 151 156 157 @Override 158 public Location addLocationToPlanner(PlannerLocationDto plannerLocationDto) { 159 Location location = this.locationRepository.findById(plannerLocationDto.getLocationId()) 160 .orElseThrow(() -> new LocationNotFoundException(plannerLocationDto.getLocationId())); 161 Planner planner = this.plannerRepository.getById(plannerLocationDto.getPlannerId()); 162 planner.getLocationList().add(location); 163 return this.locationRepository.save(location); 164 } 165 166 @Override 167 public List<Location> getAllLocationsForPlanner(Long plannerId) { 168 return this.locationRepository.getAllLocationsForPlanner(plannerId); 169 } 170 171 152 172 } -
trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/PlannerServiceImpl.java
r6c1585f rceaed42 22 22 private final JpaPlannerRepository plannerRepository; 23 23 private final JpaLocationRepository locationRepository; 24 private final LocationService locationService;25 24 26 public PlannerServiceImpl(JpaPlannerRepository plannerRepository, JpaLocationRepository locationRepository , LocationService locationService) {25 public PlannerServiceImpl(JpaPlannerRepository plannerRepository, JpaLocationRepository locationRepository) { 27 26 this.plannerRepository = plannerRepository; 28 27 this.locationRepository = locationRepository; 29 this.locationService = locationService;30 28 } 31 29 … … 40 38 } 41 39 42 @Override43 public Planner addLocationToPlanner(Long plannerId, Long locationId) {44 Location location = this.locationService.findById(locationId)45 .orElseThrow(() -> new LocationNotFoundException(locationId));46 Planner planner = this.plannerRepository.getById(plannerId);47 planner.getLocationList().add(location);48 return this.plannerRepository.save(planner);49 }50 40 51 41 @Override … … 84 74 planner.setName(plannerDto.getName()); 85 75 planner.setDescription(plannerDto.getDescription()); 86 76 /* 87 77 List<Location> locationList = new ArrayList<>(); 88 78 for(Long location : plannerDto.getLocationList()){ … … 92 82 } 93 83 planner.setLocationList(locationList); 84 85 */ 94 86 return Optional.of(this.plannerRepository.save(planner)); 95 87 }
Note:
See TracChangeset
for help on using the changeset viewer.