Changeset 84d0fbb for trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/PlannerServiceImpl.java
- Timestamp:
- 12/19/21 19:39:00 (3 years ago)
- Branches:
- master
- Children:
- bdd6491
- Parents:
- 1ad8e64
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/PlannerServiceImpl.java
r1ad8e64 r84d0fbb 3 3 import finki.diplomska.tripplanner.models.Location; 4 4 import finki.diplomska.tripplanner.models.Planner; 5 import finki.diplomska.tripplanner.models.User; 5 6 import finki.diplomska.tripplanner.models.dto.PlannerDto; 6 7 import finki.diplomska.tripplanner.models.exceptions.LocationNotFoundException; … … 8 9 import finki.diplomska.tripplanner.repository.jpa.JpaLocationRepository; 9 10 import finki.diplomska.tripplanner.repository.jpa.JpaPlannerRepository; 10 import finki.diplomska.tripplanner. service.LocationService;11 import finki.diplomska.tripplanner.repository.jpa.JpaUserRepository; 11 12 import finki.diplomska.tripplanner.service.PlannerService; 12 13 import org.springframework.stereotype.Service; 13 import reactor.util.annotation.Nullable;14 14 15 import java .util.ArrayList;15 import javax.jws.soap.SOAPBinding; 16 16 import java.util.List; 17 17 import java.util.Optional; … … 22 22 private final JpaPlannerRepository plannerRepository; 23 23 private final JpaLocationRepository locationRepository; 24 private final JpaUserRepository userRepository; 24 25 25 public PlannerServiceImpl(JpaPlannerRepository plannerRepository, JpaLocationRepository locationRepository ) {26 public PlannerServiceImpl(JpaPlannerRepository plannerRepository, JpaLocationRepository locationRepository, JpaUserRepository userRepository) { 26 27 this.plannerRepository = plannerRepository; 27 28 this.locationRepository = locationRepository; 29 this.userRepository = userRepository; 28 30 } 29 31 … … 31 33 public List<Planner> getAllPlaners() { 32 34 return this.plannerRepository.findAll(); 35 } 36 37 @Override 38 public List<Planner> getPlannersByUser(String username) { 39 User user = this.userRepository.findByUsername(username); 40 return this.plannerRepository.getPlannersByUser(user.getUsername()); 33 41 } 34 42 … … 40 48 41 49 @Override 42 public Optional<Planner> newPlanner(PlannerDto plannerDto ) {50 public Optional<Planner> newPlanner(PlannerDto plannerDto, String username) { 43 51 /* 44 52 List<Location> locationList = new ArrayList<>(); … … 48 56 locationList.add(loc); 49 57 } 50 51 58 */ 52 return Optional.of(this.plannerRepository.save(new Planner(plannerDto.getName(), plannerDto.getDescription(), null))); 59 User user = this.userRepository.findByUsername(username); 60 plannerDto.setUser(user.getUsername()); 61 return Optional.of(this.plannerRepository.save(new Planner(plannerDto.getName(), plannerDto.getDescription(), null, user))); 53 62 } 54 63 … … 69 78 70 79 @Override 71 public Optional<Planner> editPlanner(Long id, PlannerDto plannerDto ) {80 public Optional<Planner> editPlanner(Long id, PlannerDto plannerDto, String username) { 72 81 Planner planner = this.plannerRepository.findById(id).orElseThrow(() -> new PlannerNotFoundException(id)); 82 User user = this.userRepository.findByUsername(username); 73 83 74 84 planner.setName(plannerDto.getName()); 75 85 planner.setDescription(plannerDto.getDescription()); 86 plannerDto.setUser(user.getUsername()); 87 planner.setUser(user); 76 88 /* 77 89 List<Location> locationList = new ArrayList<>();
Note:
See TracChangeset
for help on using the changeset viewer.