diff --git a/src/main/java/com/labwork1/app/student/service/SessionService.java b/src/main/java/com/labwork1/app/student/service/SessionService.java index 3597b7e..9088717 100644 --- a/src/main/java/com/labwork1/app/student/service/SessionService.java +++ b/src/main/java/com/labwork1/app/student/service/SessionService.java @@ -39,6 +39,12 @@ public class SessionService { .orElseThrow(() -> new SessionNotFoundException(id)); } + @Transactional(readOnly = true) + public Session findBaseSession(Long id) { + return sessionRepository.findById(id) + .orElseThrow(() -> new SessionNotFoundException(id)); + } + @Transactional(readOnly = true) public List findAllSessions() { return sessionRepository.getSessionsWithCapacity(); @@ -46,7 +52,7 @@ public class SessionService { @Transactional public Session updateSession(Long id, Double price) { - final Session currentSession = findSession(id); + final Session currentSession = findBaseSession(id); currentSession.setPrice(price); validatorUtil.validate(currentSession); return sessionRepository.save(currentSession); @@ -54,7 +60,7 @@ public class SessionService { @Transactional public Session deleteSession(Long id) { - final Session currentSession = findSession(id); + final Session currentSession = findBaseSession(id); // все равно сеанс не удалился бы, который участвует в заказах // для отслеживания операции с ошибкой if (currentSession.getOrders().size() > 0)