Skip to content

Commit

Permalink
Merge pull request #22 from TG-WinG/feature/blog
Browse files Browse the repository at this point in the history
fix: missing field on post views
  • Loading branch information
wwingyou authored Oct 14, 2024
2 parents 635269e + 4ada716 commit bde62c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/kr/tgwing/tech/blog/dto/PostDetail.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.tgwing.tech.blog.dto;

import java.time.format.DateTimeFormatter;
import java.util.Set;

import lombok.Builder;
Expand All @@ -18,16 +19,19 @@ public class PostDetail {
private String title;
private String content;
private String thumbnail;
private String modDate;
private int likeCount;
private int commnetCount;
@Singular private Set<String> hashtags;

public static PostDetail of(Post post) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
var builder = PostDetail.builder()
.id(post.getId())
.title(post.getTitle())
.writer(ProfileDTO.of(post.getWriter()))
.thumbnail(post.getThumbnail())
.modDate(post.getModDate().format(formatter))
.content(post.getContent())
.commnetCount(post.getComments().size());

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/kr/tgwing/tech/blog/dto/PostOverview.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.tgwing.tech.blog.dto;

import java.time.format.DateTimeFormatter;
import java.util.Set;

import lombok.Builder;
Expand All @@ -19,17 +20,22 @@ public class PostOverview {
private ProfileDTO writer;
private String title;
private String summary;
private String thumbnail;
private String modDate;
private int likeCount;
private int commentCount;
@Singular private final Set<String> hashtags;

public static PostOverview of(Post post) {
String content = post.getContent();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return PostOverview.builder()
.id(post.getId())
.writer(ProfileDTO.of(post.getWriter()))
.title(post.getTitle())
.summary((content.length() < SUMMARY_LENGTH) ? content : content.substring(0, SUMMARY_LENGTH))
.thumbnail(post.getThumbnail())
.modDate(post.getModDate().format(formatter))
.commentCount(post.getComments().size())
.hashtags(post.getHashtags().stream().map(hashtag -> hashtag.getName()).toList())
.build();
Expand Down

0 comments on commit bde62c9

Please sign in to comment.