Changeset 6fe77af for trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/LocationServiceImpl.java
- Timestamp:
- 02/06/22 18:15:51 (3 years ago)
- Branches:
- master
- Children:
- 571e0df
- Parents:
- 76712b2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/LocationServiceImpl.java
r76712b2 r6fe77af 1 1 package finki.diplomska.tripplanner.service.impl; 2 2 3 import finki.diplomska.tripplanner.models. Location;4 import finki.diplomska.tripplanner.models. Planner;3 import finki.diplomska.tripplanner.models.*; 4 import finki.diplomska.tripplanner.models.dto.LocationDto; 5 5 import finki.diplomska.tripplanner.models.dto.PlannerLocationDto; 6 import finki.diplomska.tripplanner.models.exceptions.CityNotFoundException; 7 import finki.diplomska.tripplanner.models.exceptions.CompanionNotFoundException; 6 8 import finki.diplomska.tripplanner.models.exceptions.LocationNotFoundException; 7 import finki.diplomska.tripplanner. repository.jpa.JpaLocationRepository;8 import finki.diplomska.tripplanner.repository.jpa. JpaPlannerRepository;9 import finki.diplomska.tripplanner.models.exceptions.RegionNotFoundException; 10 import finki.diplomska.tripplanner.repository.jpa.*; 9 11 import finki.diplomska.tripplanner.service.LocationService; 10 12 import org.springframework.stereotype.Service; … … 19 21 private final JpaLocationRepository locationRepository; 20 22 private final JpaPlannerRepository plannerRepository; 21 22 public LocationServiceImpl(JpaLocationRepository locationRepository, JpaPlannerRepository plannerRepository) { 23 private final JpaRegionRepository regionRepository; 24 private final JpaCityRepository cityRepository; 25 private final JpaUserRepository userRepository; 26 private final JpaCategoryRepository categoryRepository; 27 private final JpaCompanionRepository companionRepository; 28 29 public LocationServiceImpl(JpaLocationRepository locationRepository, JpaPlannerRepository plannerRepository, JpaRegionRepository regionRepository, JpaCityRepository cityRepository, JpaUserRepository userRepository, JpaCategoryRepository categoryRepository, JpaCompanionRepository companionRepository) { 23 30 this.locationRepository = locationRepository; 24 31 this.plannerRepository = plannerRepository; 32 this.regionRepository = regionRepository; 33 this.cityRepository = cityRepository; 34 this.userRepository = userRepository; 35 this.categoryRepository = categoryRepository; 36 this.companionRepository = companionRepository; 25 37 } 26 38 … … 151 163 } 152 164 } 153 154 165 return newList; 155 166 } … … 189 200 } 190 201 202 @Override 203 public Optional<Location> save(LocationDto locationDto, String username) { 204 City city = new City(); 205 Region region = this.regionRepository.findById(locationDto.getRegion()) 206 .orElseThrow(() -> new RegionNotFoundException(locationDto.getRegion())); 207 if(locationDto.getCity() != null){ 208 city = this.cityRepository.findById(locationDto.getCity()) 209 .orElseThrow(() -> new CityNotFoundException(locationDto.getCity())); 210 }else{ 211 city = null; 212 } 213 User user = this.userRepository.findByUsername(username); 214 locationDto.setUser(user.getUsername()); 215 return Optional.of(this.locationRepository.save(new Location(locationDto.getName(), locationDto.getDescription(), locationDto.getAddress(), locationDto.getPriority(), 216 locationDto.getDuration(), locationDto.getTrivia(), locationDto.getPhoto(), region, city, user))); 217 } 191 218 192 219 }
Note:
See TracChangeset
for help on using the changeset viewer.