Skip to content

Commit

Permalink
Merge pull request #17 from STUDIO-EYE/feat/EPIC-80-post
Browse files Browse the repository at this point in the history
Feat/epic 80 post
  • Loading branch information
ibaesuyeon authored May 1, 2024
2 parents cf82008 + c12370f commit 6e7a05f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class PostDetailResponse {
@Schema(description = "게시글 내용")
private String content;

@Schema(description = "작성자ID")
private Long writerId;

@Schema(description = "작성자")
private String userName;

Expand All @@ -47,13 +50,14 @@ public class PostDetailResponse {
@Schema(description = "수정일")
private LocalDateTime updatedAt;

public static PostDetailResponse from(Post post, String userName){
public static PostDetailResponse from(Post post, Long writerId, String userName){

return PostDetailResponse.builder()
.id(post.getId())
// .status()
.title(post.getTitle())
.content(post.getContent())
.writerId(writerId)
.userName(userName)
.startDate(post.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy년 MM월 dd일 HH:mm:ss")))
.commentSum(post.getCommentList().size())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class PostResponse {
@Schema(description = "게시글 제목")
private String title;

@Schema(description = "작성자ID")
private Long writerId;

@Schema(description = "작성자")
private String userName;

Expand All @@ -40,12 +43,14 @@ public class PostResponse {
@Schema(description = "수정일")
private LocalDateTime updatedAt;

public static PostResponse from(Post post, String userName){

public static PostResponse from(Post post, Long writerId, String userName){

return PostResponse.builder()
.id(post.getId())
// .status()
.title(post.getTitle())
.writerId(writerId)
.userName(userName)
.startDate(post.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy년 MM월 dd일 HH:mm:ss")))
.commentSum(post.getCommentList().size())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public List<PostResponse> readAll(Long projectId, Long userId, String category)
List<Post> postList = postRepository.findByCategoryAndProject(getCategory, project);
List<PostResponse> postResponseList = new ArrayList<>();
postList.forEach(post->{
postResponseList.add(PostResponse.from(post, userService.getUsername(post.getWriterId())));
postResponseList.add(PostResponse.from(post,
post.getWriterId(), userService.getUsername(post.getWriterId())));
});
return postResponseList;
}
Expand All @@ -65,7 +66,8 @@ public List<PostResponse> readThree(Long projectId, Long userId, String category
List<Post> postList = postRepository.findByCategoryAndProject(getCategory,project, pageable);
List<PostResponse> postResponseList = new ArrayList<>();
postList.forEach(post->{
postResponseList.add(PostResponse.from(post, userService.getUsername(post.getWriterId())));
postResponseList.add(PostResponse.from(post, post.getWriterId(),
userService.getUsername(post.getWriterId())));
});
return postResponseList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public CommonResult retrieveDetailPost(RetrieveDetailPostRequestServiceDto dto)
}

Post post = optionalPost.get();
return responseService.getSingleResult(PostDetailResponse.from(post, userService.getUsername(post.getWriterId())));
return responseService.getSingleResult(PostDetailResponse.from(post,
post.getWriterId(), userService.getUsername(post.getWriterId())));
}

@Transactional(readOnly = true)
Expand Down

0 comments on commit 6e7a05f

Please sign in to comment.