Skip to content

Commit

Permalink
refactor [#109] 엔티티 존재 여부 메소드 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1hyun committed Jan 18, 2025
1 parent 200401d commit 51f0d4a
Showing 1 changed file with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,40 @@ public class UserTimetableFacade {

@Transactional(readOnly = true)
public UserTimetableDTO getTimetablesListAndDate(long userId) {
if (!userService.existsById(userId)) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}
validateExistUser(userId);

List<TimetableFestival> festivalList = timetableFestivalService.getFetivalList(userId);
return UserTimetableDTO.from(festivalList);
}

@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);
}
}
}

0 comments on commit 51f0d4a

Please sign in to comment.