Ignore:
Timestamp:
11/11/21 12:59:26 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
59329aa
Parents:
6c1585f
Message:

add location to planner

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/LocationServiceImpl.java

    r6c1585f rceaed42  
    22
    33import finki.diplomska.tripplanner.models.Location;
     4import finki.diplomska.tripplanner.models.Planner;
     5import finki.diplomska.tripplanner.models.dto.PlannerLocationDto;
    46import finki.diplomska.tripplanner.models.exceptions.LocationNotFoundException;
    57import finki.diplomska.tripplanner.repository.jpa.JpaLocationRepository;
     8import finki.diplomska.tripplanner.repository.jpa.JpaPlannerRepository;
    69import finki.diplomska.tripplanner.service.LocationService;
    710import org.springframework.stereotype.Service;
     
    1518
    1619    private final JpaLocationRepository locationRepository;
     20    private final JpaPlannerRepository plannerRepository;
    1721
    18     public LocationServiceImpl(JpaLocationRepository locationRepository) {
     22    public LocationServiceImpl(JpaLocationRepository locationRepository, JpaPlannerRepository plannerRepository) {
    1923        this.locationRepository = locationRepository;
     24        this.plannerRepository = plannerRepository;
    2025    }
    2126
     
    150155    }
    151156
     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
    152172}
Note: See TracChangeset for help on using the changeset viewer.