Skip to content

Commit

Permalink
feat: keyword search for post writer
Browse files Browse the repository at this point in the history
  • Loading branch information
wwingyou committed Nov 24, 2024
1 parent 9106834 commit fa44fa3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ public static Specification<Post> hasWriterStudentNumber(String studentNumber) {
};
}

public static Specification<Post> hasWriterNameLike(String name) {
return (root, query, cb) -> {
Join<User, Post> userPost = root.join("writer");
return cb.like(userPost.get("name"), "%" + name + "%");
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ public void deletePost(Long postId, String writerStudentNumber) {
public Page<PostOverview> getPostOverviews(PostQuery query, String userStudentNumber, Pageable pageable) {
User user = getUserEntity(userStudentNumber);
Specification<Post> spec = PostSpecifications.hasTitleLike(query.getKeyword())
.or(PostSpecifications.hasContentLike(query.getKeyword()));
.or(PostSpecifications.hasContentLike(query.getKeyword()))
.or(PostSpecifications.hasWriterNameLike(query.getKeyword()));

if (query.getHashtag() != null && query.getHashtag().size() > 0) {
spec = spec.and(PostSpecifications.hasHashtagIn(query.getHashtag()));
Expand Down

0 comments on commit fa44fa3

Please sign in to comment.