Skip to content

Commit

Permalink
[refactor] username 사용에서 userId 사용 방식으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
BaeJunho committed Oct 9, 2024
1 parent 53237e9 commit e318c18
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/main/java/team7/inplace/user/application/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ public UserCommand.Info getUserByUsername(String username) {
}

@Transactional(readOnly = true)
public List<Long> getInfluencerIdsByUsername(String username) {
List<UserFavoriteInfluencer> likes = userFavoriteInfluencerRepository
.findByUser(userRepository.findByUsername(username).orElseThrow());
public List<Long> getInfluencerIdsByUsername(Long userId) {
List<UserFavoriteInfluencer> likes = userFavoriteInfluencerRepository.findByUserId(userId);
return likes.stream().map(UserFavoriteInfluencer::getInfluencer).map(Influencer::getId).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
import java.util.List;

public interface UserFavoriteInfluencerRepository extends JpaRepository<UserFavoriteInfluencer, Long> {
List<UserFavoriteInfluencer> findByUser(User user);

UserFavoriteInfluencer save(UserFavoriteInfluencer favorite);
List<UserFavoriteInfluencer> findByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import team7.inplace.global.exception.InplaceException;
import team7.inplace.global.exception.code.AuthorizationErrorCode;
Expand Down Expand Up @@ -57,13 +58,13 @@ public Page<VideoInfo> getAllVideosDesc(Pageable pageable) {

public Page<VideoInfo> getVideosByMyInfluencer(Pageable pageable){
// User 정보를 쿠키에서 추출
String username = AuthorizationUtil.getUsername();
Long userId = AuthorizationUtil.getUserId();
// 토큰 정보에 대한 검증
if(!StringUtils.hasText(username)) {
if(ObjectUtils.isEmpty(userId)) {
throw InplaceException.of(AuthorizationErrorCode.TOKEN_IS_EMPTY);
}
// 유저 정보를 이용하여 유저가 좋아요를 누른 인플루언서 id 리스트를 조회
List<Long> influencerIds = userService.getInfluencerIdsByUsername(username);
List<Long> influencerIds = userService.getInfluencerIdsByUsername(userId);
// 인플루언서 id 리스트를 이용하여 해당 인플루언서의 비디오들을 조회
Page<Video> videos = videoRepository.findVideosByInfluencerIdIn(influencerIds, pageable);
return videos.map(this::videoToInfo);
Expand Down

0 comments on commit e318c18

Please sign in to comment.