Ignore:
Timestamp:
02/08/22 23:21:50 (2 years ago)
Author:
andrejTavchioski <andrej.tavchioski@…>
Branches:
master
Children:
0c049e9
Parents:
98f448a
Message:

change in getParkingSpaces logic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sources/app/src/main/java/parkup/services/ParkingZoneService.java

    r98f448a rc71fa06  
    22
    33import org.springframework.beans.factory.annotation.Autowired;
     4import org.springframework.security.core.Authentication;
    45import org.springframework.stereotype.Service;
     6import parkup.ParkUpApplication;
    57import parkup.data.ParkingZoneAdminView;
    68import parkup.data.ParkingZoneLocation;
     
    1315import parkup.repositories.ParkingZoneRepository;
    1416import parkup.repositories.WorkerRepository;
    15 
     17import static parkup.ParkUpApplication.getToken;
    1618import javax.transaction.Transactional;
    1719import java.util.ArrayList;
     
    3739
    3840    public List<ParkingZone> getAllParkingZones() {
    39         List<ParkingZone> parkingZones= parkingZoneRepository.findAll();
     41        Authentication user = getToken();
     42        String role =user.getAuthorities().stream().findFirst().get().getAuthority();
     43        String email = user.getName();
     44        List<ParkingZone> parkingZones;
     45        if(role.equals("ROLE_REG_USER"))
     46            parkingZones= parkingZoneRepository.findAll();
     47        else if(role.equals("ROLE_WORKER")){
     48            Worker loggedInWorker = workerRepository.findWorkerByEmail(email).orElseThrow(null);
     49            parkingZones= parkingZoneRepository.findAll().stream().filter(pz->loggedInWorker.getParkingZones().contains(pz)).collect(Collectors.toList());
     50        }else if(role.equals("ROLE_ADMIN"))
     51            parkingZones= parkingZoneRepository.findAll();
     52        else
     53            parkingZones=parkingZoneRepository.findAll();
    4054        for(ParkingZone pz:parkingZones){
    4155            setTransientVariables(pz);
Note: See TracChangeset for help on using the changeset viewer.