-
Notifications
You must be signed in to change notification settings - Fork 2
Feat: 프로필 화면 상단정보 / 피드 이미지 미리보기 api #177
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
Changes from all commits
d8981f0
4fb7818
6df7516
f6cf450
f8adc41
229cd10
787f642
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -251,6 +251,19 @@ public CardFeedResponse getCardFeed(Long cardId, Long userId) { | |
| ); | ||
| } | ||
|
|
||
| @Override | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| public CardResponse.ProfileCardListDTO getProfileCardList(Long userId, int size, Long cursor) { | ||
| Slice<Card> cardSlice; | ||
| Pageable pageable = PageRequest.of(0, size); | ||
|
|
||
| if (cursor == null) { | ||
| cardSlice = cardRepository.findByUserIdAndIsSharedTrueAndIsDeletedFalseOrderByIdDesc(userId, pageable); | ||
| } else { | ||
| cardSlice = cardRepository.findByUserIdAndIsSharedTrueAndIsDeletedFalseAndIdLessThanOrderByIdDesc(userId, cursor, pageable); | ||
| } | ||
| return CardConverter.toProfileCardList(userId, cardSlice); | ||
| } | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public CardDeleteResponse deleteCard(Long cardId, Long userId) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,4 +23,7 @@ public interface UserFollowRepository extends JpaRepository<UserFollow,Long> { | |||||||||
| List<Long> findFollowingUserIds(@Param("userId") Long userId); | ||||||||||
|
|
||||||||||
| UserFollow findByUserAndTargetUser(User user, User target); | ||||||||||
|
|
||||||||||
| Long countUserFollowByTargetUser(User targetUser); | ||||||||||
| Long countUserFollowByUser(User user); | ||||||||||
|
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메서드 이름이 약간 혼동을 줄 수 있습니다. Spring Data JPA의 명명 규칙에 따라 더 명확하고 간결한 이름으로 변경하는 것을 제안합니다. 예를 들어,
Suggested change
|
||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package EatPic.spring.domain.user.service; | ||
|
|
||
| import EatPic.spring.domain.card.repository.CardRepository; | ||
| import EatPic.spring.domain.user.converter.UserConverter; | ||
| import EatPic.spring.domain.user.dto.*; | ||
| import EatPic.spring.domain.user.dto.request.LoginRequestDTO; | ||
|
|
@@ -44,6 +45,7 @@ public class UserServiceImpl implements UserService{ | |
| private final UserFollowRepository userFollowRepository; | ||
| private final UserBlockRepository userBlockRepository; | ||
| private final UserBadgeService userBadgeService; | ||
| private final CardRepository cardRepository; | ||
| private final PasswordEncoder passwordEncoder; | ||
| private final JwtTokenProvider jwtTokenProvider; | ||
|
|
||
|
|
@@ -189,6 +191,19 @@ public User getLoginUser(HttpServletRequest request) { | |
| .orElseThrow(() -> new ExceptionHandler(ErrorStatus.MEMBER_NOT_FOUND)); | ||
| } | ||
|
|
||
| @Override | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| public UserResponseDTO.DetailProfileDto getProfile(HttpServletRequest request, Long userId) { | ||
| User me = getLoginUser(request); | ||
|
|
||
| User user = userRepository.findById(userId).orElseThrow(()-> new ExceptionHandler(USER_NOT_FOUND)); | ||
| Boolean isFollowing = userFollowRepository.existsByUserAndTargetUser(me, user); | ||
| Long totalCard = cardRepository.countByUserIdAndIsDeletedFalseAndIsSharedTrue(userId); | ||
| Long totalFollower = userFollowRepository.countUserFollowByTargetUser(user); | ||
| Long totalFollowing = userFollowRepository.countUserFollowByUser(user); | ||
|
|
||
| return UserConverter.toDetailProfileDto(user, isFollowing,totalCard,totalFollower,totalFollowing); | ||
| } | ||
|
|
||
| @Override | ||
| public UserResponseDTO.UserActionResponseDto unfollowUser(HttpServletRequest request, Long targetUserId) { | ||
| User user = getLoginUser(request); | ||
|
|
@@ -207,8 +222,13 @@ public UserResponseDTO.UserActionResponseDto unfollowUser(HttpServletRequest req | |
| @Override | ||
| public UserResponseDTO.UserActionResponseDto followUser(HttpServletRequest request, Long targetUserId) { | ||
| User user = getLoginUser(request); | ||
| if(user.getId().equals(targetUserId)) { | ||
| throw new ExceptionHandler(FOLLOW_FORBBIDEN); | ||
| } | ||
|
|
||
| User target = userRepository.findUserById(targetUserId); | ||
|
|
||
|
|
||
| UserFollow prev = userFollowRepository.findByUserAndTargetUser(user,target); | ||
| UserFollow follow = UserFollow.builder().user(user).targetUser(target).build(); | ||
| if(prev!=null && prev.getTargetUser().getId().equals(targetUserId)) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cardList.getContent()가 중복으로 호출되고 있습니다. 169번째 줄에서 이미list변수에 저장했으므로,list.stream()을 사용하여 중복 호출을 피하는 것이 좋습니다. 이렇게 하면 코드가 더 효율적이고 깔끔해집니다.