-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] 피드 조회 시 [내 정보 or 특정 유저 정보] 조회하는 api 개발 #119
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c03a1aa
[feat] 피드 조회시 유저 정보 조회 api (2개) controller 개발 (#115)
seongjunnoh e3be4e2
[feat] 피드 조회시 유저 정보 조회 api (2개) use case 개발 (#115)
seongjunnoh 2f9da6d
[feat] 유저가 작성한 공개 피드 개수 반환 메서드 구현 (#115)
seongjunnoh 0c3e128
[feat] 팔로워의 프로필 이미지 조회하는 영속성 메서드 추가 (#115)
seongjunnoh 20ba819
[feat] 팔로워의 프로필 이미지 조회하는 QueryDSL 코드 구현 (#115)
seongjunnoh 388635e
[test] 피드 조회 시 유저의 정보 조회 api (2개) 통합 테스트 코드 작성 (#115)
seongjunnoh 782a524
[refactor] UserJpaEntity 에서 imageUrl 필드 삭제 (#115)
seongjunnoh a839915
[refactor] UserMapper 수정 (#115)
seongjunnoh e31757a
[refactor] UserJpaEntity 에서 imageUrl 필드를 제거함에 따른 프로덕션 코드 수정 (#115)
seongjunnoh 9360e05
[refactor] UserJpaEntity 에서 imageUrl 필드를 제거함에 따른 TestEntityFactory 코드…
seongjunnoh c778d0b
[refactor] UserJpaEntity 에서 imageUrl 필드를 제거함에 따른 나머지 테스트 코드 수정 (#115)
seongjunnoh 05fc9cb
[refactor] 메서드 네이밍 수정 (#115)
seongjunnoh 92d2c23
[feat] api 설명을 위해 스웨거 operation 추가 (#115)
seongjunnoh 333e001
[refactor] response 구성 책임을 mapper가 수행하도록 수정 (#115)
seongjunnoh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/konkuk/thip/feed/adapter/in/web/response/FeedShowUserInfoResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package konkuk.thip.feed.adapter.in.web.response; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Builder | ||
| public record FeedShowUserInfoResponse( | ||
| String profileImageUrl, | ||
| String nickname, | ||
| String aliasName, | ||
| String aliasColor, | ||
| int followerCount, | ||
| int totalFeedCount, | ||
| List<String> latestFollowerProfileImageUrls | ||
| ) { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/konkuk/thip/feed/application/port/in/FeedShowUserInfoUseCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package konkuk.thip.feed.application.port.in; | ||
|
|
||
| import konkuk.thip.feed.adapter.in.web.response.FeedShowUserInfoResponse; | ||
|
|
||
| public interface FeedShowUserInfoUseCase { | ||
|
|
||
| FeedShowUserInfoResponse showMyInfoInFeeds(Long userId); | ||
|
|
||
| FeedShowUserInfoResponse showAnotherUserInfoInFeeds(Long anotherUserId); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/konkuk/thip/feed/application/service/FeedShowUserInfoService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package konkuk.thip.feed.application.service; | ||
|
|
||
| import konkuk.thip.feed.adapter.in.web.response.FeedShowUserInfoResponse; | ||
| import konkuk.thip.feed.application.mapper.FeedQueryMapper; | ||
| import konkuk.thip.feed.application.port.in.FeedShowUserInfoUseCase; | ||
| import konkuk.thip.feed.application.port.out.FeedQueryPort; | ||
| import konkuk.thip.user.application.port.out.FollowingQueryPort; | ||
| import konkuk.thip.user.application.port.out.UserCommandPort; | ||
| import konkuk.thip.user.domain.User; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class FeedShowUserInfoService implements FeedShowUserInfoUseCase { | ||
|
|
||
| private static final int FOLLOWER_DISPLAY_LIMIT = 5; | ||
| private final UserCommandPort userCommandPort; | ||
| private final FollowingQueryPort followingQueryPort; | ||
| private final FeedQueryPort feedQueryPort; | ||
| private final FeedQueryMapper feedQueryMapper; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| @Override | ||
| public FeedShowUserInfoResponse showMyInfoInFeeds(Long userId) { | ||
| // 1. User 찾기 | ||
| User feedOwner = userCommandPort.findById(userId); | ||
|
|
||
| // 2. 해당 유저를 팔로우 하는 유저들을 프로필 이미지 정보 구하기 | ||
| List<String> latestFollowerProfileImageUrls = followingQueryPort.getLatestFollowerImageUrls(userId, FOLLOWER_DISPLAY_LIMIT); | ||
|
|
||
| // 3. 내가 작성한 전체 피드 개수 구하기 | ||
| int allFeedCount = feedQueryPort.countAllFeedsByUserId(userId); | ||
|
|
||
| return feedQueryMapper.toFeedShowUserInfoResponse(feedOwner, allFeedCount, latestFollowerProfileImageUrls); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| @Override | ||
| public FeedShowUserInfoResponse showAnotherUserInfoInFeeds(Long anotherUserId) { | ||
| // 1. User 찾기 | ||
| User feedOwner = userCommandPort.findById(anotherUserId); | ||
|
|
||
| // 2. 해당 유저를 팔로우 하는 유저들을 프로필 이미지 정보 구하기 | ||
| List<String> latestFollowerProfileImageUrls = followingQueryPort.getLatestFollowerImageUrls(anotherUserId, FOLLOWER_DISPLAY_LIMIT); | ||
|
|
||
| // 3. 유저가 작성한 공개 피드 개수 구하기 | ||
| int publicFeedCount = feedQueryPort.countPublicFeedsByUserId(anotherUserId); | ||
|
|
||
| return feedQueryMapper.toFeedShowUserInfoResponse(feedOwner, publicFeedCount, latestFollowerProfileImageUrls); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,9 +23,6 @@ public class UserJpaEntity extends BaseJpaEntity { | |
| @Column(length = 60, nullable = false) | ||
| private String nickname; | ||
|
|
||
| @Column(name = "image_url", columnDefinition = "TEXT", nullable = false) | ||
| private String imageUrl; | ||
|
|
||
|
Comment on lines
-26
to
-28
Contributor
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. 👍🏻 👍🏻 |
||
| @Column(name = "oauth2_id", length = 50, nullable = false) | ||
| private String oauth2Id; | ||
|
|
||
|
|
@@ -43,8 +40,7 @@ public class UserJpaEntity extends BaseJpaEntity { | |
| public void updateFrom(User user) { | ||
| this.nickname = user.getNickname(); | ||
| Assert.notNull(user.getAlias(), "Alias must not be null"); | ||
| this.imageUrl = user.getAlias().getImageUrl(); | ||
| this.role = UserRole.from(user.getUserRole()); | ||
| this.followerCount = user.getFollowerCount(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,4 +89,22 @@ private List<UserQueryDto> findFollowDtos(Long userId, LocalDateTime cursor, int | |
| .limit(size + 1) | ||
| .fetch(); | ||
| } | ||
|
|
||
| @Override | ||
| public List<String> findLatestFollowerImageUrls(Long userId, int size) { | ||
| QFollowingJpaEntity following = QFollowingJpaEntity.followingJpaEntity; | ||
| QUserJpaEntity follower = QUserJpaEntity.userJpaEntity; // userId 를 팔로우하는 사람들(= follower) | ||
| QAliasJpaEntity alias = QAliasJpaEntity.aliasJpaEntity; | ||
|
|
||
| return jpaQueryFactory | ||
| .select(alias.imageUrl) | ||
| .from(following) | ||
| .join(following.userJpaEntity, follower) | ||
| .join(follower.aliasForUserJpaEntity, alias) | ||
| .where(following.followingUserJpaEntity.userId.eq(userId) | ||
| .and(following.status.eq(StatusType.ACTIVE))) | ||
| .orderBy(following.createdAt.desc()) | ||
| .limit(size) | ||
| .fetch(); | ||
| } | ||
|
Comment on lines
+93
to
+109
Contributor
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. LGTM |
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
여기서는 파라미터로 statusType까지 전달해서 동적으로 필터링한 이유가 있나요?? (단순 궁금)
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.
그냥 jpa repository 내부에서 status = ACTIVE 구문을 추가할까 하다가, 영속성 adapter 에서 주입해주는게 "status가 ACTIVE인 것을 찾는다" 라는 것을 보여주고 싶어서 위와 같이 구현해보았습니다