Index: sources/app/src/main/java/parkup/services/ParkingSessionService.java
===================================================================
--- sources/app/src/main/java/parkup/services/ParkingSessionService.java	(revision 8f153cad3cf9f07b1e4d7cd4b4f4be97050fe0f6)
+++ sources/app/src/main/java/parkup/services/ParkingSessionService.java	(revision 3f0bf09dc007aa9e8eccba37878ab138ddb4acf3)
@@ -2,11 +2,10 @@
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
 import org.springframework.stereotype.Service;
+import parkup.ParkUpApplication;
 import parkup.data.Plate;
 import parkup.data.enumarations.SessionStatus;
-import parkup.entities.ParkingSession;
-import parkup.entities.ParkingSpace;
-import parkup.entities.ParkingZone;
-import parkup.entities.RegisteredUser;
+import parkup.entities.*;
 import parkup.repositories.*;
 
@@ -25,7 +24,8 @@
     private final RegisteredUserRepository registeredUserRepository;
     private final PlateRepository plateRepository;
+    private final GuestRepository guestRepository;
 
     @Autowired
-    public ParkingSessionService(ParkingSessionRepository parkingSessionRepository, ParkingZoneRepository parkingZoneRepository, ParkingSpaceRepository parkingSpaceRepository, RegisteredUserRepository registeredUserRepository, PlateRepository plateRepository) {
+    public ParkingSessionService(ParkingSessionRepository parkingSessionRepository, ParkingZoneRepository parkingZoneRepository, ParkingSpaceRepository parkingSpaceRepository, RegisteredUserRepository registeredUserRepository, PlateRepository plateRepository, GuestRepository guestRepository) {
         this.parkingSessionRepository = parkingSessionRepository;
         this.parkingZoneRepository = parkingZoneRepository;
@@ -33,4 +33,5 @@
         this.registeredUserRepository = registeredUserRepository;
         this.plateRepository = plateRepository;
+        this.guestRepository = guestRepository;
     }
 
@@ -74,4 +75,5 @@
     public Optional<ParkingSession> startParkingSession(String tablica, String parkingZoneName) {
         ParkingZone parkingZone = parkingZoneRepository.findByPzName(parkingZoneName);
+        Authentication token = ParkUpApplication.getToken();
         Plate plate = plateRepository.findByPlate(tablica);
         if(plate ==null) {
@@ -82,4 +84,14 @@
         sessionToAdd.setParkingZone(parkingZone);
         parkingSessionRepository.save(sessionToAdd);
+        String role =token.getAuthorities().stream().findFirst().get().getAuthority();
+        String email =token.getName();
+        if(role.equals("ROLE_REG_USER")){
+            RegisteredUser user = registeredUserRepository.findRegisteredUserByEmail(email).get();
+            user.setSession(sessionToAdd);
+        }
+        else{
+            Guest user = guestRepository.findGuestByEmail(email).get();
+            user.setSession(sessionToAdd);
+        }
         return Optional.of(sessionToAdd);
 
@@ -132,19 +144,39 @@
     }
     @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){
+    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){
             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;
+        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;
     }
     @Transactional
     public boolean payParkingSession(int id,String date){
-        ParkingSession parkingSession = parkingSessionRepository.findByPssId(id);
         String expMonthString=date.split("/")[0];
         String expYearString=date.split("/")[1];
@@ -164,4 +196,16 @@
                 throw new IllegalStateException("Your card has expired or the date that you have entered is incorrect");
         }
+        Authentication token = ParkUpApplication.getToken();
+        String role =token.getAuthorities().stream().findFirst().get().getAuthority();
+        String email =token.getName();
+        ParkingSession parkingSession;
+        if(role.equals("ROLE_REG_USER")){
+            RegisteredUser user = registeredUserRepository.findRegisteredUserByEmail(email).get();
+            parkingSession=user.getSession();
+        }
+        else{
+            Guest user = guestRepository.findGuestByEmail(email).get();
+            parkingSession=user.getSession();
+        }
         if(parkingSession==null){
             throw new IllegalStateException("No such session exists");
