Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix/4-getMyPage2] 카테고리 한글 반환 및 날짜 포맷 변경 #33

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/main/java/com/ewhatever/qna/common/enums/Category.java
Original file line number Diff line number Diff line change
@@ -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;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Page<GetPostsRes> getPostsByCategory(String category, Pageable page) thro
if (postExists) {
Page<Post> postPage = postRepository.findAllByCategoryAndIsJuicyTrueOrderByLastModifiedDateDesc(categoryName, page); // 최신순 조회
return postPage.map(post -> new GetPostsRes(
post.getCategory().toString(),
post.getCategory().getKrName(),
post.getLastModifiedDate(),
post.getScrapCount(),
post.getCommentCount(),
Expand Down Expand Up @@ -122,7 +122,7 @@ public Page<GetPostsRes> 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(),
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Page<GetQuestionsRes> getQuestions(Pageable page) throws BaseException {
try {
Page<Post> postPage = postRepository.findAllByIsJuicyFalseOrderByCreatedDateDesc(page); // 최신순 조회
return postPage.map(post -> new GetQuestionsRes(
post.getCategory().toString(),
post.getCategory().getKrName(),
post.getTitle(),
post.getContent(),
post.getCreatedDate()
Expand All @@ -92,7 +92,7 @@ public Page<GetQuestionsRes> getQuestionsByCategory(String category, Pageable pa
if (questionExists) {
Page<Post> postPage = postRepository.findAllByCategoryAndIsJuicyFalseOrderByCreatedDateDesc(categoryName, page); // 최신순 조회
return postPage.map(post -> new GetQuestionsRes(
post.getCategory().toString(),
post.getCategory().getKrName(),
post.getTitle(),
post.getContent(),
post.getCreatedDate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import static java.time.temporal.ChronoUnit.DAYS;

Expand All @@ -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;

Expand All @@ -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();
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/ewhatever/qna/user/dto/GetScrapResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@
import lombok.Setter;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Builder
@Setter
@Getter
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말고 잘라진 부분만 가져오게 수정?
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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();
}
Expand Down