Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat [#109] 지난 공연 제외하는 기능 추가 #110

Merged
merged 8 commits into from
Jan 20, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class PerformanceController {
@GetMapping("/concerts/{concertId}")
public ResponseEntity<BaseResponse<?>> getConcertInfo(
@RequestHeader(name = "Authorization", required = false) Long userId,
@PathVariable("concertId") @Min(value = 0, message = "요청 형식이 올바르지 않습니다.") Long concertId
@PathVariable("concertId") @Min(value = 0, message = "요청 형식이 올바르지 않습니다.") long concertId
) {
ConcertDetailDTO concertDetailDTO = performanceFacade.getConcertDetailInfo(concertId);
return ApiResponseUtil.success(SuccessMessage.SUCCESS, ConcertDetailResponse.of(concertDetailDTO, s3FileHandler));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sopt.confeti.api.performance.facade;

import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import org.sopt.confeti.annotation.Facade;
import org.sopt.confeti.api.performance.facade.dto.request.CreateFestivalDTO;
Expand All @@ -10,6 +11,8 @@
import org.sopt.confeti.domain.festival.Festival;
import org.sopt.confeti.domain.festival.application.FestivalService;
import org.sopt.confeti.domain.festivalfavorite.application.FestivalFavoriteService;
import org.sopt.confeti.global.exception.NotFoundException;
import org.sopt.confeti.global.message.ErrorMessage;
import org.sopt.confeti.global.util.S3FileHandler;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -25,23 +28,46 @@ public class PerformanceFacade {
@Transactional(readOnly = true)
public ConcertDetailDTO getConcertDetailInfo(final long concertId) {
Concert concert = concertService.getConcertDetailByConcertId(concertId);
validateConcertNotPassed(concert);

return ConcertDetailDTO.from(concert);
}

@Transactional(readOnly = true)
protected void validateConcertNotPassed(final Concert concert) {
if (LocalDate.now().isAfter(concert.getConcertEndAt())) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}
}

@Transactional
public void createFestival(final CreateFestivalDTO createFestivalDTO) {
festivalService.create(createFestivalDTO);
}

@Transactional(readOnly = true)
public FestivalDetailDTO getFestivalDetailInfo(final Long userId, final long festivalId) {
boolean isFavorite = false;

if (userId != null) {
isFavorite = festivalFavoriteService.isFavorite(userId, festivalId);
}
boolean isFavorite = getIsFavorite(userId, festivalId);

Festival festival = festivalService.getFestivalDetailByFestivalId(festivalId);
validateFestivalNotPassed(festival);

return FestivalDetailDTO.of(festival, isFavorite, s3FileHandler);
}

@Transactional(readOnly = true)
protected boolean getIsFavorite(final Long userid, final long festivalId) {
if (userid != null) {
return festivalFavoriteService.isFavorite(userid, festivalId);
}

return false;
}

@Transactional(readOnly = true)
protected void validateFestivalNotPassed(final Festival festival) {
if (LocalDate.now().isAfter(festival.getFestivalEndAt())) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sopt.confeti.api.user.facade;

import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import org.sopt.confeti.annotation.Facade;
import org.sopt.confeti.api.user.facade.dto.response.UserFavoriteArtistDTO;
Expand Down Expand Up @@ -37,21 +38,45 @@ 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) {
// TODO: 페스티벌 좋아요 삭제 시 엔티티 값을 사용하지 않으므로 아이디 값으로 삭제하도록 리펙토링 예정
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 validateExistFestival(final long festivalId) {
if (!festivalService.existsById(festivalId)) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}
}

@Transactional(readOnly = true)
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 +85,70 @@ 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);
}
}
}
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);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TimetableFestivalService {

@Transactional(readOnly = true)
public List<TimetableFestival> getFetivalList(long userId){
return timetableFestivalRepository.findByUserId(userId);
return timetableFestivalRepository.findByUserIdWhereEndAtLENow(userId);
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface TimetableFestivalRepository extends JpaRepository<TimetableFestival, Long> {
List<TimetableFestival> findByUserId(Long userId);
@Query("select tf from TimetableFestival tf join fetch tf.festival f where tf.user.id = :userId and f.festivalEndAt <= CURRENT_DATE")
List<TimetableFestival> findByUserIdWhereEndAtLENow(@Param("userId") Long userId);

boolean existsByUserIdAndFestivalId(final long userId, final long festivalId);

Expand Down