-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] 팔로잉 피드, 사용자가 올린 게시물 목록 조회를 구현한다 (#35)
* fix: transform이 동작하지 않는 에러 수정 * refactor: PageArgumentResolver가 lastId 값이 없다면 null로 채우도록 수정 * feature: 팔로잉 피드 조회 구현 * fix: 팔로잉, 팔로워 목록 조회 시 lastId가 null인 경우 동적쿼리를 사용 * feature: 사용자가 업로드한 게시물 목록 조회 구현
- Loading branch information
Showing
12 changed files
with
245 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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
36 changes: 36 additions & 0 deletions
36
src/main/java/daybyquest/post/application/GetPostByUsernameService.java
This file contains 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,36 @@ | ||
package daybyquest.post.application; | ||
|
||
import daybyquest.global.query.LongIdList; | ||
import daybyquest.global.query.NoOffsetIdPage; | ||
import daybyquest.post.dto.response.PagePostsResponse; | ||
import daybyquest.post.query.PostDao; | ||
import daybyquest.post.query.PostData; | ||
import daybyquest.user.domain.Users; | ||
import java.util.List; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
public class GetPostByUsernameService { | ||
|
||
private final PostDao postDao; | ||
|
||
private final Users users; | ||
|
||
private final PostResponseConverter converter; | ||
|
||
public GetPostByUsernameService(final PostDao postDao, final Users users, | ||
final PostResponseConverter converter) { | ||
this.postDao = postDao; | ||
this.users = users; | ||
this.converter = converter; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public PagePostsResponse invoke(final Long loginId, final String username, final NoOffsetIdPage page) { | ||
final Long targetId = users.getUserIdByUsername(username); | ||
final LongIdList postIds = postDao.findPostIdsByUserId(loginId, targetId, page); | ||
final List<PostData> postData = postDao.findAllByIdIn(loginId, postIds.getIds()); | ||
return new PagePostsResponse(converter.convertFromPostData(loginId, postData), postIds.getLastId()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/daybyquest/post/application/GetPostFromFollowingService.java
This file contains 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,30 @@ | ||
package daybyquest.post.application; | ||
|
||
import daybyquest.global.query.LongIdList; | ||
import daybyquest.global.query.NoOffsetIdPage; | ||
import daybyquest.post.dto.response.PagePostsResponse; | ||
import daybyquest.post.query.PostDao; | ||
import daybyquest.post.query.PostData; | ||
import java.util.List; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
public class GetPostFromFollowingService { | ||
|
||
private final PostDao postDao; | ||
|
||
private final PostResponseConverter converter; | ||
|
||
public GetPostFromFollowingService(final PostDao postDao, final PostResponseConverter converter) { | ||
this.postDao = postDao; | ||
this.converter = converter; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public PagePostsResponse invoke(final Long loginId, final NoOffsetIdPage page) { | ||
final LongIdList postIds = postDao.findPostIdsFromFollowings(loginId, page); | ||
final List<PostData> postData = postDao.findAllByIdIn(loginId, postIds.getIds()); | ||
return new PagePostsResponse(converter.convertFromPostData(loginId, postData), postIds.getLastId()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/daybyquest/post/application/PostResponseConverter.java
This file contains 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,28 @@ | ||
package daybyquest.post.application; | ||
|
||
import daybyquest.post.dto.response.PostResponse; | ||
import daybyquest.post.query.PostData; | ||
import daybyquest.user.query.Profile; | ||
import daybyquest.user.query.ProfileDao; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class PostResponseConverter { | ||
|
||
private final ProfileDao profileDao; | ||
|
||
public PostResponseConverter(final ProfileDao profileDao) { | ||
this.profileDao = profileDao; | ||
} | ||
|
||
public List<PostResponse> convertFromPostData(final Long loginId, final List<PostData> postData) { | ||
final Set<Long> userIds = postData.stream().map(PostData::getUserId).collect(Collectors.toSet()); | ||
final Map<Long, Profile> profiles = profileDao.findMapByUserIdIn(loginId, userIds); | ||
return postData.stream() | ||
.map((pd) -> PostResponse.of(pd, profiles.get(pd.getUserId()))).toList(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/daybyquest/post/dto/response/PagePostsResponse.java
This file contains 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,19 @@ | ||
package daybyquest.post.dto.response; | ||
|
||
import java.util.List; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class PagePostsResponse { | ||
|
||
private List<PostResponse> posts; | ||
|
||
private Long lastId; | ||
|
||
public PagePostsResponse(final List<PostResponse> posts, final Long lastId) { | ||
this.posts = posts; | ||
this.lastId = lastId; | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1,6 +1,17 @@ | ||
package daybyquest.post.query; | ||
|
||
import daybyquest.global.query.LongIdList; | ||
import daybyquest.global.query.NoOffsetIdPage; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public interface PostDao { | ||
|
||
PostData getByPostId(final Long userId, final Long postId); | ||
|
||
LongIdList findPostIdsFromFollowings(final Long userId, final NoOffsetIdPage page); | ||
|
||
LongIdList findPostIdsByUserId(final Long userId, final Long targetId, final NoOffsetIdPage page); | ||
|
||
List<PostData> findAllByIdIn(final Long userId, final Collection<Long> postIds); | ||
} |
This file contains 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 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 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 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