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 [#107] 타임테이블 페스티벌 삭제 API 구현 #108

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sopt.confeti.api.user.controller;

import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import org.sopt.confeti.api.user.dto.response.UserTimetableDetailResponse;
import org.sopt.confeti.api.user.facade.UserTimetableFacade;
Expand All @@ -9,12 +10,16 @@
import org.sopt.confeti.global.util.ApiResponseUtil;
import org.sopt.confeti.global.util.S3FileHandler;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Validated
@RequiredArgsConstructor
@RequestMapping("/user/timetables/festivals")
public class UserTimetableController {
Expand All @@ -26,4 +31,13 @@ public ResponseEntity<BaseResponse<?>> getTimetablesListAndDate(@RequestHeader("
UserTimetableDTO userTimetableDTO = userTimetableFacade.getTimetablesListAndDate(userId);
return ApiResponseUtil.success(SuccessMessage.SUCCESS, UserTimetableDetailResponse.of(userTimetableDTO, s3FileHandler));
}

@DeleteMapping("/{festivalId}")
public ResponseEntity<BaseResponse<?>> removeTimetableFestival(
@RequestHeader("Authorization") long userId,
@PathVariable(name = "festivalId") @Min(value = 0, message = "요청 형식이 올바르지 않습니다.") long festivalId
) {
userTimetableFacade.removeTimetableFestival(userId, festivalId);
return ApiResponseUtil.success(SuccessMessage.SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public void removeFestivalFavorite(long userId, long festivalId) {

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

List<ArtistFavorite> artists = artistFavoriteService.getArtistList(userId);
return UserFavoriteArtistDTO.from(artists);
}
Expand All @@ -67,9 +70,9 @@ public void addArtistFavorite(final long userId, final String artistId) {

@Transactional
public void removeArtistFavorite(final long userId, final String artistId) {
userService.existsById(userId);

if (!artistFavoriteService.isFavorite(userId, artistId)) {
if (
!userService.existsById(userId) || !artistFavoriteService.isFavorite(userId, artistId)
) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}

Expand All @@ -90,10 +93,9 @@ public void addConcertFavorite(final long userId, final long concertId) {

@Transactional
public void removeConcertFavorite(final long userId, final long concertId) {
userService.existsById(userId);
concertService.existsById(concertId);

if (!concertFavoriteService.isFavorite(userId, concertId)) {
if (
!userService.existsById(userId) || !concertService.existsById(concertId) || !concertFavoriteService.isFavorite(userId, concertId)
) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package org.sopt.confeti.api.user.facade;

import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.sopt.confeti.annotation.Facade;
import org.sopt.confeti.api.user.facade.dto.response.UserTimetableDTO;
import org.sopt.confeti.domain.festival.application.FestivalService;
import org.sopt.confeti.domain.timetablefestival.TimetableFestival;
import org.sopt.confeti.domain.timetablefestival.application.TimetableFestivalService;
import org.sopt.confeti.domain.user.application.UserService;
import org.sopt.confeti.global.util.S3FileHandler;
import org.sopt.confeti.global.exception.NotFoundException;
import org.sopt.confeti.global.message.ErrorMessage;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

@Facade
Expand All @@ -20,12 +19,29 @@ public class UserTimetableFacade {

private final UserService userService;
private final TimetableFestivalService timetableFestivalService;
private final FestivalService festivalService;

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

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)
) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}

timetableFestivalService.removeTimetableFestival(userId, festivalId);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ public Concert getConcertDetailByConcertId(final long concertId) {
}

@Transactional(readOnly = true)
public void existsById(long concertId) {
if (!concertRepository.existsById(concertId)) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}
public boolean existsById(long concertId) {
return concertRepository.existsById(concertId);
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ public void create(final CreateFestivalDTO createFestivalDTO) {
Festival.create(createFestivalDTO)
);
}

public boolean existsById(final long festivalId) {
return festivalRepository.existsById(festivalId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@
import org.springframework.stereotype.Service;

import java.util.List;
import org.springframework.transaction.annotation.Transactional;

@Service
@AllArgsConstructor
public class TimetableFestivalService {
private final TimetableFestivalRepository timetableFestivalRepository;

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

@Transactional(readOnly = true)
public boolean existsByUserIdAndFestivalId(final long userId, final long festivalId) {
return timetableFestivalRepository.existsByUserIdAndFestivalId(userId, festivalId);
}

@Transactional
public void removeTimetableFestival(final long userId, final long festivalId) {
timetableFestivalRepository.deleteByUserIdAndFestivalId(userId, festivalId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@

public interface TimetableFestivalRepository extends JpaRepository<TimetableFestival, Long> {
List<TimetableFestival> findByUserId(Long userId);

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

void deleteByUserIdAndFestivalId(final long userId, final long festivalId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ public User findById(Long userId) {
}

@Transactional(readOnly = true)
public void existsById(Long userId) {
final boolean isExistUser = userRepository.existsById(userId);
if(!isExistUser) {
throw new NotFoundException(ErrorMessage.NOT_FOUND);
}
public boolean existsById(Long userId) {
return userRepository.existsById(userId);
}
}