From 3dd76c8795975a27953e43f3544cad81586ace10 Mon Sep 17 00:00:00 2001 From: Haeun-Y Date: Fri, 22 Sep 2023 11:27:48 +0900 Subject: [PATCH] =?UTF-8?q?#4=20fix:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20API=20=EC=88=98?= =?UTF-8?q?=EC=A0=95-=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=ED=95=9C?= =?UTF-8?q?=EA=B8=80=20=EB=B0=98=ED=99=98=20=EB=B0=8F=20=EB=82=A0=EC=A7=9C?= =?UTF-8?q?=20=ED=8F=AC=EB=A7=B7=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ewhatever/qna/common/enums/Category.java | 16 +++++++++++++++- .../ewhatever/qna/post/service/PostService.java | 6 +++--- .../qna/question/service/QuestionService.java | 4 ++-- .../qna/user/dto/GetCommentResponse.java | 5 +++-- .../qna/user/dto/GetJunyQuestionResponse.java | 9 +++++---- .../ewhatever/qna/user/dto/GetScrapResponse.java | 10 ++++++---- .../qna/user/dto/GetSinyAnswerResponse.java | 11 +++++++---- 7 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/ewhatever/qna/common/enums/Category.java b/src/main/java/com/ewhatever/qna/common/enums/Category.java index 7d091f5..673c31b 100644 --- a/src/main/java/com/ewhatever/qna/common/enums/Category.java +++ b/src/main/java/com/ewhatever/qna/common/enums/Category.java @@ -1,6 +1,20 @@ package com.ewhatever.qna.common.enums; public enum Category { - DAILY, RELATIONSHIP, SOCIAL, ETC + DAILY("일상"), + RELATIONSHIP("인간관계"), + SOCIAL("사회생활"), + ETC("기타"); + + private String krName; + + Category(String krName) { + this.krName = krName; + } + + public String getKrName() { + return krName; + } + } diff --git a/src/main/java/com/ewhatever/qna/post/service/PostService.java b/src/main/java/com/ewhatever/qna/post/service/PostService.java index 95fba46..1269195 100644 --- a/src/main/java/com/ewhatever/qna/post/service/PostService.java +++ b/src/main/java/com/ewhatever/qna/post/service/PostService.java @@ -93,7 +93,7 @@ public Page getPostsByCategory(String category, Pageable page) thro if (postExists) { Page postPage = postRepository.findAllByCategoryAndIsJuicyTrueOrderByLastModifiedDateDesc(categoryName, page); // 최신순 조회 return postPage.map(post -> new GetPostsRes( - post.getCategory().toString(), + post.getCategory().getKrName(), post.getLastModifiedDate(), post.getScrapCount(), post.getCommentCount(), @@ -122,7 +122,7 @@ public Page getPostsBySearchWord(String searchWord, Pageable page) if (searchResultExists) { return postRepository.searchJuicyPosts(searchWord, page) .map(searchPost -> new GetPostsRes( - searchPost.getCategory().toString(), + searchPost.getCategory().getKrName(), searchPost.getLastModifiedDate(), searchPost.getScrapCount(), searchPost.getCommentCount(), @@ -147,7 +147,7 @@ public GetPostRes getPost(String token, Long postIdx) throws BaseException { Post post = postRepository.findById(postIdx).orElseThrow(() -> new BaseException(INVALID_POST_IDX)); User user = userRepository.findByUserIdxAndStatusEquals(authService.getUserIdx(token), ACTIVE).orElseThrow(() -> new BaseException(INVALID_USER)); return new GetPostRes( - post.getCategory().toString(), + post.getCategory().getKrName(), getCardList(post), post.getLastModifiedDate(), post.getCommentCount(), diff --git a/src/main/java/com/ewhatever/qna/question/service/QuestionService.java b/src/main/java/com/ewhatever/qna/question/service/QuestionService.java index 39de638..b0a33f5 100644 --- a/src/main/java/com/ewhatever/qna/question/service/QuestionService.java +++ b/src/main/java/com/ewhatever/qna/question/service/QuestionService.java @@ -68,7 +68,7 @@ public Page getQuestions(Pageable page) throws BaseException { try { Page postPage = postRepository.findAllByIsJuicyFalseOrderByCreatedDateDesc(page); // 최신순 조회 return postPage.map(post -> new GetQuestionsRes( - post.getCategory().toString(), + post.getCategory().getKrName(), post.getTitle(), post.getContent(), post.getCreatedDate() @@ -92,7 +92,7 @@ public Page getQuestionsByCategory(String category, Pageable pa if (questionExists) { Page postPage = postRepository.findAllByCategoryAndIsJuicyFalseOrderByCreatedDateDesc(categoryName, page); // 최신순 조회 return postPage.map(post -> new GetQuestionsRes( - post.getCategory().toString(), + post.getCategory().getKrName(), post.getTitle(), post.getContent(), post.getCreatedDate() 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 7b4d74d..69a8622 100644 --- a/src/main/java/com/ewhatever/qna/user/dto/GetCommentResponse.java +++ b/src/main/java/com/ewhatever/qna/user/dto/GetCommentResponse.java @@ -7,13 +7,14 @@ import lombok.Setter; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; @Builder @Getter @Setter public class GetCommentResponse { private String content; - private LocalDate createdDate; + private String date; private Long postIdx; private String postTitle; @@ -22,7 +23,7 @@ public class GetCommentResponse { public static GetCommentResponse fromComment(Comment comment) { Post post = comment.getPost(); return GetCommentResponse.builder().content(comment.getContent().substring(0, Math.min(comment.getContent().length(), 20))) - .createdDate(comment.getCreatedDate().toLocalDate())//TODO : 날짜 포맷 수정 -> 시간 필요 + .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(); } 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 392dc21..3268f5d 100644 --- a/src/main/java/com/ewhatever/qna/user/dto/GetJunyQuestionResponse.java +++ b/src/main/java/com/ewhatever/qna/user/dto/GetJunyQuestionResponse.java @@ -8,6 +8,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import static java.time.temporal.ChronoUnit.DAYS; @@ -16,8 +17,8 @@ @Setter public class GetJunyQuestionResponse { private String title; - private LocalDateTime date; - private Category category; + private String date; + private String category; private Long answerCount; private Long daysUntilDday; @@ -26,8 +27,8 @@ public static GetJunyQuestionResponse fromPost(Post post, Long answerCount, Bool LocalDateTime date = (isJuicy)? post.getLastModifiedDate() : post.getCreatedDate(); return GetJunyQuestionResponse.builder() .title(post.getTitle().substring(0, Math.min(post.getTitle().length(), 20))) - .date(date)//TODO : 날짜 포맷 수정 - .category(post.getCategory()) + .date(date.format(DateTimeFormatter.ofPattern("yy/MM/dd HH:mm"))) + .category(post.getCategory().getKrName()) .answerCount(answerCount) .daysUntilDday(LocalDate.now().until(targetDate, DAYS)).build(); } 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 8faa251..b986ad3 100644 --- a/src/main/java/com/ewhatever/qna/user/dto/GetScrapResponse.java +++ b/src/main/java/com/ewhatever/qna/user/dto/GetScrapResponse.java @@ -8,6 +8,7 @@ import lombok.Setter; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; @Builder @Setter @@ -15,11 +16,11 @@ public class GetScrapResponse { private String postTitle; private Long postIdx; - private Category category; + private String category; private String content; private Long commentCount; private Long scrapCount; - private LocalDateTime createdDate;//쥬시글 등록 날짜 + private String date;//쥬시글 등록 날짜 //TODO : 해당 필드명 수정하기?? //TODO : substring말고 잘라진 부분만 가져오게 수정? @@ -27,10 +28,11 @@ public static GetScrapResponse fromScrap(Scrap scrap) { Post post = scrap.getPost(); return GetScrapResponse.builder().postTitle(post.getTitle().substring(0, Math.min(post.getTitle().length(), 10))) .postIdx(post.getPostIdx()) - .category(post.getCategory()) + .category(post.getCategory().getKrName()) .content(post.getContent().substring(0, Math.min(post.getContent().length(), 45))) .commentCount(post.getCommentCount()) .scrapCount(post.getScrapCount()) - .createdDate(post.getLastModifiedDate()).build();//TODO : 날짜 포맷 수정 + .date(post.getLastModifiedDate().format(DateTimeFormatter.ofPattern("yy/MM/dd HH:mm"))) + .build(); } } 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 152284b..d548376 100644 --- a/src/main/java/com/ewhatever/qna/user/dto/GetSinyAnswerResponse.java +++ b/src/main/java/com/ewhatever/qna/user/dto/GetSinyAnswerResponse.java @@ -2,12 +2,15 @@ import com.ewhatever.qna.answer.entity.Answer; import com.ewhatever.qna.common.enums.Category; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Builder; import lombok.Getter; import lombok.Setter; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import static java.time.temporal.ChronoUnit.DAYS; @@ -16,8 +19,8 @@ @Getter public class GetSinyAnswerResponse { private String content; - private LocalDateTime date; - private Category category; + private String date; + private String category; private Long answerCount; private Long daysUntilDday; @@ -26,8 +29,8 @@ public static GetSinyAnswerResponse fromAnswer(Answer answer, Long answerCount, LocalDateTime date = (isJuicy)? answer.getPost().getLastModifiedDate() : answer.getPost().getCreatedDate(); return GetSinyAnswerResponse.builder() .content(answer.getContent().substring(0, Math.min(20, answer.getContent().length()))) - .date(date)//TODO : 날짜 포맷 수정 - .category(answer.getPost().getCategory()) + .date(date.format(DateTimeFormatter.ofPattern("yy/MM/dd HH:mm"))) + .category(answer.getPost().getCategory().getKrName()) .answerCount(answerCount) .daysUntilDday(LocalDate.now().until(targetDate, DAYS)).build(); }