From ee472879de9b9679f3ccfe8bf3469d8813da8edb Mon Sep 17 00:00:00 2001 From: BaeJunho Date: Tue, 8 Oct 2024 22:06:56 +0900 Subject: [PATCH 01/10] =?UTF-8?q?[refactor]=20Custom=20Error=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 별도의 Enum 클래스 만들어 등록 --- .../code/AuthorizationErrorCode.java | 5 +--- .../global/exception/code/VideoErrorCode.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 src/main/java/team7/inplace/global/exception/code/VideoErrorCode.java diff --git a/src/main/java/team7/inplace/global/exception/code/AuthorizationErrorCode.java b/src/main/java/team7/inplace/global/exception/code/AuthorizationErrorCode.java index 7c7c998f..640aaccf 100644 --- a/src/main/java/team7/inplace/global/exception/code/AuthorizationErrorCode.java +++ b/src/main/java/team7/inplace/global/exception/code/AuthorizationErrorCode.java @@ -9,10 +9,7 @@ public enum AuthorizationErrorCode implements ErrorCode { TOKEN_IS_EMPTY(HttpStatus.BAD_REQUEST, "A001", "Token is Empty"), INVALID_TOKEN(HttpStatus.BAD_REQUEST, "A002", "Invalid Token"), - TOKEN_IS_EXPIRED(HttpStatus.BAD_REQUEST, "A003", "Token is Expired"), - - NO_SUCH_VIDEO(HttpStatus.NOT_FOUND, "V001", "Can't find such video info"); - + TOKEN_IS_EXPIRED(HttpStatus.BAD_REQUEST, "A003", "Token is Expired"); private final HttpStatus httpStatus; private final String errorCode; diff --git a/src/main/java/team7/inplace/global/exception/code/VideoErrorCode.java b/src/main/java/team7/inplace/global/exception/code/VideoErrorCode.java new file mode 100644 index 00000000..483b97d0 --- /dev/null +++ b/src/main/java/team7/inplace/global/exception/code/VideoErrorCode.java @@ -0,0 +1,30 @@ +package team7.inplace.global.exception.code; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@AllArgsConstructor +@Getter +public enum VideoErrorCode implements ErrorCode{ + NO_SUCH_VIDEO(HttpStatus.NOT_FOUND, "V001", "Can't find such video 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; + } +} From 6eef10099c782fd01ded54885039fb68d9d87f1d Mon Sep 17 00:00:00 2001 From: BaeJunho Date: Tue, 8 Oct 2024 22:09:54 +0900 Subject: [PATCH 02/10] =?UTF-8?q?[feat]=20=EC=9D=B8=ED=94=8C=EB=A3=A8?= =?UTF-8?q?=EC=96=B8=EC=84=9C=EC=99=80=20=EC=9C=A0=EC=A0=80=EC=9D=98=20?= =?UTF-8?q?=EA=B4=80=EA=B3=84=EB=A5=BC=20=EC=A0=80=EC=9E=A5=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=A1=B0=EC=9D=B8=20=ED=85=8C=EC=9D=B4=EB=B8=94=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/team7/inplace/like/domain/Like.java | 26 +++++++++++++++++++ .../like/persistent/LikeRepository.java | 12 +++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/team7/inplace/like/domain/Like.java create mode 100644 src/main/java/team7/inplace/like/persistent/LikeRepository.java diff --git a/src/main/java/team7/inplace/like/domain/Like.java b/src/main/java/team7/inplace/like/domain/Like.java new file mode 100644 index 00000000..4d634bb2 --- /dev/null +++ b/src/main/java/team7/inplace/like/domain/Like.java @@ -0,0 +1,26 @@ +package team7.inplace.like.domain; + +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import team7.inplace.influencer.domain.Influencer; +import team7.inplace.user.domain.User; + +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PRIVATE; + +@Getter +@NoArgsConstructor(access = PRIVATE) +@Entity +public class Like { + @Id + @GeneratedValue(strategy = IDENTITY) + private Long id; + @ManyToOne + @JoinColumn(name = "user_id") + private User user; + @ManyToOne + @JoinColumn(name = "influencer_id") + private Influencer influencer; +} diff --git a/src/main/java/team7/inplace/like/persistent/LikeRepository.java b/src/main/java/team7/inplace/like/persistent/LikeRepository.java new file mode 100644 index 00000000..d4780949 --- /dev/null +++ b/src/main/java/team7/inplace/like/persistent/LikeRepository.java @@ -0,0 +1,12 @@ +package team7.inplace.like.persistent; + +import org.springframework.data.jpa.repository.JpaRepository; +import team7.inplace.influencer.domain.Influencer; +import team7.inplace.like.domain.Like; +import team7.inplace.user.domain.User; + +import java.util.List; + +public interface LikeRepository extends JpaRepository { + List findByUser(User user); +} From 821775be050dc848070c25d08fec376fbb3a32df Mon Sep 17 00:00:00 2001 From: BaeJunho Date: Tue, 8 Oct 2024 22:10:49 +0900 Subject: [PATCH 03/10] =?UTF-8?q?[feat]=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=ED=95=9C=20=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20?= =?UTF-8?q?=EC=9D=B4=EC=9A=A9=ED=95=98=EC=97=AC=20=EC=A2=8B=EC=95=84?= =?UTF-8?q?=EC=9A=94=20=ED=95=9C=20=EC=9D=B8=ED=94=8C=EB=A3=A8=EC=96=B8?= =?UTF-8?q?=EC=84=9C=EC=9D=98=20=EB=8F=99=EC=98=81=EC=83=81=EC=9D=84=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inplace/user/application/UserService.java | 19 +++++++++++++---- .../video/application/VideoService.java | 21 ++++++++++++++++++- .../video/presentation/VideoController.java | 10 +++++++++ .../presentation/VideoControllerApiSpec.java | 9 ++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/main/java/team7/inplace/user/application/UserService.java b/src/main/java/team7/inplace/user/application/UserService.java index 8edf6daf..3c094fc6 100644 --- a/src/main/java/team7/inplace/user/application/UserService.java +++ b/src/main/java/team7/inplace/user/application/UserService.java @@ -1,19 +1,24 @@ package team7.inplace.user.application; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import team7.inplace.influencer.application.dto.InfluencerInfo; +import team7.inplace.influencer.domain.Influencer; +import team7.inplace.like.domain.Like; +import team7.inplace.like.persistent.LikeRepository; import team7.inplace.user.application.dto.UserCommand; import team7.inplace.user.domain.User; import team7.inplace.user.persistence.UserRepository; +import java.util.List; + @Service +@RequiredArgsConstructor public class UserService { private final UserRepository userRepository; - - public UserService(UserRepository userRepository) { - this.userRepository = userRepository; - } + private final LikeRepository likeRepository; @Transactional public void registerUser(UserCommand.Create userCreate) { @@ -30,4 +35,10 @@ public boolean isExistUser(String username) { public UserCommand.Info getUserByUsername(String username) { return UserCommand.Info.of(userRepository.findByUsername(username).orElseThrow()); } + + @Transactional(readOnly = true) + public List getInfluencerIdsByUsername(String username) { + List likes = likeRepository.findByUser(userRepository.findByUsername(username).orElseThrow()); + return likes.stream().map(Like::getInfluencer).map(Influencer::getId).toList(); + } } diff --git a/src/main/java/team7/inplace/video/application/VideoService.java b/src/main/java/team7/inplace/video/application/VideoService.java index 0d78596d..ce8371a1 100644 --- a/src/main/java/team7/inplace/video/application/VideoService.java +++ b/src/main/java/team7/inplace/video/application/VideoService.java @@ -5,11 +5,15 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; import team7.inplace.global.exception.InplaceException; import team7.inplace.global.exception.code.AuthorizationErrorCode; +import team7.inplace.global.exception.code.VideoErrorCode; 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.dto.VideoInfo; import team7.inplace.video.domain.Video; import team7.inplace.video.persistence.VideoRepository; @@ -24,6 +28,7 @@ public class VideoService { private final VideoRepository videoRepository; private final PlaceRepository placeRepository; + private final UserService userService; public Page getVideosBySurround(VideoSearchParams videoSearchParams, Pageable pageable) { Page places = placeRepository.getPlacesByDistance( @@ -37,7 +42,7 @@ public Page getVideosBySurround(VideoSearchParams videoSearchParams, if (videos.size() == places.getSize()) break; videos.add(videoRepository.findTopByPlaceOrderByIdDesc(place) - .orElseThrow(()-> InplaceException.of(AuthorizationErrorCode.NO_SUCH_VIDEO))); + .orElseThrow(()-> InplaceException.of(VideoErrorCode.NO_SUCH_VIDEO))); } return new PageImpl<>(videos).map(this::videoToInfo); } @@ -50,6 +55,20 @@ public Page getAllVideosDesc(Pageable pageable) { return videos.map(this::videoToInfo); } + public Page getVideosByMyInfluencer(Pageable pageable){ + // User 정보를 쿠키에서 추출 + String username = AuthorizationUtil.getUsername(); + // 토큰 정보에 대한 검증 + if(!StringUtils.hasText(username) || username == null) { + throw InplaceException.of(AuthorizationErrorCode.TOKEN_IS_EMPTY); + } + // 유저 정보를 이용하여 유저가 좋아요를 누른 인플루언서 id 리스트를 조회 + List influencerIds = userService.getInfluencerIdsByUsername(username); + // 인플루언서 id 리스트를 이용하여 해당 인플루언서의 비디오들을 조회 + Page