Skip to content

Commit

Permalink
[#8]♻️Refacotr: dateTime localdate로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
sumin220 committed Nov 23, 2024
1 parent 553d43b commit 0fb253f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,14 +25,19 @@ public record BoardInfoResDto(
int InvestmentCount,
boolean invest,
int commentCount,
String date,
String date, // 포맷팅된 날짜 필드
List<CommentInfoResDto> comments
) {
public static BoardInfoResDto of(Member member, Board board, boolean isLike) {
// 이미지 URL 변환
List<String> 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())
Expand All @@ -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<String> imageUrl,
// String serviceUrl,
// String PTUrl,
// int likeCount,
// boolean isLike,
// int InvestmentCount,
// boolean invest,
// int commentCount,
// String date,
// List<CommentInfoResDto> comments
//) {
// public static BoardInfoResDto of(Member member, Board board, boolean isLike) {
// List<String> 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();
// }
//}
4 changes: 2 additions & 2 deletions src/main/java/univ/yesummit/domain/board/domain/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 0fb253f

Please sign in to comment.