From 0fb253f86041d9a504e22526a502fb0bddb7293a Mon Sep 17 00:00:00 2001 From: sonsumin Date: Sun, 24 Nov 2024 05:49:34 +0900 Subject: [PATCH] =?UTF-8?q?[#8]=E2=99=BB=EF=B8=8FRefacotr:=20dateTime=20lo?= =?UTF-8?q?caldate=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/dto/response/BoardInfoResDto.java | 53 ++++++++++++++++++- .../yesummit/domain/board/domain/Board.java | 4 +- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/main/java/univ/yesummit/domain/board/api/dto/response/BoardInfoResDto.java b/src/main/java/univ/yesummit/domain/board/api/dto/response/BoardInfoResDto.java index 00cd818..ce2f8fe 100644 --- a/src/main/java/univ/yesummit/domain/board/api/dto/response/BoardInfoResDto.java +++ b/src/main/java/univ/yesummit/domain/board/api/dto/response/BoardInfoResDto.java @@ -6,6 +6,7 @@ import univ.yesummit.domain.comment.api.dto.response.CommentInfoResDto; import univ.yesummit.domain.member.entity.Member; +import java.time.format.DateTimeFormatter; import java.util.List; @Builder @@ -24,14 +25,19 @@ public record BoardInfoResDto( int InvestmentCount, boolean invest, int commentCount, - String date, + String date, // 포맷팅된 날짜 필드 List comments ) { public static BoardInfoResDto of(Member member, Board board, boolean isLike) { + // 이미지 URL 변환 List imageUrl = board.getPictures().stream() .map(BoardPicture::getImageUrl) .toList(); + // 날짜 포맷 설정 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + String formattedDate = board.getBoardDate().format(formatter); + return BoardInfoResDto.builder() .myMemberId(member.getId()) .writerMemberId(board.getWriter().getId()) @@ -43,8 +49,51 @@ public static BoardInfoResDto of(Member member, Board board, boolean isLike) { .serviceUrl(builder().serviceUrl) .PTUrl(builder().PTUrl) .likeCount(board.getLikeCount()) + .isLike(isLike) .commentCount(board.getComments().size()) - .date(board.getBoardDate()) + .date(formattedDate) // 포맷팅된 날짜 전달 .build(); } } + +// +//@Builder +//public record BoardInfoResDto( +// Long myMemberId, +// Long writerMemberId, +// String writerMemberName, +// Long boardId, +// String title, +// String content, +// List imageUrl, +// String serviceUrl, +// String PTUrl, +// int likeCount, +// boolean isLike, +// int InvestmentCount, +// boolean invest, +// int commentCount, +// String date, +// List comments +//) { +// public static BoardInfoResDto of(Member member, Board board, boolean isLike) { +// List imageUrl = board.getPictures().stream() +// .map(BoardPicture::getImageUrl) +// .toList(); +// +// return BoardInfoResDto.builder() +// .myMemberId(member.getId()) +// .writerMemberId(board.getWriter().getId()) +// .writerMemberName(board.getWriter().getUsername()) +// .boardId(board.getBoardId()) +// .title(board.getTitle()) +// .content(board.getContent()) +// .imageUrl(imageUrl) +// .serviceUrl(builder().serviceUrl) +// .PTUrl(builder().PTUrl) +// .likeCount(board.getLikeCount()) +// .commentCount(board.getComments().size()) +// .date(board.getBoardDate()) +// .build(); +// } +//} diff --git a/src/main/java/univ/yesummit/domain/board/domain/Board.java b/src/main/java/univ/yesummit/domain/board/domain/Board.java index ed3dfca..4b78bbc 100644 --- a/src/main/java/univ/yesummit/domain/board/domain/Board.java +++ b/src/main/java/univ/yesummit/domain/board/domain/Board.java @@ -49,7 +49,7 @@ public class Board { private Long summitId; @Schema(description = "게시글 날짜", example = "2024.06.21") - private String boardDate; + private LocalDateTime boardDate; @Schema(description = "좋아요 개수", example = "1") private int likeCount; @@ -76,7 +76,7 @@ private Board(String title, String content, String serviceUrl, String PTUrl, Mem this.pictures = pictures; this.serviceUrl = serviceUrl; this.PTUrl = PTUrl; - this.boardDate = String.valueOf(LocalDateTime.now(ZoneId.of("Asia/Seoul"))); + this.boardDate = LocalDateTime.now(ZoneId.of("Asia/Seoul")); this.likeCount = 0; this.writer = writer; this.summitId = summitId;