Index: sources/app/src/main/java/parkup/services/ParkingSessionService.java
===================================================================
--- sources/app/src/main/java/parkup/services/ParkingSessionService.java	(revision b6e52e10c78a9e25dd98add9da2cbe57c2dc2cb8)
+++ sources/app/src/main/java/parkup/services/ParkingSessionService.java	(revision 3b17c69dfd5c6dafba6b762aefa797108693fc03)
@@ -77,8 +77,4 @@
         Authentication token = ParkUpApplication.getToken();
         Plate plate = plateRepository.findByPlate(tablica);
-        if(plate ==null) {
-            plateRepository.save(new Plate(tablica));
-        }
-        plate = plateRepository.findByPlate(tablica);
         ParkingSession sessionToAdd = new ParkingSession(plate);
         sessionToAdd.setParkingZone(parkingZone);
@@ -145,35 +141,14 @@
     @Transactional
     public ParkingSession endParkingSession(){
-        Authentication token = ParkUpApplication.getToken();
-        String role =token.getAuthorities().stream().findFirst().get().getAuthority();
-        String email =token.getName();
-        ParkingSession session;
-        if(role.equals("ROLE_REG_USER")){
-            RegisteredUser user = registeredUserRepository.findRegisteredUserByEmail(email).get();
-            session=user.getSession();
-        }
-        else{
-            Guest user = guestRepository.findGuestByEmail(email).get();
-            session=user.getSession();
-        }
-        if(session==null){
-            throw new IllegalStateException("No such session exists");
-        }
-        else if(session.getStatus()==SessionStatus.ENDED_UNPAID){
+        ParkingSession parkingSession=getParkingSession();
+        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");
         }
-        session.setStatus(SessionStatus.ENDED_UNPAID);
-        session.setTimeEnd(LocalDateTime.now());
-        return session;
-//        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;
+        parkingSession.setStatus(SessionStatus.ENDED_UNPAID);
+        parkingSession.setTimeEnd(LocalDateTime.now());
+        return parkingSession;
     }
     @Transactional
@@ -196,4 +171,25 @@
                 throw new IllegalStateException("Your card has expired or the date that you have entered is incorrect");
         }
+        ParkingSession parkingSession=getParkingSession();
+        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;
+    }
+
+    public SessionStatus getStatusOfParkirac(int regParkId){
+        RegisteredUser registeredUser = registeredUserRepository.findByRegParkId(regParkId);
+        List<String> plates =parkingSessionRepository.findAll().stream().filter(ps->registeredUser.getPlates().contains(ps.getPlate())).map(ps->ps.getPlate().getPlate()).collect(Collectors.toList());
+        if(plates.size()>0)
+        return parkingSessionRepository.findAll().stream().filter(ps->ps.getPlate().getPlate().equals(plates.get(0))).collect(Collectors.toList()).get(0).getStatus();
+        return null;
+    }
+
+    public ParkingSession getParkingSession() {
         Authentication token = ParkUpApplication.getToken();
         String role =token.getAuthorities().stream().findFirst().get().getAuthority();
@@ -208,21 +204,5 @@
             parkingSession=user.getSession();
         }
-        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;
-    }
-
-    public SessionStatus getStatusOfParkirac(int regParkId){
-        RegisteredUser registeredUser = registeredUserRepository.findByRegParkId(regParkId);
-        List<String> plates =parkingSessionRepository.findAll().stream().filter(ps->registeredUser.getPlates().contains(ps.getPlate())).map(ps->ps.getPlate().getPlate()).collect(Collectors.toList());
-        if(plates.size()>0)
-        return parkingSessionRepository.findAll().stream().filter(ps->ps.getPlate().getPlate().equals(plates.get(0))).collect(Collectors.toList()).get(0).getStatus();
-        return null;
+        return parkingSession;
     }
 }
