-
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.
Merge pull request #29 from Team-Walkie/mvc/byeonghee
[api] 타인 게시글 목록 가져오기, 내 게시글 목록 가져오기
- Loading branch information
Showing
9 changed files
with
153 additions
and
7 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
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
3 changes: 2 additions & 1 deletion
3
src/main/java/com/whyranoid/walkie/repository/PostRepository.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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package com.whyranoid.walkie.repository; | ||
|
||
import com.whyranoid.walkie.domain.Post; | ||
import com.whyranoid.walkie.repository.querydsl.PostRepositoryCustom; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface PostRepository extends JpaRepository<Post, Long> { | ||
public interface PostRepository extends JpaRepository<Post, Long>, PostRepositoryCustom { | ||
|
||
Optional<Post> findByPostId(Long postId); | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/whyranoid/walkie/repository/querydsl/PostRepositoryCustom.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,13 @@ | ||
package com.whyranoid.walkie.repository.querydsl; | ||
|
||
import com.querydsl.jpa.JPQLQuery; | ||
import com.whyranoid.walkie.dto.PostDto; | ||
|
||
import java.util.List; | ||
|
||
public interface PostRepositoryCustom { | ||
|
||
List<PostDto> findCurrentPosts(JPQLQuery<Long> following, Long viewerId, Integer pagingSize, Integer pagingStart); | ||
|
||
List<PostDto> findMyPosts(Long viewerId, Integer pagingSize, Integer pagingStart); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/whyranoid/walkie/repository/querydsl/PostRepositoryImpl.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,46 @@ | ||
package com.whyranoid.walkie.repository.querydsl; | ||
|
||
import com.querydsl.core.types.dsl.Expressions; | ||
import com.querydsl.jpa.JPQLQuery; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import com.whyranoid.walkie.dto.PostDto; | ||
import com.whyranoid.walkie.dto.QPostDto; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
import static com.whyranoid.walkie.domain.QPost.post; | ||
|
||
@RequiredArgsConstructor | ||
public class PostRepositoryImpl implements PostRepositoryCustom { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
// TODO: 나의 좋아요 여부 반영 | ||
// TODO: 좋아요 누른 사람 목록 반영 | ||
@Override | ||
public List<PostDto> findCurrentPosts(JPQLQuery<Long> following, Long viewerId, Integer pagingSize, Integer pagingStart) { | ||
return queryFactory | ||
.select(new QPostDto(post, Expressions.asNumber(viewerId))) | ||
.from(post) | ||
.where(post.user.userId.in(following)) | ||
.orderBy(post.date.desc()) | ||
.offset(pagingStart) | ||
.limit(pagingSize) | ||
.fetch(); | ||
} | ||
|
||
// TODO: 나의 좋아요 여부 반영 | ||
// TODO: 좋아요 누른 사람 목록 반영 | ||
@Override | ||
public List<PostDto> findMyPosts(Long viewerId, Integer pagingSize, Integer pagingStart) { | ||
return queryFactory | ||
.select(new QPostDto(post, Expressions.asNumber(viewerId))) | ||
.from(post) | ||
.where(post.user.userId.eq(viewerId)) | ||
.orderBy(post.date.desc()) | ||
.offset(pagingStart) | ||
.limit(pagingSize) | ||
.fetch(); | ||
} | ||
} |
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