From 51f0d4ab158d5a69913efc8275137d97f84359eb Mon Sep 17 00:00:00 2001 From: chyun Date: Sun, 19 Jan 2025 02:28:34 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20[#109]=20=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=20=EC=A1=B4=EC=9E=AC=20=EC=97=AC=EB=B6=80=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/user/facade/UserTimetableFacade.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/sopt/confeti/api/user/facade/UserTimetableFacade.java b/src/main/java/org/sopt/confeti/api/user/facade/UserTimetableFacade.java index 2b1e330..2172140 100644 --- a/src/main/java/org/sopt/confeti/api/user/facade/UserTimetableFacade.java +++ b/src/main/java/org/sopt/confeti/api/user/facade/UserTimetableFacade.java @@ -23,9 +23,7 @@ public class UserTimetableFacade { @Transactional(readOnly = true) public UserTimetableDTO getTimetablesListAndDate(long userId) { - if (!userService.existsById(userId)) { - throw new NotFoundException(ErrorMessage.NOT_FOUND); - } + validateExistUser(userId); List festivalList = timetableFestivalService.getFetivalList(userId); return UserTimetableDTO.from(festivalList); @@ -33,15 +31,32 @@ public UserTimetableDTO getTimetablesListAndDate(long userId) { @Transactional public void removeTimetableFestival(final long userId, final long festivalId) { - if ( - !userService.existsById(userId) || - !festivalService.existsById(festivalId) || - !timetableFestivalService.existsByUserIdAndFestivalId(userId, festivalId) - ) { + validateExistUser(userId); + validateExistFestival(festivalId); + validateExistTimetableFestival(userId, festivalId); + + timetableFestivalService.removeTimetableFestival(userId, festivalId); + } + + @Transactional(readOnly = true) + protected void validateExistUser(final long userId) { + if (!userService.existsById(userId)) { throw new NotFoundException(ErrorMessage.NOT_FOUND); } + } - timetableFestivalService.removeTimetableFestival(userId, festivalId); + @Transactional(readOnly = true) + protected void validateExistFestival(final long festivalId) { + if (!festivalService.existsById(festivalId)) { + throw new NotFoundException(ErrorMessage.NOT_FOUND); + } + } + + @Transactional(readOnly = true) + protected void validateExistTimetableFestival(final long userId, final long festivalId) { + if (!timetableFestivalService.existsByUserIdAndFestivalId(userId, festivalId)) { + throw new NotFoundException(ErrorMessage.NOT_FOUND); + } } }