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 4a3b54d commit 1b21014
Showing 1 changed file with 65 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,37 @@ public class UserFavoriteFacade {
public void addFestivalFavorite(long userId, long festivalId) {
User user = userService.findById(userId);
Festival festival = festivalService.findById(festivalId);
validateNotExistFestivalFavorite(userId, festivalId);

festivalFavoriteService.save(user, festival);
}

@Transactional
public void removeFestivalFavorite(long userId, long festivalId) {
User user = userService.findById(userId);
Festival festival = festivalService.findById(festivalId);
validateExistFestivalFavorite(userId, festivalId);

festivalFavoriteService.delete(user, festival);
}

@Transactional(readOnly = true)
public UserFavoriteArtistDTO getArtistList(long userId) {
if (!userService.existsById(userId)) {
protected void validateExistFestivalFavorite(final long userId, final long festivalId) {
if (!festivalFavoriteService.isFavorite(userId, festivalId)) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}
}

@Transactional(readOnly = true)
protected void validateNotExistFestivalFavorite(final long userId, final long festivalId) {
if (festivalFavoriteService.isFavorite(userId, festivalId)) {
throw new ConflictException(ErrorMessage.CONFLICT);
}
}

@Transactional(readOnly = true)
public UserFavoriteArtistDTO getArtistList(long userId) {
validateExistUser(userId);

List<ArtistFavorite> artists = artistFavoriteService.getArtistList(userId);
return UserFavoriteArtistDTO.from(artists);
Expand All @@ -60,45 +76,77 @@ public UserFavoriteArtistDTO getArtistList(long userId) {
@Transactional
public void addArtistFavorite(final long userId, final String artistId) {
User user = userService.findById(userId);

if (artistFavoriteService.isFavorite(userId, artistId)) {
throw new ConflictException(ErrorMessage.CONFLICT);
}
validateNotExistArtistFavorite(userId, artistId);

artistFavoriteService.addFavorite(user, artistId);
}

@Transactional
public void removeArtistFavorite(final long userId, final String artistId) {
if (
!userService.existsById(userId) || !artistFavoriteService.isFavorite(userId, artistId)
) {
validateExistUser(userId);
validateExistArtistFavorite(userId, artistId);

artistFavoriteService.removeFavorite(userId, artistId);
}

@Transactional(readOnly = true)
protected void validateExistArtistFavorite(final long userId, final String artistId) {
if (!artistFavoriteService.isFavorite(userId, artistId)) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}
}

artistFavoriteService.removeFavorite(userId, artistId);
@Transactional(readOnly = true)
protected void validateNotExistArtistFavorite(final long userId, final String artistId) {
if (artistFavoriteService.isFavorite(userId, artistId)) {
throw new ConflictException(ErrorMessage.CONFLICT);
}
}

@Transactional
public void addConcertFavorite(final long userId, final long concertId) {
User user = userService.findById(userId);
Concert concert = concertService.findById(concertId);

if (concertFavoriteService.isFavorite(userId, concertId)) {
throw new ConflictException(ErrorMessage.CONFLICT);
}
validateExistConcertFavorite(userId, concertId);

concertFavoriteService.addFavorite(user, concert);
}

@Transactional
public void removeConcertFavorite(final long userId, final long concertId) {
if (
!userService.existsById(userId) || !concertService.existsById(concertId) || !concertFavoriteService.isFavorite(userId, concertId)
) {
validateExistUser(userId);
validateExistConcert(concertId);
validateExistConcertFavorite(userId, concertId);

concertFavoriteService.removeFavorite(userId, concertId);
}

@Transactional(readOnly = true)
protected void validateExistConcertFavorite(final long userId, final long concertId) {
if (!concertFavoriteService.isFavorite(userId, concertId)) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}
}

concertFavoriteService.removeFavorite(userId, concertId);
@Transactional(readOnly = true)
protected void validateExistUser(final long userId) {
if (!userService.existsById(userId)) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}
}

@Transactional(readOnly = true)
protected void validateExistConcert(final long concertId) {
if (!concertService.existsById(concertId)) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}
}

@Transactional(readOnly = true)
protected void validateExistFestival(final long festivalId) {
if (!festivalService.existsById(festivalId)) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}
}
}

0 comments on commit 1b21014

Please sign in to comment.