From a2a967fb932f8f0e564e43ff2dc4f5018d5e1808 Mon Sep 17 00:00:00 2001 From: limehee Date: Mon, 6 May 2024 14:46:59 +0900 Subject: [PATCH] =?UTF-8?q?refactor(Board):=20=EA=B2=8C=EC=8B=9C=EA=B8=80?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=EC=97=90=EC=84=9C=20=EC=9A=B4=EC=98=81?= =?UTF-8?q?=EC=A7=84=EC=9D=B4=20=EC=9E=91=EC=84=B1=ED=95=9C=20=EA=B3=B5?= =?UTF-8?q?=EC=A7=80=EC=82=AC=ED=95=AD=20=EA=B2=8C=EC=8B=9C=EA=B8=80?= =?UTF-8?q?=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EC=9A=B4=EC=98=81=EC=A7=84?= =?UTF-8?q?=EC=9E=84=EC=9D=84=20=ED=91=9C=EC=8B=9C=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/BoardCategoryResponseDto.java | 5 +- .../dto/response/BoardDetailsResponseDto.java | 9 ++-- .../dto/response/BoardListResponseDto.java | 6 +-- .../domain/board/dto/response/WriterInfo.java | 48 +++++++++++++++++++ 4 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 src/main/java/page/clab/api/domain/board/dto/response/WriterInfo.java diff --git a/src/main/java/page/clab/api/domain/board/dto/response/BoardCategoryResponseDto.java b/src/main/java/page/clab/api/domain/board/dto/response/BoardCategoryResponseDto.java index a040476f4..20290fe66 100644 --- a/src/main/java/page/clab/api/domain/board/dto/response/BoardCategoryResponseDto.java +++ b/src/main/java/page/clab/api/domain/board/dto/response/BoardCategoryResponseDto.java @@ -26,11 +26,12 @@ public class BoardCategoryResponseDto { private LocalDateTime createdAt; public static BoardCategoryResponseDto toDto(Board board) { + WriterInfo writerInfo = WriterInfo.fromBoard(board); return BoardCategoryResponseDto.builder() .id(board.getId()) .category(board.getCategory().getKey()) - .writerId(board.isWantAnonymous() ? null : board.getMember().getId()) - .writerName(board.isWantAnonymous() ? board.getNickname() : board.getMember().getName()) + .writerId(writerInfo.getId()) + .writerName(writerInfo.getName()) .title(board.getTitle()) .imageUrl(board.getImageUrl()) .createdAt(board.getCreatedAt()) diff --git a/src/main/java/page/clab/api/domain/board/dto/response/BoardDetailsResponseDto.java b/src/main/java/page/clab/api/domain/board/dto/response/BoardDetailsResponseDto.java index 002dc86c9..71fb5fd4c 100644 --- a/src/main/java/page/clab/api/domain/board/dto/response/BoardDetailsResponseDto.java +++ b/src/main/java/page/clab/api/domain/board/dto/response/BoardDetailsResponseDto.java @@ -41,12 +41,13 @@ public class BoardDetailsResponseDto { private LocalDateTime createdAt; public static BoardDetailsResponseDto toDto(Board board, boolean hasLikeByMe, boolean isOwner) { + WriterInfo writerInfo = WriterInfo.fromBoardDetails(board); return BoardDetailsResponseDto.builder() .id(board.getId()) - .writerId(board.isWantAnonymous() ? null : board.getMember().getId()) - .writerName(board.isWantAnonymous() ? board.getNickname() : board.getMember().getName()) - .writerRoleLevel(board.isWantAnonymous() ? null : board.getMember().getRole().toRoleLevel()) - .writerImageUrl(board.isWantAnonymous() ? null : board.getMember().getImageUrl()) + .writerId(writerInfo.getId()) + .writerName(writerInfo.getName()) + .writerRoleLevel(writerInfo.getRoleLevel()) + .writerImageUrl(writerInfo.getImageUrl()) .title(board.getTitle()) .content(board.getContent()) .files(UploadedFileResponseDto.toDto(board.getUploadedFiles())) diff --git a/src/main/java/page/clab/api/domain/board/dto/response/BoardListResponseDto.java b/src/main/java/page/clab/api/domain/board/dto/response/BoardListResponseDto.java index 820f24cc0..eef2f6165 100644 --- a/src/main/java/page/clab/api/domain/board/dto/response/BoardListResponseDto.java +++ b/src/main/java/page/clab/api/domain/board/dto/response/BoardListResponseDto.java @@ -3,7 +3,6 @@ import lombok.Builder; import lombok.Getter; import page.clab.api.domain.board.domain.Board; -import page.clab.api.domain.board.domain.BoardCategory; import java.time.LocalDateTime; @@ -30,10 +29,11 @@ public class BoardListResponseDto { private LocalDateTime createdAt; public static BoardListResponseDto toDto(Board board, Long commentCount) { + WriterInfo writerInfo = WriterInfo.fromBoard(board); return BoardListResponseDto.builder() .id(board.getId()) - .writerId(board.isWantAnonymous() ? null : board.getMember().getId()) - .writerName(board.isWantAnonymous() ? board.getNickname() : board.getMember().getName()) + .writerId(writerInfo.getId()) + .writerName(writerInfo.getName()) .category(board.getCategory().getKey()) .title(board.getTitle()) .content(board.getContent()) diff --git a/src/main/java/page/clab/api/domain/board/dto/response/WriterInfo.java b/src/main/java/page/clab/api/domain/board/dto/response/WriterInfo.java new file mode 100644 index 000000000..9ce553141 --- /dev/null +++ b/src/main/java/page/clab/api/domain/board/dto/response/WriterInfo.java @@ -0,0 +1,48 @@ +package page.clab.api.domain.board.dto.response; + +import lombok.Getter; +import page.clab.api.domain.board.domain.Board; +import page.clab.api.domain.member.domain.Role; + +@Getter +public class WriterInfo { + + private String id; + + private String name; + + private Long roleLevel; + + private String imageUrl; + + public WriterInfo(String id, String name) { + this.id = id; + this.name = name; + } + + public WriterInfo(String id, String name, Long roleLevel, String imageUrl) { + this.id = id; + this.name = name; + this.roleLevel = roleLevel; + this.imageUrl = imageUrl; + } + + public static WriterInfo fromBoard(Board board) { + if (board.getMember().isAdminRole() && board.isNotice()) { + return new WriterInfo(null, "운영진"); + } else if (board.isWantAnonymous()) { + return new WriterInfo(null, board.getNickname()); + } + return new WriterInfo(board.getMember().getId(), board.getMember().getName()); + } + + public static WriterInfo fromBoardDetails(Board board) { + if (board.getMember().isAdminRole() && board.isNotice()) { + return new WriterInfo(null, "운영진", Role.ADMIN.toRoleLevel(), null); + } else if (board.isWantAnonymous()) { + return new WriterInfo(null, board.getNickname(), null, null); + } + return new WriterInfo(board.getMember().getId(), board.getMember().getName(), board.getMember().getRole().toRoleLevel(), board.getMember().getImageUrl()); + } + +}