Ignore:
Timestamp:
12/19/21 19:39:00 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
bdd6491
Parents:
1ad8e64
Message:

spring security 2.0

Location:
trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl
Files:
1 added
2 edited

Legend:

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

    r1ad8e64 r84d0fbb  
    33import finki.diplomska.tripplanner.models.Location;
    44import finki.diplomska.tripplanner.models.Planner;
     5import finki.diplomska.tripplanner.models.User;
    56import finki.diplomska.tripplanner.models.dto.PlannerDto;
    67import finki.diplomska.tripplanner.models.exceptions.LocationNotFoundException;
     
    89import finki.diplomska.tripplanner.repository.jpa.JpaLocationRepository;
    910import finki.diplomska.tripplanner.repository.jpa.JpaPlannerRepository;
    10 import finki.diplomska.tripplanner.service.LocationService;
     11import finki.diplomska.tripplanner.repository.jpa.JpaUserRepository;
    1112import finki.diplomska.tripplanner.service.PlannerService;
    1213import org.springframework.stereotype.Service;
    13 import reactor.util.annotation.Nullable;
    1414
    15 import java.util.ArrayList;
     15import javax.jws.soap.SOAPBinding;
    1616import java.util.List;
    1717import java.util.Optional;
     
    2222    private final JpaPlannerRepository plannerRepository;
    2323    private final JpaLocationRepository locationRepository;
     24    private final JpaUserRepository userRepository;
    2425
    25     public PlannerServiceImpl(JpaPlannerRepository plannerRepository, JpaLocationRepository locationRepository) {
     26    public PlannerServiceImpl(JpaPlannerRepository plannerRepository, JpaLocationRepository locationRepository, JpaUserRepository userRepository) {
    2627        this.plannerRepository = plannerRepository;
    2728        this.locationRepository = locationRepository;
     29        this.userRepository = userRepository;
    2830    }
    2931
     
    3133    public List<Planner> getAllPlaners() {
    3234        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());
    3341    }
    3442
     
    4048
    4149    @Override
    42     public Optional<Planner> newPlanner(PlannerDto plannerDto) {
     50    public Optional<Planner> newPlanner(PlannerDto plannerDto, String username) {
    4351        /*
    4452        List<Location> locationList  = new ArrayList<>();
     
    4856            locationList.add(loc);
    4957        }
    50 
    5158         */
    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)));
    5362    }
    5463
     
    6978
    7079    @Override
    71     public Optional<Planner> editPlanner(Long id, PlannerDto plannerDto) {
     80    public Optional<Planner> editPlanner(Long id, PlannerDto plannerDto, String username) {
    7281        Planner planner = this.plannerRepository.findById(id).orElseThrow(() -> new PlannerNotFoundException(id));
     82        User user = this.userRepository.findByUsername(username);
    7383
    7484        planner.setName(plannerDto.getName());
    7585        planner.setDescription(plannerDto.getDescription());
     86        plannerDto.setUser(user.getUsername());
     87        planner.setUser(user);
    7688/*
    7789        List<Location> locationList  = new ArrayList<>();
  • trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/UserServiceImpl.java

    r1ad8e64 r84d0fbb  
    99import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
    1010import org.springframework.stereotype.Service;
     11
     12import java.util.Optional;
    1113
    1214
     
    2830            // We don't persist or show the confirmPassword
    2931            newUser.setConfirmPassword("");
    30             return this.userRepository.save(newUser);
     32             return this.userRepository.save(newUser);
    3133        }catch(Exception e){
    3234            throw new UsernameAlreadyExistsException("Username '"+newUser.getUsername()+ "' already exists");
Note: See TracChangeset for help on using the changeset viewer.