Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

공지사항 게시글에 대한 응답 변경 완료 #339

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}

}
Loading