Skip to content

Commit 4cc935e

Browse files
authored
Feat: 프로필 화면 상단정보 / 피드 이미지 미리보기 api (#177)
## #️⃣연관된 이슈 > ex) #이슈번호, #이슈번호 ## 📝작업 내용 > 이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능) ### 스크린샷 (선택) ## 💬리뷰 요구사항(선택) > 리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요 > > ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?
2 parents 4856017 + 787f642 commit 4cc935e

File tree

13 files changed

+149
-1
lines changed

13 files changed

+149
-1
lines changed

src/main/java/EatPic/spring/domain/card/controller/CardController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,13 @@ public ApiResponse<List<RecommendCardResponse>> getRecommendedCards(
143143
return ApiResponse.onSuccess(cardService.getRecommendedCardPreviews(user.getId()));
144144
}
145145

146+
@GetMapping("/profile/{userId}")
147+
@Operation(summary = "프로필 화면 피드 미리보기", description = "공유한 카드의 번호와 이미지 url 조회 API")
148+
public ApiResponse<CardResponse.ProfileCardListDTO> getProfileCardsList(@PathVariable Long userId,
149+
@RequestParam(required = false) Long cursor,
150+
@RequestParam(defaultValue = "15") int size) {
151+
return ApiResponse.onSuccess(cardService.getProfileCardList(userId, size, cursor));
152+
}
153+
146154

147155
}

src/main/java/EatPic/spring/domain/card/converter/CardConverter.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,23 @@ public static CardDeleteResponse toCardDeleteResponse(Card card) {
157157
.successMessage("카드 삭제 성공")
158158
.build();
159159
}
160+
161+
public static CardResponse.ProfileCardDTO toProfileCardDto(Card card){
162+
return CardResponse.ProfileCardDTO.builder()
163+
.cardId(card.getId())
164+
.cardImageUrl(card.getCardImageUrl())
165+
.build();
166+
}
167+
168+
public static CardResponse.ProfileCardListDTO toProfileCardList(Long userId, Slice<Card> cardList) {
169+
List<Card> list = cardList.getContent();
170+
return CardResponse.ProfileCardListDTO.builder()
171+
.hasNext(cardList.hasNext())
172+
.nextCursor(cardList.hasNext() ? list.get(list.size() - 1).getId() : null)
173+
.userId(userId)
174+
.cardsList(cardList.getContent().stream()
175+
.map(CardConverter::toProfileCardDto)
176+
.toList())
177+
.build();
178+
}
160179
}

src/main/java/EatPic/spring/domain/card/dto/response/CardResponse.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,25 @@ public static class CardDeleteResponse {
293293

294294
}
295295

296+
@Builder
297+
@Getter
298+
@NoArgsConstructor
299+
@AllArgsConstructor
300+
public static class ProfileCardListDTO{
301+
private Long userId;
302+
private boolean hasNext;
303+
private Long nextCursor;
304+
private List<ProfileCardDTO> cardsList;
305+
}
306+
307+
@Builder
308+
@Getter
309+
@NoArgsConstructor
310+
@AllArgsConstructor
311+
public static class ProfileCardDTO {
312+
private Long cardId;
313+
private String cardImageUrl;
314+
}
296315

297316

298317
}

src/main/java/EatPic/spring/domain/card/repository/CardRepository.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,17 @@ SELECT ch.hashtag.id, COUNT(ch.card.id)
110110
""")
111111
List<Object[]> countCardsByHashtagIds(@Param("hashtagIds") List<Long> hashtagIds);
112112

113+
Slice<Card> findByUserIdAndIsSharedTrueAndIsDeletedFalseOrderByIdDesc(Long userId, Pageable pageable);
114+
Slice<Card> findByUserIdAndIsSharedTrueAndIsDeletedFalseAndIdLessThanOrderByIdDesc(Long userId, Long cursor, Pageable pageable);
115+
116+
@Query("""
117+
select count(c)
118+
from Card c
119+
where c.isDeleted = false
120+
and c.isShared = true
121+
and c.user.id = :userId
122+
""")
123+
Long countByUserIdAndIsDeletedFalseAndIsSharedTrue(@Param("userId") Long userId);
124+
125+
113126
}

src/main/java/EatPic/spring/domain/card/service/CardService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ public interface CardService {
2525
CardDetailResponse updateCard(Long cardId, User user, CardUpdateRequest request);
2626
CardResponse.PagedCardFeedResponseDto getCardFeedByCursor(HttpServletRequest request, Long userId, int size, Long cursor);
2727
List<RecommendCardResponse> getRecommendedCardPreviews(Long userId);
28+
CardResponse.ProfileCardListDTO getProfileCardList(Long userId, int size, Long cursor);
2829
}

src/main/java/EatPic/spring/domain/card/service/CardServiceImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,19 @@ public CardFeedResponse getCardFeed(Long cardId, Long userId) {
251251
);
252252
}
253253

254+
@Override
255+
public CardResponse.ProfileCardListDTO getProfileCardList(Long userId, int size, Long cursor) {
256+
Slice<Card> cardSlice;
257+
Pageable pageable = PageRequest.of(0, size);
258+
259+
if (cursor == null) {
260+
cardSlice = cardRepository.findByUserIdAndIsSharedTrueAndIsDeletedFalseOrderByIdDesc(userId, pageable);
261+
} else {
262+
cardSlice = cardRepository.findByUserIdAndIsSharedTrueAndIsDeletedFalseAndIdLessThanOrderByIdDesc(userId, cursor, pageable);
263+
}
264+
return CardConverter.toProfileCardList(userId, cardSlice);
265+
}
266+
254267
@Override
255268
@Transactional
256269
public CardDeleteResponse deleteCard(Long cardId, Long userId) {

src/main/java/EatPic/spring/domain/user/controller/UserRestController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,11 @@ public ApiResponse<UserResponseDTO.ProfileDto> updateUserIntroduce(
7979
UserResponseDTO.ProfileDto updatedProfile = userService.updateIntroduce(request, introduce, user);
8080
return ApiResponse.onSuccess(updatedProfile);
8181
}
82+
83+
@Operation(summary = "유저 프로필 조회")
84+
@GetMapping("/profile/{userId}")
85+
public ApiResponse<UserResponseDTO.DetailProfileDto> getProfile(HttpServletRequest request,
86+
@PathVariable Long userId) {
87+
return ApiResponse.onSuccess(userService.getProfile(request,userId));
88+
}
8289
}

src/main/java/EatPic/spring/domain/user/converter/UserConverter.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public static UserResponseDTO.ProfileDto toProfileIconDto(User user){
6363
.isFollowing(true)
6464
.build();
6565
}
66-
// todo: 두개 비슷함 -> 합치기
6766
public static UserResponseDTO.ProfileDto toProfileDto(User user, Boolean isFollowing){
6867
return UserResponseDTO.ProfileDto.builder()
6968
.userId(user.getId())
@@ -73,6 +72,25 @@ public static UserResponseDTO.ProfileDto toProfileDto(User user, Boolean isFollo
7372
.isFollowing(isFollowing)
7473
.build();
7574
}
75+
public static UserResponseDTO.DetailProfileDto toDetailProfileDto(
76+
User user,
77+
Boolean isFollowing,
78+
Long totalCard,
79+
Long totalFollower,
80+
Long totalFollowing) {
81+
82+
return UserResponseDTO.DetailProfileDto.builder()
83+
.userId(user.getId())
84+
.profileImageUrl(user.getProfileImageUrl())
85+
.nameId(user.getNameId())
86+
.nickname(user.getNickname())
87+
.isFollowing(isFollowing)
88+
.introduce(user.getIntroduce())
89+
.totalCard(totalCard)
90+
.totalFollower(totalFollower)
91+
.totalFollowing(totalFollowing)
92+
.build();
93+
}
7694

7795
public static ReactionResponseDTO.CardReactionUserListDto toCardReactionUsersListDto(Long cardId, ReactionType reactionType, Page<UserResponseDTO.ProfileDto> profileList){
7896
return ReactionResponseDTO.CardReactionUserListDto.builder()

src/main/java/EatPic/spring/domain/user/dto/response/UserResponseDTO.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,31 @@ public static class UserIconListResponseDto{
4444
private List<ProfileDto> userIconList;
4545
}
4646

47+
@Getter
48+
@Builder
49+
@AllArgsConstructor
50+
@NoArgsConstructor
51+
public static class DetailProfileDto {
52+
@NotNull
53+
private Long userId;
54+
@NotNull
55+
private String profileImageUrl;
56+
@NotNull
57+
private String nameId;
58+
@NotNull
59+
private String nickname;
60+
@NotNull
61+
private Boolean isFollowing;
62+
@NotNull
63+
private String introduce;
64+
@NotNull
65+
private Long totalCard;
66+
@NotNull
67+
private Long totalFollower;
68+
@NotNull
69+
private Long totalFollowing;
70+
}
71+
4772
@Getter
4873
@Builder
4974
@AllArgsConstructor

src/main/java/EatPic/spring/domain/user/repository/UserFollowRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ public interface UserFollowRepository extends JpaRepository<UserFollow,Long> {
2323
List<Long> findFollowingUserIds(@Param("userId") Long userId);
2424

2525
UserFollow findByUserAndTargetUser(User user, User target);
26+
27+
Long countUserFollowByTargetUser(User targetUser);
28+
Long countUserFollowByUser(User user);
2629
}

0 commit comments

Comments
 (0)