-
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 1 commit
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -157,4 +157,22 @@ public static CardDeleteResponse toCardDeleteResponse(Card card) { | |||||||||||||
| .successMessage("카드 삭제 성공") | ||||||||||||||
| .build(); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| public static CardResponse.ProfileCardDTO toProfileCardDto(Card card){ | ||||||||||||||
| return CardResponse.ProfileCardDTO.builder() | ||||||||||||||
| .cardId(card.getId()) | ||||||||||||||
| .cardImageUrl(card.getCardImageUrl()) | ||||||||||||||
| .build(); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| public static CardResponse.profileCardListDTO toProfileCardList(Long userId, Slice<Card> cardList) { | ||||||||||||||
| return CardResponse.profileCardListDTO.builder() | ||||||||||||||
|
||||||||||||||
| public static CardResponse.profileCardListDTO toProfileCardList(Long userId, Slice<Card> cardList) { | |
| return CardResponse.profileCardListDTO.builder() | |
| public static CardResponse.ProfileCardListDTO toProfileCardList(Long userId, Slice<Card> cardList) { | |
| return CardResponse.ProfileCardListDTO.builder() |
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()을 사용하여 중복 호출을 피하는 것이 좋습니다. 이렇게 하면 코드가 더 효율적이고 깔끔해집니다.
| .cardsList(cardList.getContent().stream() | |
| .map(CardConverter::toProfileCardDto) | |
| .toList()) | |
| .cardsList(list.stream() | |
| .map(CardConverter::toProfileCardDto) | |
| .toList()) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -293,6 +293,25 @@ public static class CardDeleteResponse { | |
|
|
||
| } | ||
|
|
||
| @Builder | ||
| @Getter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public static class profileCardListDTO{ | ||
|
||
| private Long userId; | ||
| private boolean hasNext; | ||
| private Long nextCursor; | ||
| private List<ProfileCardDTO> cardsList; | ||
| } | ||
|
|
||
| @Builder | ||
| @Getter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public static class ProfileCardDTO { | ||
| private Long cardId; | ||
| private String cardImageUrl; | ||
| } | ||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -110,4 +110,17 @@ SELECT ch.hashtag.id, COUNT(ch.card.id) | |||||||||||||||||
| """) | ||||||||||||||||||
| List<Object[]> countCardsByHashtagIds(@Param("hashtagIds") List<Long> hashtagIds); | ||||||||||||||||||
|
|
||||||||||||||||||
| Slice<Card> findByUserIdAndIsSharedTrueOrderByIdDesc(Long userId, Pageable pageable); | ||||||||||||||||||
| Slice<Card> findByUserIdAndIsSharedTrueAndIdLessThanOrderByIdDesc(Long userId, Long cursor, Pageable pageable); | ||||||||||||||||||
|
||||||||||||||||||
| Slice<Card> findByUserIdAndIsSharedTrueOrderByIdDesc(Long userId, Pageable pageable); | |
| Slice<Card> findByUserIdAndIsSharedTrueAndIdLessThanOrderByIdDesc(Long userId, Long cursor, Pageable pageable); | |
| Slice<Card> findByUserIdAndIsDeletedFalseAndIsSharedTrueOrderByIdDesc(Long userId, Pageable pageable); | |
| Slice<Card> findByUserIdAndIsDeletedFalseAndIsSharedTrueAndIdLessThanOrderByIdDesc(Long userId, Long cursor, Pageable pageable); |
Outdated
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.
프로필 카드 목록을 조회하는 쿼리 메서드에 삭제된 카드를 필터링하는 IsDeletedFalse 조건이 누락되었습니다. countByUserIdAndIsDeletedFalseAndIsSharedTrue 메서드에서는 해당 조건이 사용되고 있어 로직의 일관성이 부족하며, 삭제된 카드가 프로필에 노출될 수 있는 버그를 유발할 수 있습니다. 메서드 이름과 쿼리에 IsDeletedFalse 조건을 추가하여 수정하는 것을 권장합니다.
| Slice<Card> findByUserIdAndIsSharedTrueOrderByIdDesc(Long userId, Pageable pageable); | |
| Slice<Card> findByUserIdAndIsSharedTrueAndIdLessThanOrderByIdDesc(Long userId, Long cursor, Pageable pageable); | |
| Slice<Card> findByUserIdAndIsSharedTrueAndIsDeletedFalseOrderByIdDesc(Long userId, Pageable pageable); | |
| Slice<Card> findByUserIdAndIsSharedTrueAndIdLessThanAndIsDeletedFalseOrderByIdDesc(Long userId, Long cursor, Pageable pageable); |
| 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.findByUserIdAndIsSharedTrueOrderByIdDesc(userId, pageable); | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| cardSlice = cardRepository.findByUserIdAndIsSharedTrueAndIdLessThanOrderByIdDesc(userId, cursor, pageable); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
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. 이 메서드에서 호출하는
Suggested change
|
||||||||||||||||||||||
| 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.findUserById(userId); | ||
2anizirong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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); | ||
|
|
||
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.
컨트롤러 메서드의 반환 타입 또한 DTO 클래스 이름에 맞춰
ProfileCardListDTO로 변경해야 합니다. 일관성을 위해 수정해주세요.