Skip to content

Commit

Permalink
refactor(Board): 게시글 조회에서 운영진이 작성한 공지사항 게시글일 경우 운영진임을 표시하도록 설정 (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
limehee authored May 6, 2024
1 parent 224926e commit 5d1d467
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

}

0 comments on commit 5d1d467

Please sign in to comment.