From a41fcf561835d42ffecbe76a72716e1a20041608 Mon Sep 17 00:00:00 2001 From: dasha Date: Sat, 13 May 2023 14:32:40 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D0=B8=D0=BD=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=D0=B5=D0=B0=D0=BD=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../labwork1/app/student/service/SessionService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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)