diff --git a/src/main/java/team7/inplace/global/exception/code/PlaceErrorCode.java b/src/main/java/team7/inplace/global/exception/code/PlaceErrorCode.java new file mode 100644 index 00000000..e9bbe2de --- /dev/null +++ b/src/main/java/team7/inplace/global/exception/code/PlaceErrorCode.java @@ -0,0 +1,31 @@ +package team7.inplace.global.exception.code; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + + +@AllArgsConstructor +@Getter +public enum PlaceErrorCode implements ErrorCode{ + NOT_FOUND(HttpStatus.NOT_FOUND, "P001", "Can't find such place info"); + + private final HttpStatus httpStatus; + private final String errorCode; + private final String message; + + @Override + public HttpStatus httpStatus() { + return httpStatus; + } + + @Override + public String code() { + return errorCode; + } + + @Override + public String message() { + return message; + } +} diff --git a/src/main/java/team7/inplace/global/exception/code/VideoErrorCode.java b/src/main/java/team7/inplace/global/exception/code/VideoErrorCode.java index 483b97d0..a1c6ea37 100644 --- a/src/main/java/team7/inplace/global/exception/code/VideoErrorCode.java +++ b/src/main/java/team7/inplace/global/exception/code/VideoErrorCode.java @@ -7,7 +7,7 @@ @AllArgsConstructor @Getter public enum VideoErrorCode implements ErrorCode{ - NO_SUCH_VIDEO(HttpStatus.NOT_FOUND, "V001", "Can't find such video info"); + NOT_FOUND(HttpStatus.NOT_FOUND, "V001", "Can't find such video info"); private final HttpStatus httpStatus; private final String errorCode; diff --git a/src/main/java/team7/inplace/influencer/application/InfluencerService.java b/src/main/java/team7/inplace/influencer/application/InfluencerService.java index 250d62d5..d8628289 100644 --- a/src/main/java/team7/inplace/influencer/application/InfluencerService.java +++ b/src/main/java/team7/inplace/influencer/application/InfluencerService.java @@ -55,6 +55,7 @@ public void deleteInfluencer(Long id) { influencerRepository.delete(influencer); } + @Transactional public void likeToInfluencer(InfluencerRequestParam param) { String username = AuthorizationUtil.getUsername(); if (StringUtils.hasText(username)) { diff --git a/src/main/java/team7/inplace/place/application/command/PlacesCommand.java b/src/main/java/team7/inplace/place/application/command/PlacesCommand.java index 376f2351..27fc1939 100644 --- a/src/main/java/team7/inplace/place/application/command/PlacesCommand.java +++ b/src/main/java/team7/inplace/place/application/command/PlacesCommand.java @@ -7,6 +7,7 @@ import java.util.Objects; import org.springframework.data.domain.Pageable; import team7.inplace.place.domain.Place; +import team7.inplace.video.presentation.dto.VideoSearchParams; public class PlacesCommand { @@ -19,6 +20,17 @@ public record PlacesCoordinateCommand( String latitude, Pageable pageable ) { + public static PlacesCoordinateCommand from(VideoSearchParams videoSearchParams, Pageable pageable) { + return new PlacesCoordinateCommand( + videoSearchParams.topLeftLongitude(), + videoSearchParams.topLeftLatitude(), + videoSearchParams.bottomRightLatitude(), + videoSearchParams.bottomRightLatitude(), + videoSearchParams.longitude(), + videoSearchParams.latitude(), + pageable + ); + } } public record PlacesFilterParamsCommand( diff --git a/src/main/java/team7/inplace/video/application/VideoFacade.java b/src/main/java/team7/inplace/video/application/VideoFacade.java index 2e4712f7..a4bd2a14 100644 --- a/src/main/java/team7/inplace/video/application/VideoFacade.java +++ b/src/main/java/team7/inplace/video/application/VideoFacade.java @@ -2,17 +2,26 @@ import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.ObjectUtils; import team7.inplace.global.annotation.Facade; +import team7.inplace.global.exception.InplaceException; +import team7.inplace.global.exception.code.AuthorizationErrorCode; import team7.inplace.place.application.PlaceService; import team7.inplace.place.application.command.PlacesCommand; +import team7.inplace.security.util.AuthorizationUtil; +import team7.inplace.user.application.UserService; import team7.inplace.video.application.command.VideoCommand; +import team7.inplace.video.application.dto.VideoInfo; @Facade @RequiredArgsConstructor public class VideoFacade { private final VideoService videoService; private final PlaceService placeService; + private final UserService userService; @Transactional public void createVideos(List videoCommands, List placeCommands) { @@ -20,4 +29,17 @@ public void createVideos(List videoCommands, List getVideosByMyInfluencer(Pageable pageable){ + // User 정보를 쿠키에서 추출 + Long userId = AuthorizationUtil.getUserId(); + // 토큰 정보에 대한 검증 + if (ObjectUtils.isEmpty(userId)) { + throw InplaceException.of(AuthorizationErrorCode.TOKEN_IS_EMPTY); + } + // 유저 정보를 이용하여 유저가 좋아요를 누른 인플루언서 id 리스트를 조회 + List influencerIds = userService.getInfluencerIdsByUsername(userId); + // 인플루언서 id를 사용하여 영상을 조회 + return videoService.getVideosByMyInfluencer(influencerIds, pageable); + } } diff --git a/src/main/java/team7/inplace/video/application/VideoService.java b/src/main/java/team7/inplace/video/application/VideoService.java index 9129fb3a..868d7864 100644 --- a/src/main/java/team7/inplace/video/application/VideoService.java +++ b/src/main/java/team7/inplace/video/application/VideoService.java @@ -7,15 +7,13 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import org.springframework.util.ObjectUtils; import team7.inplace.global.exception.InplaceException; -import team7.inplace.global.exception.code.AuthorizationErrorCode; +import team7.inplace.global.exception.code.PlaceErrorCode; +import team7.inplace.global.exception.code.VideoErrorCode; import team7.inplace.influencer.persistence.InfluencerRepository; import team7.inplace.place.application.dto.PlaceForVideo; import team7.inplace.place.domain.Place; import team7.inplace.place.persistence.PlaceRepository; -import team7.inplace.security.util.AuthorizationUtil; -import team7.inplace.user.application.UserService; import team7.inplace.video.application.command.VideoCommand.Create; import team7.inplace.video.application.dto.VideoInfo; import team7.inplace.video.domain.Video; @@ -28,22 +26,29 @@ public class VideoService { private final VideoRepository videoRepository; private final PlaceRepository placeRepository; private final InfluencerRepository influencerRepository; - private final UserService userService; public Page getVideosBySurround(VideoSearchParams videoSearchParams, Pageable pageable) { - Page places = placeRepository.getPlacesByDistance( + // Place 엔티티 조회 + Page places = placeRepository.getPlacesByDistanceAndFilters( + videoSearchParams.topLeftLongitude(), + videoSearchParams.topLeftLatitude(), + videoSearchParams.bottomRightLongitude(), + videoSearchParams.bottomRightLatitude(), videoSearchParams.longitude(), videoSearchParams.latitude(), + new ArrayList<>(), + new ArrayList<>(), pageable ); - + // 조회된 엔티티가 비어있는지 아닌지 확인 + if(places.isEmpty()){ + throw InplaceException.of(PlaceErrorCode.NOT_FOUND); + } + // 장소를 기준으로 비디오 엔티티 조회 ( 장소 별로 가장 최근 비디오 하나 씩 ) List