From 6106851fe37662856aa52eba445b5dda44539399 Mon Sep 17 00:00:00 2001 From: BaeJunho Date: Thu, 10 Oct 2024 19:32:08 +0900 Subject: [PATCH 1/6] =?UTF-8?q?[refactor]=20video=20url=20=ED=98=95?= =?UTF-8?q?=EC=8B=9D=20=EB=B3=80=ED=99=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team7/inplace/video/presentation/dto/VideoResponse.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/team7/inplace/video/presentation/dto/VideoResponse.java b/src/main/java/team7/inplace/video/presentation/dto/VideoResponse.java index c7871a86..89003f8c 100644 --- a/src/main/java/team7/inplace/video/presentation/dto/VideoResponse.java +++ b/src/main/java/team7/inplace/video/presentation/dto/VideoResponse.java @@ -14,8 +14,8 @@ public static VideoResponse from(VideoInfo videoInfo) { return new VideoResponse( videoInfo.videoId(), videoInfo.videoAlias(), - videoInfo.videoUrl(), + "https://www.youtube.com/watch?v=" + videoInfo.videoUrl(), videoInfo.place() ); } -} +} \ No newline at end of file From 39423ed83c911333b1d150f7dec69255441eb628 Mon Sep 17 00:00:00 2001 From: BaeJunho Date: Thu, 10 Oct 2024 19:32:48 +0900 Subject: [PATCH 2/6] =?UTF-8?q?[refactor]=20place=20nullable=20=3D=20true?= =?UTF-8?q?=EB=A1=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 장소가 아직 입려되지 않은 비디오 엔티티가 있을 수 있기 때문에 --- src/main/java/team7/inplace/video/domain/Video.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/team7/inplace/video/domain/Video.java b/src/main/java/team7/inplace/video/domain/Video.java index 3b2eada2..1d653adb 100644 --- a/src/main/java/team7/inplace/video/domain/Video.java +++ b/src/main/java/team7/inplace/video/domain/Video.java @@ -19,24 +19,20 @@ @Entity @Getter @NoArgsConstructor(access = PROTECTED) -@RequiredArgsConstructor public class Video { @Id @GeneratedValue(strategy = IDENTITY) private Long id; @Column(name = "video_url", nullable = false, columnDefinition = "TEXT") - @NonNull private String videoUrl; @ManyToOne @JoinColumn(name = "influencer_id", nullable = false) - @NonNull private Influencer influencer; @ManyToOne - @JoinColumn(name = "place_id", nullable = false) - @NonNull + @JoinColumn(name = "place_id") private Place place; private Video(Influencer influencer, Place place, String videoUrl) { From 46ab086ebc7d5d98d2df77d9144d08ecb178278f Mon Sep 17 00:00:00 2001 From: BaeJunho Date: Thu, 10 Oct 2024 20:08:28 +0900 Subject: [PATCH 3/6] =?UTF-8?q?[chore]=20=EB=88=84=EB=9D=BD=EB=90=9C=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=82=BD?= =?UTF-8?q?=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team7/inplace/influencer/application/InfluencerService.java | 1 + 1 file changed, 1 insertion(+) 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)) { From 47f589d7d8dbb8f89c02dd3c3f0611edcc941cbb Mon Sep 17 00:00:00 2001 From: BaeJunho Date: Fri, 11 Oct 2024 19:15:35 +0900 Subject: [PATCH 4/6] =?UTF-8?q?[refactor]=20error=20code=20=ED=98=95?= =?UTF-8?q?=EC=8B=9D=20=ED=86=B5=EC=9D=BC=20=EB=B0=8F=20Place=20error=20co?= =?UTF-8?q?de=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/code/PlaceErrorCode.java | 31 +++++++++++++++++++ .../global/exception/code/VideoErrorCode.java | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/main/java/team7/inplace/global/exception/code/PlaceErrorCode.java 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; From 761bd2cd2d539e87db55177de25c18484926497b Mon Sep 17 00:00:00 2001 From: BaeJunho Date: Fri, 11 Oct 2024 19:16:19 +0900 Subject: [PATCH 5/6] =?UTF-8?q?[refactor]=20=EA=B2=80=EC=83=89=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=EC=9D=B4=20=EB=8D=94=20=EB=B3=B5=EC=9E=A1=ED=95=B4?= =?UTF-8?q?=EC=A0=B8=EC=84=9C=20=ED=95=B4=EB=8B=B9=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EB=B3=80=ED=99=98=ED=95=B4=EC=A3=BC=EB=8A=94=20=ED=8E=99?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../place/application/command/PlacesCommand.java | 12 ++++++++++++ .../video/presentation/dto/VideoSearchParams.java | 4 ++++ 2 files changed, 16 insertions(+) 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/presentation/dto/VideoSearchParams.java b/src/main/java/team7/inplace/video/presentation/dto/VideoSearchParams.java index e56c21cc..6efcb0d7 100644 --- a/src/main/java/team7/inplace/video/presentation/dto/VideoSearchParams.java +++ b/src/main/java/team7/inplace/video/presentation/dto/VideoSearchParams.java @@ -1,6 +1,10 @@ package team7.inplace.video.presentation.dto; public record VideoSearchParams( + String topLeftLongitude, + String topLeftLatitude, + String bottomRightLongitude, + String bottomRightLatitude, String longitude, String latitude ) { From fb85dcf8523461016660f5990187f1aed68bfcb6 Mon Sep 17 00:00:00 2001 From: BaeJunho Date: Fri, 11 Oct 2024 19:17:06 +0900 Subject: [PATCH 6/6] =?UTF-8?q?[refactor]=20Facade=20=ED=8C=A8=ED=84=B4=20?= =?UTF-8?q?=EB=8F=84=EC=9E=85=20=EB=B0=8F=20Place=20Nullable=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC=20=EB=8F=84=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../video/application/VideoFacade.java | 22 +++++++++++ .../video/application/VideoService.java | 38 +++++++++---------- .../video/presentation/VideoController.java | 4 +- 3 files changed, 42 insertions(+), 22 deletions(-) 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