Skip to content

Commit

Permalink
feat: #15 미디어 게시글만 조회 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ehs208 committed Nov 4, 2024
1 parent c65dd66 commit 38ff4f9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public ResponseEntity<GlobalResponseDto<List<ArticlesResponseDto>>> getArticles(
.body(GlobalResponseDto.success(postService.getArticles(customId)));
}

// @GetMapping("/{customId}/list/media")
// @Operation(summary = "특정 사용자의 미디어 게시글 조회", description = "특정 사용자의 미디어 게시글을 조회합니다.")
// public ResponseEntity<GlobalResponseDto<List<ArticleWithMediaResponseDto>>> getMediaArticles(
// @PathVariable String customId) {
// return ResponseEntity.status(HttpStatus.OK)
// .body(GlobalResponseDto.success(postService.getMediaArticles(customId)));
// }
@GetMapping("/{customId}/list/media")
@Operation(summary = "특정 사용자의 미디어 게시글 조회", description = "특정 사용자의 미디어 게시글을 조회합니다.")
public ResponseEntity<GlobalResponseDto<List<ArticlesResponseDto>>> getMediaArticles(
@PathVariable String customId) {
return ResponseEntity.status(HttpStatus.OK)
.body(GlobalResponseDto.success(postService.getArticlesWithMedia(customId)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public class Post {
@JoinColumn(name = "repost_id")
private Post rePost;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "hashtag_id")
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "hashtag_id")
private List<Hashtag> hashtags;

public Post(User writer, String content, DeletedStatus deletedStatus, Boolean isPinned, Post rePost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,15 @@ public List<ArticlesResponseDto> getArticles(String customId) {
.map(post -> ArticlesResponseDto.from((Post)post[0], (String)post[1]))
.collect(Collectors.toList());
}

public List<ArticlesResponseDto> getArticlesWithMedia(String customId) {
User user = userRepository.findByCustomId(customId).orElseThrow(UserNotFoundException::new);
List<Object[]> posts = postRepository.findPostsByWriter(user);

return posts.stream()
.filter(post -> post[1] != null)
.map(post -> ArticlesResponseDto.from((Post)post[0], (String)post[1]))
.collect(Collectors.toList());
}
}

0 comments on commit 38ff4f9

Please sign in to comment.