Index: sources/app/src/main/java/parkup/services/AdministratorService.java
===================================================================
--- sources/app/src/main/java/parkup/services/AdministratorService.java	(revision 2ace8f05cb6199d05ce30472306247199bdbfa30)
+++ sources/app/src/main/java/parkup/services/AdministratorService.java	(revision 9ff45d65e1d0058eb0c79395ba62a726630c2daa)
@@ -137,21 +137,5 @@
 
         String token = UUID.randomUUID().toString();
-<<<<<<< HEAD
-//        ConfirmationTokenRP confirmationToken = new ConfirmationTokenRP(
-//                token,
-//                LocalDateTime.now(),
-//                LocalDateTime.now().plusMinutes(15),
-//                administrator
-//        );
-=======
-        //ConfirmationTokenRP confirmationToken = new ConfirmationTokenRP(
-        //        token,
-        //        LocalDateTime.now(),
-        //        LocalDateTime.now().plusMinutes(15),
-        //        administrator
-        //);
->>>>>>> 9504a097ce80831ea7e7130dff7215d5fbf8e939
 
-        //confirmationTokenService.saveConfirmationToken(confirmationToken);
 
         // TODO: SEND EMAIL
Index: sources/app/src/main/java/parkup/services/ParkingSessionService.java
===================================================================
--- sources/app/src/main/java/parkup/services/ParkingSessionService.java	(revision 2ace8f05cb6199d05ce30472306247199bdbfa30)
+++ sources/app/src/main/java/parkup/services/ParkingSessionService.java	(revision 9ff45d65e1d0058eb0c79395ba62a726630c2daa)
@@ -4,23 +4,42 @@
 import org.springframework.stereotype.Service;
 import parkup.data.Tablicka;
+import parkup.data.enumarations.SessionStatus;
 import parkup.entities.ParkingSession;
+import parkup.entities.ParkingSpace;
+import parkup.entities.ParkingZone;
 import parkup.repositories.ParkingSessionRepository;
+import parkup.repositories.ParkingSpaceRepository;
+import parkup.repositories.ParkingZoneRepository;
+import parkup.repositories.TablickaRepository;
 
 import javax.transaction.Transactional;
+import java.time.Duration;
+import java.time.LocalDateTime;
 import java.util.List;
-import java.util.Objects;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 @Service
 public class ParkingSessionService {
     private final ParkingSessionRepository parkingSessionRepository;
+    private final ParkingZoneRepository parkingZoneRepository;
+    private final ParkingSpaceRepository parkingSpaceRepository;
+    private final TablickaRepository tablickaRepository;
 
     @Autowired
-    public ParkingSessionService(ParkingSessionRepository parkingSessionRepository) {
+    public ParkingSessionService(ParkingSessionRepository parkingSessionRepository, ParkingZoneRepository parkingZoneRepository, ParkingSpaceRepository parkingSpaceRepository, TablickaRepository tablickaRepository) {
         this.parkingSessionRepository = parkingSessionRepository;
+        this.parkingZoneRepository = parkingZoneRepository;
+        this.parkingSpaceRepository = parkingSpaceRepository;
+        this.tablickaRepository = tablickaRepository;
     }
 
+    //TODO add getMethod for paid sessions or all sessions
+
     public List<ParkingSession> getAllParkingSessions() {
-        return parkingSessionRepository.findAll();
+        //Get all sessions that arent paid
+        return parkingSessionRepository.findAll().stream()
+                .filter(s->!s.getStatus().equals(SessionStatus.ENDED_PAID))
+                .collect(Collectors.toList());
     }
 
@@ -30,5 +49,5 @@
     }
 
-    @Transactional
+   /* @Transactional
     public void updateParkingSession(int parkingSessionId, String timeStart, String timeEnd, Tablicka tablicka) {
         Optional<ParkingSession> parkingSessionOpt = Optional.ofNullable(parkingSessionRepository.findByPssId(parkingSessionId));
@@ -48,9 +67,10 @@
             throw new IllegalStateException("The ParkingSession does not exist");
         }
-    }
-
+    }*/
+    @Transactional
     public Optional<ParkingSession> deleteParkingSession(int parkingSessionId) {
         Optional<ParkingSession> parkingSessionOpt = Optional.ofNullable(parkingSessionRepository.findByPssId(parkingSessionId));
         if (parkingSessionOpt.isPresent()) {
+            parkingSessionOpt.get().getParkingSpace().setTaken(false);
             parkingSessionRepository.deleteByPssId(parkingSessionId);
             return parkingSessionOpt;
@@ -60,13 +80,103 @@
     }
 
-    public Optional<ParkingSession> addParkingSession(ParkingSession parkingSession) {
-        Optional<ParkingSession> parkingSessionOpt = Optional.ofNullable(parkingSessionRepository.findByPssId(parkingSession.getPssId()));
-        if (parkingSessionOpt.isPresent()) {
-            throw new IllegalStateException("ID already taken, ParkingSession cannot be added");
-        } else {
-            System.out.println(parkingSession);
-            parkingSessionRepository.save(parkingSession);
-            return parkingSessionOpt;
+    @Transactional
+    public Optional<ParkingSession> startParkingSession(String tablica, int parkingZoneId) {
+        ParkingZone parkingZone = parkingZoneRepository.findByPzId(parkingZoneId);
+        Tablicka tablicka = tablickaRepository.findByTablica(tablica);
+        if(tablicka==null) {
+            tablickaRepository.save(new Tablicka(tablica));
         }
+        tablicka=tablickaRepository.findByTablica(tablica);
+        ParkingSession sessionToAdd = new ParkingSession(tablicka);
+        sessionToAdd.setParkingZone(parkingZone);
+        parkingSessionRepository.save(sessionToAdd);
+        return Optional.of(sessionToAdd);
+
+    }
+
+//    public void executePayment(int id){
+//        ParkingSession session = parkingSessionRepository.findByPssId(id);
+//        if(session==null){
+//            throw new IllegalStateException("No such session exists");
+//        }
+//        else if(session.getStatus()== SessionStatus.ENDED_UNPAID){
+//            throw new IllegalStateException("Cannot execute payment on an ended session");
+//        }
+//        session.setStatus(SessionStatus.ENDED_PAID);
+//    }
+
+    public int calculatePayment(int id){
+        ParkingSession session = parkingSessionRepository.findByPssId(id);
+        if(session==null){
+            throw new IllegalStateException("No such session exists");
+        }
+        else if(session.getStatus()== SessionStatus.ENDED_UNPAID){
+            throw new IllegalStateException("Cannot calculate payment on an ended session");
+        }
+        int price = session.getParkingZone().getPrice();
+        return (int) (Math.ceil(Duration.between(session.getTimeEnd(),session.getTimeStart()).toMinutes()/60.0)*price);
+    }
+    @Transactional
+    public ParkingSession verifyParkingSession(int id,String parkingSpaceName,int parkingZoneId){
+        ParkingSession parkingSession = parkingSessionRepository.findByPssId(id);
+        ParkingZone parkingZone = parkingZoneRepository.findByPzId(parkingZoneId);
+        if(parkingSession==null){
+            throw new IllegalStateException("No such session exists");
+        }
+        else if(parkingSession.getStatus()==SessionStatus.STARTED_VERIFIED){
+            throw new IllegalStateException("The session you are trying to verify has already been verified");
+        }
+//        else if(parkingSession.getStatus()!=SessionStatus.STARTED_)
+        if(!parkingZone.getParkingSpaces().contains(parkingSpaceRepository.findByPsName(parkingSpaceName))){
+            throw new IllegalStateException("Ivalid parking space inserted. Type in a new parking space or let the admin know that they should add the parking space to this zone");
+        }
+        parkingSession.setStatus(SessionStatus.STARTED_VERIFIED);
+        ParkingSpace parkingSpace = parkingZoneRepository.findByPzId(parkingZoneId).getParkingSpaces().stream().filter(ps->ps.getPsName().equals(parkingSpaceName)).findFirst().get();
+        parkingSpace.setTaken(true);
+        parkingSession.setParkingSpace(parkingSpace);
+        return parkingSession;
+    }
+    @Transactional
+    public ParkingSession endParkingSession(int id){
+        ParkingSession parkingSession = parkingSessionRepository.findByPssId(id);
+        if(parkingSession==null){
+            throw new IllegalStateException("No such session exists");
+        }
+        else if(parkingSession.getStatus()==SessionStatus.ENDED_UNPAID){
+            throw new IllegalStateException("The session you are trying to end has already been ended");
+        }
+        parkingSession.setStatus(SessionStatus.ENDED_UNPAID);
+        parkingSession.setTimeEnd(LocalDateTime.now());
+        return parkingSession;
+    }
+    @Transactional
+    public boolean payParkingSession(int id,String date){
+        ParkingSession parkingSession = parkingSessionRepository.findByPssId(id);
+        String expMonthString=date.split("/")[0];
+        String expYearString=date.split("/")[1];
+        if(expMonthString.startsWith("0"))
+            expMonthString=expYearString.substring(1);
+        if(expYearString.startsWith("0"))
+            expYearString=expYearString.substring(1);
+        int expMonth=Integer.parseInt(expMonthString);
+        int expYear=Integer.parseInt(expYearString);
+        int month = LocalDateTime.now().getMonth().getValue();
+        int year = LocalDateTime.now().getYear()%100;
+        if(year>expYear){
+            throw new IllegalStateException("Your card has expired or the date that you have entered is incorrect");
+        }
+        else if(year==expYear){
+            if(month>=expMonth)
+                throw new IllegalStateException("Your card has expired or the date that you have entered is incorrect");
+        }
+        if(parkingSession==null){
+            throw new IllegalStateException("No such session exists");
+        }
+        else if(parkingSession.getStatus()==SessionStatus.ENDED_PAID){
+            throw new IllegalStateException("The session has already been paid for");
+        }
+        parkingSession.setStatus(SessionStatus.ENDED_PAID);
+        parkingSession.getParkingSpace().setTaken(false);
+        return true;
     }
 }
Index: sources/app/src/main/java/parkup/services/ParkingSpaceService.java
===================================================================
--- sources/app/src/main/java/parkup/services/ParkingSpaceService.java	(revision 2ace8f05cb6199d05ce30472306247199bdbfa30)
+++ sources/app/src/main/java/parkup/services/ParkingSpaceService.java	(revision 9ff45d65e1d0058eb0c79395ba62a726630c2daa)
@@ -5,4 +5,5 @@
 import parkup.entities.ParkingSpace;
 import parkup.repositories.ParkingSpaceRepository;
+import parkup.repositories.ParkingZoneRepository;
 
 import javax.transaction.Transactional;
@@ -10,12 +11,15 @@
 import java.util.Objects;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 @Service
 public class ParkingSpaceService {
     private final ParkingSpaceRepository parkingSpaceRepository;
+    private final ParkingZoneRepository parkingZoneRepository;
 
     @Autowired
-    public ParkingSpaceService(ParkingSpaceRepository parkingSpaceRepository) {
+    public ParkingSpaceService(ParkingSpaceRepository parkingSpaceRepository, ParkingZoneRepository parkingZoneRepository) {
         this.parkingSpaceRepository = parkingSpaceRepository;
+        this.parkingZoneRepository = parkingZoneRepository;
     }
 
@@ -29,17 +33,17 @@
     }
 
-    public Optional<ParkingSpace> addParkingSpace(ParkingSpace parkingSpace) {
-        Optional<ParkingSpace> parkingSpaceOpt = Optional.ofNullable(parkingSpaceRepository.findByPsName(parkingSpace.getPsName()));
-        if (parkingSpaceOpt.isPresent()) {
-            throw new IllegalStateException("Name already taken, try adding a ParkingZone with a different name");
+    public Optional<ParkingSpace> addParkingSpace(ParkingSpace parkingSpace,int parkingZoneId) {
+        List<String> names = parkingZoneRepository.findByPzId(parkingZoneId).getParkingSpaces().stream().map(ParkingSpace::getPsName).collect(Collectors.toList());
+        if (names.contains(parkingSpace.getPsName())) {
+            throw new IllegalStateException("Name already taken, try adding a ParkingSpace with a different name");
         } else {
             System.out.println(parkingSpace);
             parkingSpaceRepository.save(parkingSpace);
         }
-        return parkingSpaceOpt;
+        return Optional.of(parkingSpace);
     }
 
     @Transactional
-    public ParkingSpace updateParkingSpace(int parkingSpaceId, String psName, boolean taken, boolean handicaped, float lat, float lng) {
+    public ParkingSpace updateParkingSpace(int parkingSpaceId, String psName, boolean taken, float lat, float lng) {
         Optional<ParkingSpace> ParkingSpaceOpt = Optional.ofNullable(parkingSpaceRepository.findByPsId(parkingSpaceId));
         if (ParkingSpaceOpt.isPresent()) {
@@ -58,7 +62,4 @@
             }
 
-            if (!Objects.equals(ParkingSpaceNov.isHandicaped(), handicaped)) {
-                ParkingSpaceNov.setHandicaped(handicaped);
-            }
 
             if(lat!=0 && !Objects.equals(ParkingSpaceNov.getLat(), lat)){
@@ -85,3 +86,6 @@
         return parkingSpaceOpt;
     }
+    public long getNumberOfTakenSpaces(){
+        return parkingSpaceRepository.findAll().stream().filter(ParkingSpace::isTaken).count();
+    }
 }
Index: sources/app/src/main/java/parkup/services/ParkingZoneService.java
===================================================================
--- sources/app/src/main/java/parkup/services/ParkingZoneService.java	(revision 2ace8f05cb6199d05ce30472306247199bdbfa30)
+++ sources/app/src/main/java/parkup/services/ParkingZoneService.java	(revision 9ff45d65e1d0058eb0c79395ba62a726630c2daa)
@@ -2,11 +2,14 @@
 
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.stereotype.Service;
 import parkup.data.ParkingZoneLocation;
+import parkup.entities.ParkingSession;
 import parkup.entities.ParkingSpace;
 import parkup.entities.ParkingZone;
 import parkup.entities.Vraboten;
+import parkup.repositories.ParkingSessionRepository;
+import parkup.repositories.ParkingSpaceRepository;
 import parkup.repositories.ParkingZoneRepository;
+import parkup.repositories.VrabotenRepository;
 
 import javax.transaction.Transactional;
@@ -19,8 +22,14 @@
 public class ParkingZoneService {
     private final ParkingZoneRepository parkingZoneRepository;
+    private final ParkingSpaceRepository parkingSpaceRepository;
+    private final VrabotenRepository vrabotenRepository;
+    private final ParkingSessionRepository parkingSessionRepository;
 
     @Autowired
-    public ParkingZoneService(ParkingZoneRepository parkingZoneRepository) {
+    public ParkingZoneService(ParkingZoneRepository parkingZoneRepository, ParkingSpaceRepository parkingSpaceRepository, VrabotenRepository vrabotenRepository, ParkingSessionRepository parkingSessionRepository) {
         this.parkingZoneRepository = parkingZoneRepository;
+        this.parkingSpaceRepository = parkingSpaceRepository;
+        this.parkingSessionRepository = parkingSessionRepository;
+        this.vrabotenRepository = vrabotenRepository;
     }
 
@@ -37,5 +46,5 @@
         List<ParkingZone> parkingZones = this.parkingZoneRepository.findAll();
         List<String> parkingZonesNames = new ArrayList<>();
-        for (ParkingZone pz : parkingZones){
+        for (ParkingZone pz : parkingZones) {
             parkingZonesNames.add(pz.getPzName());
         }
@@ -65,91 +74,88 @@
     }
 
-<<<<<<< HEAD
     //TODO proveri dali ima odgovorni i dokolku ima dali postojat vo bazata
     @Transactional
-    public ParkingZone updateParkingZone(int parkingZoneId, String pzName, int price, int capacity,
+    public ParkingZone updateParkingZone(int parkingZoneId, String pzName, int price,
                                          String location, int from, int to, String color,
-                                         List<ParkingSpace> parkingSpaces, ParkingZoneLocation parkingZoneLocation, List<Vraboten> odgovorniLica) {
+                                         List<ParkingSpace> parkingSpaces, ParkingZoneLocation parkingZoneLocation, List<Integer> odgovorniLica) {
 
-        for(ParkingSpace space:parkingSpaces){
-            System.out.println(space);
-        }
-        for(Vraboten v : odgovorniLica){
-            System.out.println(v.toString());
-        }
-=======
-    //TODO prati niza od objekti ParkingSpaces i prati objekt ParkingZoneLocation
-    @Transactional
-    public ParkingZone updateParkingZone(int parkingZoneId, String pzName, int price, int capacity,
-                                         String location, int from, int to, String color,
-                                         List<ParkingSpace> parkingSpaces, ParkingZoneLocation parkingZoneLocation) {
->>>>>>> 9504a097ce80831ea7e7130dff7215d5fbf8e939
-        Optional<ParkingZone> parkingZoneOpt = Optional.ofNullable(parkingZoneRepository.findByPzId(parkingZoneId));
-        if (parkingZoneOpt.isPresent()) {
+        //TODO prati niza od objekti ParkingSpaces i prati objekt ParkingZoneLocation
+
             ParkingZone parkingZoneNov = parkingZoneRepository.findByPzId(parkingZoneId);
-            if (pzName != null && pzName.length() > 1 && !Objects.equals(parkingZoneNov.getPzName(), pzName)) {
-                Optional<ParkingZone> parkingZoneOpt1 = Optional.ofNullable(parkingZoneRepository.findByPzName(pzName));
-                if (parkingZoneOpt1.isPresent()) {
-                    throw new IllegalStateException("There is already a ParkingZone with the same name");
+            if (parkingZoneNov!=null) {
+                if (pzName != null && pzName.length() > 1) { ;
+                    if (parkingZoneNov.getPzName().equals(pzName)&&parkingZoneNov.getId()!=parkingZoneId) {
+                        throw new IllegalStateException("There is already a ParkingZone with the same name");
+                    }
+
+                    parkingZoneNov.setPzName(pzName);
                 }
 
-                parkingZoneNov.setPzName(pzName);
+                if (price != 0 && !Objects.equals(parkingZoneNov.getPrice(), price)) {
+                    parkingZoneNov.setPrice(price);
+                }
+
+                if (location != null && location.length() > 0 && !Objects.equals(parkingZoneNov.getAddress(), location)) {
+                    parkingZoneNov.setAddress(location);
+                }
+
+                if (from != 0 && !Objects.equals(parkingZoneNov.getFrom(), from)) {
+                    parkingZoneNov.setFrom(from);
+                }
+
+                if (to != 0 && !Objects.equals(parkingZoneNov.getTo(), to)) {
+                    parkingZoneNov.setTo(to);
+                }
+
+                if (color != null && color.length() > 0 && !Objects.equals(parkingZoneNov.getColor(), color)) {
+                    parkingZoneNov.setColor(color);
+                }
+
+                if (parkingZoneLocation != null) {
+                    parkingZoneNov.setParkingZoneLocation(parkingZoneLocation);
+                }
+
+                if (!parkingSpaces.isEmpty()) {
+                    ParkingZone parkingZone = parkingZoneRepository.findByPzId(parkingZoneId);
+//                    for(ParkingSpace space :parkingZone.getParkingSpaces()){
+//                        if(!parkingSpaces.contains(space)){
+//                            for(ParkingSession session: parkingSessionRepository.findByParkingZonePzName(pzName)){
+//                                if(session.getParkingSpace().getPsId()==space.getPsId())
+//                                    throw new IllegalStateException("Vlegov vo iffot");
+//                            }
+//                        }
+//                    }
+                    //TODO: treba da se opravi 
+                    parkingZone.setParkingSpaces(null);
+                    List<ParkingSpace> spacesToAdd = new ArrayList<>(parkingSpaces);
+                    parkingZone.setParkingSpaces(spacesToAdd);
+                }
+                if (!odgovorniLica.isEmpty()) {
+                    ParkingZone parkingZone = parkingZoneRepository.findByPzId(parkingZoneId);
+                    for (Integer vrabotenId : odgovorniLica) {
+                        Vraboten vrabotenToAdd = vrabotenRepository.findByVrabotenId(vrabotenId);
+                        if(vrabotenToAdd!=null)
+                        vrabotenToAdd.getParkingZones().add(parkingZone);
+                    }
+                }
+
+
+                return parkingZoneNov;
+            } else {
+                throw new IllegalStateException("There ParkingZone does not exist");
             }
+        }
 
-            if (price != 0 && !Objects.equals(parkingZoneNov.getPrice(), price)) {
-                parkingZoneNov.setPrice(price);
+
+        @Transactional
+        public Optional<ParkingZone> deleteParkingZone ( int parkingZoneId){
+            Optional<ParkingZone> parkingZoneOpt = Optional.ofNullable(parkingZoneRepository.findByPzId(parkingZoneId));
+            if (parkingZoneOpt.isPresent()) {
+                parkingZoneRepository.deleteByPzId(parkingZoneId);
+            } else {
+                throw new IllegalStateException("ParkingZone doesn't exist, therefore can't be deleted");
             }
-
-            if (capacity != 0 && !Objects.equals(parkingZoneNov.getCapacity(), capacity)) {
-                parkingZoneNov.setCapacity(capacity);
-            }
-
-            if (location != null && location.length() > 0 && !Objects.equals(parkingZoneNov.getLocation(), location)) {
-                parkingZoneNov.setLocation(location);
-            }
-
-            if (from != 0 && !Objects.equals(parkingZoneNov.getFrom(), from)) {
-                parkingZoneNov.setFrom(from);
-            }
-
-            if (to != 0 && !Objects.equals(parkingZoneNov.getTo(), to)) {
-                parkingZoneNov.setTo(to);
-            }
-
-            if (color != null && color.length() > 0 && !Objects.equals(parkingZoneNov.getColor(), color)) {
-                parkingZoneNov.setColor(color);
-            }
-
-            if(parkingZoneLocation!=null){
-                parkingZoneNov.setParkingZoneLocation(parkingZoneLocation);
-            }
-
-            if(!parkingSpaces.isEmpty()){
-                //TODO kreiraj lista od parkingSpaces, ni gi prakja false isHandicaped i isTaken
-                parkingZoneNov.setParkingSpaces(parkingSpaces);
-            }
-<<<<<<< HEAD
-            if(!odgovorniLica.isEmpty()){
-
-                parkingZoneNov.setOdgovorniLica(odgovorniLica);
-            }
-=======
->>>>>>> 9504a097ce80831ea7e7130dff7215d5fbf8e939
-
-            return parkingZoneNov;
-        } else {
-            throw new IllegalStateException("There ParkingZone does not exist");
+            return parkingZoneOpt;
         }
     }
 
-    @Transactional
-    public Optional<ParkingZone> deleteParkingZone(int parkingZoneId) {
-        Optional<ParkingZone> parkingZoneOpt = Optional.ofNullable(parkingZoneRepository.findByPzId(parkingZoneId));
-        if (parkingZoneOpt.isPresent()) {
-            parkingZoneRepository.deleteByPzId(parkingZoneId);
-        } else {
-            throw new IllegalStateException("ParkingZone doesn't exist, therefore can't be deleted");
-        }
-        return parkingZoneOpt;
-    }
-}
Index: sources/app/src/main/java/parkup/services/VrabotenService.java
===================================================================
--- sources/app/src/main/java/parkup/services/VrabotenService.java	(revision 2ace8f05cb6199d05ce30472306247199bdbfa30)
+++ sources/app/src/main/java/parkup/services/VrabotenService.java	(revision 9ff45d65e1d0058eb0c79395ba62a726630c2daa)
@@ -3,7 +3,7 @@
 import java.time.LocalDateTime;
 import java.util.*;
+import java.util.stream.Collectors;
 import javax.transaction.Transactional;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.security.core.userdetails.UserDetailsService;
@@ -13,5 +13,8 @@
 import parkup.configs.token.ConfirmationTokenW;
 import parkup.configs.token.ConfirmationTokenService;
+import parkup.data.enumarations.EmployeeStatus;
+import parkup.entities.ParkingZone;
 import parkup.entities.Vraboten;
+import parkup.repositories.ParkingZoneRepository;
 import parkup.repositories.VrabotenRepository;
 import parkup.data.VrabotenDemo;
@@ -20,10 +23,12 @@
 public class VrabotenService implements UserDetailsService {
     private final VrabotenRepository vrabotenRepository;
+    private final ParkingZoneRepository parkingZoneRepository;
     private final BCryptPasswordEncoder bCryptPasswordEncoder;
     private final ConfirmationTokenService confirmationTokenService;
 
     @Autowired
-    public VrabotenService(VrabotenRepository vrabotenRepository, BCryptPasswordEncoder bCryptPasswordEncoder, ConfirmationTokenService confirmationTokenService) {
+    public VrabotenService(VrabotenRepository vrabotenRepository, ParkingZoneRepository parkingZoneRepository, BCryptPasswordEncoder bCryptPasswordEncoder, ConfirmationTokenService confirmationTokenService) {
         this.vrabotenRepository = vrabotenRepository;
+        this.parkingZoneRepository = parkingZoneRepository;
         this.bCryptPasswordEncoder = bCryptPasswordEncoder;
         this.confirmationTokenService = confirmationTokenService;
@@ -43,5 +48,5 @@
         List<VrabotenDemo> vrabotenDemos = new ArrayList<>();
         for (Vraboten v : vraboteni){
-            VrabotenDemo vd = new VrabotenDemo(v.getFirstName(), v.getLastName(), v.getEmail());
+            VrabotenDemo vd = new VrabotenDemo(v.getVrabotenId(),v.getFirstName(), v.getLastName(), v.getEmail());
             vrabotenDemos.add(vd);
         }
@@ -49,56 +54,128 @@
     }
 
-    public Optional<Vraboten> addVraboten(Vraboten vraboten) {
-        Optional<Vraboten> vrabotenOpt = this.vrabotenRepository.findVrabotenByEmail(vraboten.getEmail());
-        if (vrabotenOpt.isPresent()) {
-            throw new IllegalStateException("Email already taken, try adding a vraboten with a different valid email address");
+    public Optional<Vraboten> addVraboten(String password,String confirmPass,boolean locked, String firstName, String lastName, String mobile, String email, EmployeeStatus status,List<String> parkingZones) {
+        Optional<Vraboten> vrabotenOpt = this.vrabotenRepository.findVrabotenByEmail(email);
+        if (vrabotenOpt.isPresent()){
+            throw new IllegalArgumentException("User with that mail already exists");
+        }
+        Vraboten vrabotenToAdd=new Vraboten();
+        if (email != null && email.length() > 1 && email.contains("@") ) {
+            vrabotenToAdd.setEmail(email);
         } else {
-            if (vraboten.getEmail() != null && vraboten.getEmail().length() > 1 && vraboten.getEmail().contains("@")) {
-                //System.out.println(vraboten);
-                this.vrabotenRepository.save(vraboten);
-            }
-            else{
-                throw new IllegalStateException("email not valid");
-            }
-        }
-        return vrabotenOpt;
+            throw new IllegalStateException("email not valid");
+        }
+        if(password.equals(confirmPass)){
+            vrabotenToAdd.setPassword(bCryptPasswordEncoder.encode(password));
+        }
+        vrabotenToAdd.setLocked(locked);
+
+        if (firstName != null && firstName.length() > 1) {
+            vrabotenToAdd.setFirstName(firstName);
+        }
+
+        if (lastName != null && lastName.length() > 1 ) {
+            vrabotenToAdd.setLastName(lastName);
+        }
+
+        if (mobile != null && mobile.length() > 0 ) {
+            vrabotenToAdd.setMobile(mobile);
+        }
+
+        vrabotenToAdd.setStatus(status);
+
+        if(parkingZones!=null){
+            List<ParkingZone> parkingZonesAvailable =parkingZoneRepository.findAll();
+            List<ParkingZone> zonesToAdd= new ArrayList<>();
+            vrabotenToAdd.setParkingZones(null);
+            for(String pzName:parkingZones){
+                for(ParkingZone pz :parkingZonesAvailable){
+                    if(pzName.equals(pz.getPzName())) {
+                        zonesToAdd.add(pz);
+//                            pz.getOdgovorniLica().add(vrabotenRepository.findByVrabotenId(vrabotenId));
+                    }
+                }
+            }
+            vrabotenToAdd.setParkingZones(zonesToAdd);
+        }
+        String token = UUID.randomUUID().toString();
+        ConfirmationTokenW confirmationTokenW = new ConfirmationTokenW(
+                token,
+                LocalDateTime.now(),
+                LocalDateTime.now().plusMinutes(15),
+                vrabotenToAdd
+        );
+
+        confirmationTokenService.saveConfirmationTokenW(confirmationTokenW);
+
+        return Optional.of(vrabotenToAdd);
+//        Optional<Vraboten> vrabotenOpt = this.vrabotenRepository.findVrabotenByEmail(vraboten.getEmail());
+//        if (vrabotenOpt.isPresent()) {
+//            throw new IllegalStateException("Email already taken, try adding a vraboten with a different valid email address");
+//        } else {
+//            if (vraboten.getEmail() != null && vraboten.getEmail().length() > 1 && vraboten.getEmail().contains("@")) {
+//                //System.out.println(vraboten);
+//                this.vrabotenRepository.save(vraboten);
+//            }
+//            else{
+//                throw new IllegalStateException("email not valid");
+//            }
+//        }
+//        return vrabotenOpt;
     }
 
     @Transactional
-    public Vraboten updateVraboten(int vrabotenId, String firstName, String lastName, String mobile, String email, String status) {
+    public Vraboten updateVraboten(int vrabotenId,String password,String confirmPass,boolean locked, String firstName, String lastName, String mobile, String email, EmployeeStatus status,List<String> parkingZones) {
         Optional<Vraboten> vrabotenOpt = Optional.ofNullable(this.vrabotenRepository.findByVrabotenId(vrabotenId));
         if (vrabotenOpt.isPresent()) {
-            Vraboten vrabotenNov = this.vrabotenRepository.findByVrabotenId(vrabotenId);
-            if (email != null && email.length() > 1 && email.contains("@") && !Objects.equals(vrabotenNov.getEmail(), email)) {
-                Optional<Vraboten> userOpt1 = this.vrabotenRepository.findVrabotenByEmail(email);
-                if (userOpt1.isPresent()) {
+
+            if (email != null && email.length() > 1 && email.contains("@") ) {
+                List<String> emails = vrabotenRepository.findAll().stream().map(Vraboten::getEmail).collect(Collectors.toList());
+                for(String mailToCheck :emails)
+                if (email.equals(mailToCheck)&&vrabotenOpt.get().getVrabotenId()!=vrabotenId) {
                     throw new IllegalStateException("email taken");
                 }
-                vrabotenNov.setEmail(email);
+                vrabotenOpt.get().setEmail(email);
             } else {
                 throw new IllegalStateException("email not valid");
             }
-
-            if (firstName != null && firstName.length() > 1 && !Objects.equals(vrabotenNov.getFirstName(), firstName)) {
-                vrabotenNov.setFirstName(firstName);
-            }
-
-            if (lastName != null && lastName.length() > 1 && !Objects.equals(vrabotenNov.getLastName(), lastName)) {
-                vrabotenNov.setLastName(lastName);
-            }
-
-            if (mobile != null && mobile.length() > 0 && !Objects.equals(vrabotenNov.getMobile(), mobile)) {
-                vrabotenNov.setMobile(mobile);
-            }
-
-            if (mobile != null && status.length() > 0 && !Objects.equals(vrabotenNov.getStatus(), status)) {
-                if(status.equals("raboti") || status.equals("ne raboti") || status.equals("na odmor") || status.equals("na boleduvanje")){
-                    vrabotenNov.setStatus(status);
-                }else{
-                    throw new IllegalStateException("Please enter one of the following statuses: 'raboti', 'ne raboti', 'na odmor', 'na boleduvanje'");
+            if(password.equals(confirmPass)){
+                vrabotenOpt.get().setPassword(bCryptPasswordEncoder.encode(password));
+            }
+            vrabotenOpt.get().setLocked(locked);
+
+            if (firstName != null && firstName.length() > 1 && !Objects.equals(vrabotenOpt.get().getFirstName(), firstName)) {
+                vrabotenOpt.get().setFirstName(firstName);
+            }
+
+            if (lastName != null && lastName.length() > 1 && !Objects.equals(vrabotenOpt.get().getLastName(), lastName)) {
+                vrabotenOpt.get().setLastName(lastName);
+            }
+
+            if (mobile != null && mobile.length() > 0 && !Objects.equals(vrabotenOpt.get().getMobile(), mobile)) {
+                vrabotenOpt.get().setMobile(mobile);
+            }
+
+//            if (status != null && status.toString().length() > 0) {
+//                if(Arrays.stream(EmployeeStatus.values()).toList().contains(EmployeeStatus.valueOf(status))){
+            vrabotenOpt.get().setStatus(status);
+//                }else{
+//                    throw new IllegalStateException("Please enter one of the following statuses: 'raboti', 'ne raboti', 'na odmor', 'na boleduvanje'");
+//                }
+//            }
+            if(parkingZones!=null){
+                List<ParkingZone> parkingZonesAvailable =parkingZoneRepository.findAll();
+                List<ParkingZone> zonesToAdd= new ArrayList<>();
+                vrabotenOpt.get().setParkingZones(null);
+                for(String pzName:parkingZones){
+                    for(ParkingZone pz :parkingZonesAvailable){
+                        if(pzName.equals(pz.getPzName())) {
+                            zonesToAdd.add(pz);
+//                            pz.getOdgovorniLica().add(vrabotenRepository.findByVrabotenId(vrabotenId));
+                        }
+                    }
                 }
-            }
-
-            return vrabotenNov;
+                vrabotenOpt.get().setParkingZones(zonesToAdd);
+            }
+            return vrabotenOpt.get();
         }
         else{
@@ -107,10 +184,8 @@
     }//za menjanje password da se implementira
 
-    @Modifying
     @Transactional
     public Optional<Vraboten> deleteVraboten(int vrabotenId) {
         Optional<Vraboten> vrabotenOpt = Optional.ofNullable(this.vrabotenRepository.findByVrabotenId(vrabotenId));
         if (vrabotenOpt.isPresent()) {
-            //TODO da povikamo metod od ConfirmationTokenService za brisenje na ConfirmationTokenW
             this.confirmationTokenService.deleteByVraboten_VrabotenId(vrabotenId);
             this.vrabotenRepository.deleteByVrabotenId(vrabotenId);
@@ -129,5 +204,5 @@
             throw new IllegalStateException("Vraboten doesn't exist, therefore his account can't be locked/unlocked");
         }
-    }//dali treba da stoi @Transactional gore nad funkcijata?
+    }
 
     @Override
@@ -176,3 +251,13 @@
     }
 
+//    @Transactional
+//    public void setVrabotenStatus(int vrabotenId,String vrabotenStatus) {
+//        Vraboten vraboten = vrabotenRepository.findByVrabotenId(vrabotenId);
+//        if(vraboten!=null && value){
+//            vraboten.setStatus(valuee);
+//        }
+//        else {
+//            throw new IllegalStateException(String.format("Vraboten with id %d does not exist.",vrabotenId));
+//        }
+//    }
 }
