Skip to content

Commit

Permalink
Merge pull request #170 from pknu-wap/feature/또또추가사항
Browse files Browse the repository at this point in the history
수정
  • Loading branch information
JONG-KYEONG authored Nov 29, 2023
2 parents f4ab391 + a2f0e68 commit c19d61c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ public ResponseEntity<PostPreviewDtos> searchPost(@RequestParam(defaultValue = "
return new ResponseEntity<>(postPreviewDtos, HttpStatus.OK);
}

@GetMapping("/search/category")
public ResponseEntity<PostPreviewDtos> searchContentsByCategory(@RequestParam Long categoryId) {
//content 내용을 포함한 게시글의 리스트를 생성한다.
PostPreviewDtos postPreviewDtos = postService.searchPostsByCategory(categoryId);

return new ResponseEntity<>(postPreviewDtos, HttpStatus.OK);
}



@PatchMapping("/post/like")
public ResponseEntity<String> plusLike(@CurrentUser UserPrincipal userPrincipal,
@RequestParam Long postId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.project.Glog.repository;

import com.project.Glog.domain.Category;
import com.project.Glog.domain.Post;
import com.project.Glog.domain.User;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -34,6 +35,7 @@ public interface PostRepository extends JpaRepository<Post,Long> {

List<Post> findAllByTitleContaining(String title);
List<Post> findAllByUser(User user);
List<Post> findAllByCategory(Category category);
List<Post> findAllByContentContaining(String contnt);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public interface PrPostRepository extends JpaRepository<PrPost, Long> {
@Query("SELECT pr FROM PrPost pr WHERE pr.id=:prId")
Optional<PrPost> findPrByPrId( @Param("prId") Long prId);

@Query("SELECT p.category FROM PrPost p WHERE p.category.id=:PrId")
Category findByPrId(@Param("PrId") Long PrId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Post create(UserPrincipal userPrincipal, MultipartFile multipartFile, Pos

if (req.getPrId() != null) {
PrPost prPost = prPostRepository.findPrByPrId(req.getPrId()).get();
Category ct = prPostRepository.findByPrId(req.getPrId());
Category ct = prPost.getCategory();
post = req.toPost(user, ct, blog);
post.setPrPost(prPost);
post.setIsPr(true);
Expand Down Expand Up @@ -312,6 +312,13 @@ public String clickLike(UserPrincipal userPrincipal, Long postId) {
}
}

public PostPreviewDtos searchPostsByCategory(Long categoryId) {
Category category = categoryRepository.findByCategoryId(categoryId);
List<Post> posts = postRepository.findAllByCategory(category);

return new PostPreviewDtos(posts, posts.size());
}

private void setPostHashtag(Post post, List<String> hashtagList) {
for (String hashtag : hashtagList) {
PostHashtag postHashtag = new PostHashtag();
Expand Down

0 comments on commit c19d61c

Please sign in to comment.