Ignore:
Timestamp:
02/10/22 11:13:18 (2 years ago)
Author:
andrejTavchioski <andrej.tavchioski@…>
Branches:
master
Children:
ccb2d72
Parents:
0c049e9
Message:

calculate payment fix and added error handling

File:
1 edited

Legend:

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

    r0c049e9 rad4da86  
    4141        return parkingSessionRepository.findAll().stream()
    4242                .filter(s->!s.getStatus().equals(SessionStatus.ENDED_PAID))
     43                .collect(Collectors.toList());
     44    }
     45
     46    public List<ParkingSession> getAllParkingSessionsFromZone(Integer pzId) {
     47        //Get all sessions that arent paid
     48
     49        return parkingSessionRepository.findAll().stream()
     50                .filter(s->!s.getStatus().equals(SessionStatus.ENDED_PAID) && s.getParkingZone().getId()==pzId)
    4351                .collect(Collectors.toList());
    4452    }
     
    92100            throw new IllegalStateException("No such session exists");
    93101        }
    94         else if(session.getStatus()== SessionStatus.ENDED_UNPAID){
    95             throw new IllegalStateException("Cannot calculate payment on an ended session");
    96         }
     102//        else if(session.getStatus()!= SessionStatus.ENDED_PAID){
     103//            throw new IllegalStateException("Cannot calculate payment on a paid session");
     104//        }
    97105        int price = session.getParkingZone().getPrice();
    98         return (int) (Math.ceil(Duration.between(session.getTimeEnd(),session.getTimeStart()).toMinutes()/60.0)*price);
     106        return (int) (Math.ceil(Duration.between(session.getTimeStart(),session.getTimeEnd()).toMinutes()/60.0)*price);
    99107    }
    100108    @Transactional
     
    111119        if(!parkingZone.getParkingSpaces().contains(parkingSpaceRepository.findByPsName(parkingSpaceName))){
    112120            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");
     121        }
     122        if(parkingSpaceRepository.findByPsName(parkingSpaceName).isTaken()){
     123            throw new IllegalStateException("Ivalid parking space inserted. Type in a new parking space, this space is already in a session");
    113124        }
    114125        parkingSession.setStatus(SessionStatus.STARTED_VERIFIED);
Note: See TracChangeset for help on using the changeset viewer.