From ea97c08a87dca5abea4cf1f77fe02273932aac34 Mon Sep 17 00:00:00 2001 From: Haeun-Y Date: Fri, 22 Sep 2023 21:42:33 +0900 Subject: [PATCH] =?UTF-8?q?#4=20fix:=20=EB=82=B4=EC=9A=A9=20=EA=B8=80?= =?UTF-8?q?=EC=9E=90=EC=88=98=20=EC=B4=88=EA=B3=BC=EC=8B=9C=20...=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=ED=9B=84=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ewhatever/qna/user/dto/GetCommentResponse.java | 13 +++++++++++-- .../qna/user/dto/GetJunyQuestionResponse.java | 6 +++++- .../ewhatever/qna/user/dto/GetScrapResponse.java | 12 ++++++++++-- .../qna/user/dto/GetSinyAnswerResponse.java | 7 ++++++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/ewhatever/qna/user/dto/GetCommentResponse.java b/src/main/java/com/ewhatever/qna/user/dto/GetCommentResponse.java index 69a8622..56b3d91 100644 --- a/src/main/java/com/ewhatever/qna/user/dto/GetCommentResponse.java +++ b/src/main/java/com/ewhatever/qna/user/dto/GetCommentResponse.java @@ -22,9 +22,18 @@ public class GetCommentResponse { //TODO : dto에서 LocalDateTime -> LocalDate로 변경 public static GetCommentResponse fromComment(Comment comment) { Post post = comment.getPost(); - return GetCommentResponse.builder().content(comment.getContent().substring(0, Math.min(comment.getContent().length(), 20))) + + String title; + if(post.getTitle().length() > 10) title = post.getTitle().substring(0, 10) + "..."; + else title = post.getTitle(); + + String content; + if(comment.getContent().length() > 20) content = comment.getContent().substring(0, 20) + "..."; + else content = comment.getContent(); + + return GetCommentResponse.builder().content(content) .date(comment.getCreatedDate().format(DateTimeFormatter.ofPattern("yy/MM/dd HH:mm"))) .postIdx(post.getPostIdx()) - .postTitle(post.getTitle().substring(0, Math.min(post.getTitle().length(), 10))).build(); + .postTitle(title).build(); } } diff --git a/src/main/java/com/ewhatever/qna/user/dto/GetJunyQuestionResponse.java b/src/main/java/com/ewhatever/qna/user/dto/GetJunyQuestionResponse.java index 7bfc882..011f308 100644 --- a/src/main/java/com/ewhatever/qna/user/dto/GetJunyQuestionResponse.java +++ b/src/main/java/com/ewhatever/qna/user/dto/GetJunyQuestionResponse.java @@ -26,8 +26,12 @@ public class GetJunyQuestionResponse { public static GetJunyQuestionResponse fromPost(Post post, Long answerCount, Boolean isJuicy) { LocalDate targetDate = post.getCreatedDate().toLocalDate().plusDays(3); LocalDateTime date = (isJuicy)? post.getLastModifiedDate() : post.getCreatedDate(); + String title; + if(post.getTitle().length() > 20) + title = post.getTitle().substring(0, 20) + "..."; + else title = post.getTitle(); return GetJunyQuestionResponse.builder() - .title(post.getTitle().substring(0, Math.min(post.getTitle().length(), 20))) + .title(title) .postIdx(post.getPostIdx()) .date(date.format(DateTimeFormatter.ofPattern("yy/MM/dd HH:mm"))) .category(post.getCategory().getKrName()) diff --git a/src/main/java/com/ewhatever/qna/user/dto/GetScrapResponse.java b/src/main/java/com/ewhatever/qna/user/dto/GetScrapResponse.java index b986ad3..a12662f 100644 --- a/src/main/java/com/ewhatever/qna/user/dto/GetScrapResponse.java +++ b/src/main/java/com/ewhatever/qna/user/dto/GetScrapResponse.java @@ -26,10 +26,18 @@ public class GetScrapResponse { //TODO : substring말고 잘라진 부분만 가져오게 수정? public static GetScrapResponse fromScrap(Scrap scrap) { Post post = scrap.getPost(); - return GetScrapResponse.builder().postTitle(post.getTitle().substring(0, Math.min(post.getTitle().length(), 10))) + String title; + if(post.getTitle().length() > 10) title = post.getTitle().substring(0, 10) + "..."; + else title = post.getTitle(); + + String content; + if(post.getContent().length() > 45) content = post.getContent().substring(0, 45) + "..."; + else content = post.getContent(); + + return GetScrapResponse.builder().postTitle(title) .postIdx(post.getPostIdx()) .category(post.getCategory().getKrName()) - .content(post.getContent().substring(0, Math.min(post.getContent().length(), 45))) + .content(content) .commentCount(post.getCommentCount()) .scrapCount(post.getScrapCount()) .date(post.getLastModifiedDate().format(DateTimeFormatter.ofPattern("yy/MM/dd HH:mm"))) diff --git a/src/main/java/com/ewhatever/qna/user/dto/GetSinyAnswerResponse.java b/src/main/java/com/ewhatever/qna/user/dto/GetSinyAnswerResponse.java index a56e4e1..4342727 100644 --- a/src/main/java/com/ewhatever/qna/user/dto/GetSinyAnswerResponse.java +++ b/src/main/java/com/ewhatever/qna/user/dto/GetSinyAnswerResponse.java @@ -29,8 +29,13 @@ public class GetSinyAnswerResponse { public static GetSinyAnswerResponse fromAnswer(Answer answer, Long answerCount, Boolean isJuicy) { LocalDate targetDate = answer.getPost().getCreatedDate().toLocalDate().plusDays(3); LocalDateTime date = (isJuicy)? answer.getPost().getLastModifiedDate() : answer.getPost().getCreatedDate(); + + String content; + if(answer.getContent().length() > 20) content = answer.getContent().substring(0, 20) + "..."; + else content = answer.getContent(); + return GetSinyAnswerResponse.builder() - .content(answer.getContent().substring(0, Math.min(20, answer.getContent().length()))) + .content(content) .date(date.format(DateTimeFormatter.ofPattern("yy/MM/dd HH:mm"))) .category(answer.getPost().getCategory().getKrName()) .postIdx(answer.getPost().getPostIdx())