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()); + } + +}