Skip to content

Commit cc1a669

Browse files
authored
feat: 생성자 패턴 수정 (#126)
* feat: 게시글 추천,추천삭제 API 추가 & 게시글 조회 시 로그인 사용자 추천 여부 응답값 추가 * chore: TODO 완료 작업 주석 삭제 * chore: JsonProperty 추가 * chore: BoardType 프론트와 협의한 Enum으로 수정 * feat: 생성일시, 수정일시를 BaseTime을 상속하도록 수정 * feat: 에러 코드 수정 * chore: 생성자 패턴 수정 * chore: ddl-auto none으로 변경
1 parent f207538 commit cc1a669

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

src/main/java/org/myteam/server/board/domain/Board.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.myteam.server.board.domain;
22

33
import jakarta.persistence.CascadeType;
4-
import jakarta.persistence.Column;
54
import jakarta.persistence.Entity;
65
import jakarta.persistence.EnumType;
76
import jakarta.persistence.Enumerated;
@@ -35,11 +34,9 @@ public class Board extends BaseTime {
3534
@JoinColumn(name = "public_id")
3635
private Member member;
3736

38-
@Column(name = "board_type")
3937
@Enumerated(EnumType.STRING)
4038
private BoardType boardType;
4139

42-
@Column(name = "category_type")
4340
@Enumerated(EnumType.STRING)
4441
private CategoryType categoryType;
4542

@@ -49,7 +46,6 @@ public class Board extends BaseTime {
4946

5047
private String link;
5148

52-
@Column(name = "created_ip")
5349
private String createdIp;
5450

5551
private String thumbnail;

src/main/java/org/myteam/server/board/domain/BoardCount.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public class BoardCount {
2929
@JoinColumn(name = "board_id")
3030
private Board board;
3131

32-
@Column(name = "recommend_count", nullable = false)
32+
@Column(nullable = false)
3333
private int recommendCount;
3434

35-
@Column(name = "view_count", nullable = false)
35+
@Column(nullable = false)
3636
private int viewCount;
3737

38-
@Column(name = "comment_count", nullable = false)
38+
@Column(nullable = false)
3939
private int commentCount;
4040

4141
@Builder

src/main/java/org/myteam/server/board/dto/reponse/BoardResponse.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import java.time.LocalDateTime;
55
import java.util.UUID;
6+
import lombok.Builder;
67
import lombok.Getter;
78
import lombok.Setter;
89
import org.myteam.server.board.domain.Board;
@@ -79,6 +80,7 @@ public class BoardResponse {
7980
*/
8081
private LocalDateTime lastModifiedDate;
8182

83+
@Builder
8284
public BoardResponse(Board board, BoardCount boardCount, boolean isRecommended) {
8385
this.boardType = board.getBoardType();
8486
this.categoryType = board.getCategoryType();
@@ -97,4 +99,12 @@ public BoardResponse(Board board, BoardCount boardCount, boolean isRecommended)
9799
this.createDate = board.getCreateDate();
98100
this.lastModifiedDate = board.getLastModifiedDate();
99101
}
102+
103+
public static BoardResponse createResponse(Board board, BoardCount boardCount, boolean isRecommended) {
104+
return BoardResponse.builder()
105+
.board(board)
106+
.boardCount(boardCount)
107+
.isRecommended(isRecommended)
108+
.build();
109+
}
100110
}

src/main/java/org/myteam/server/board/service/BoardService.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ public BoardResponse saveBoard(final BoardSaveRequest request, final String clie
5252

5353
boolean isRecommended = boardRecommendReadService.isRecommended(board.getId(), loginUser);
5454

55-
BoardResponse response = new BoardResponse(board, boardCount, isRecommended);
56-
5755
log.info("게시판 생성: {}", loginUser);
58-
return response;
56+
return BoardResponse.createResponse(board, boardCount, isRecommended);
5957
}
6058

6159
/**
@@ -95,7 +93,7 @@ public BoardResponse getBoard(final Long boardId) {
9593

9694
boolean isRecommended = boardRecommendReadService.isRecommended(board.getId(), loginUser);
9795

98-
return new BoardResponse(board, boardCount, isRecommended);
96+
return BoardResponse.createResponse(board, boardCount, isRecommended);
9997
}
10098

10199
/**
@@ -135,7 +133,7 @@ public BoardResponse updateBoard(final BoardSaveRequest request, final Long boar
135133
BoardCount boardCount = boardCountReadService.findByBoardId(board.getId());
136134

137135
boolean isRecommended = boardRecommendReadService.isRecommended(board.getId(), loginUser);
138-
return new BoardResponse(board, boardCount, isRecommended);
136+
return BoardResponse.createResponse(board, boardCount, isRecommended);
139137
}
140138

141139
/**

src/main/resources/application-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spring:
1414
use_sql_comments: false
1515
default_batch_fetch_size: 1000 #최적화 옵션
1616
hibernate:
17-
ddl-auto: create-drop
17+
ddl-auto: none
1818
# create 기존테이블을 삭제하고 다시 생성
1919
# create-drop 기존테이블을 삭제하고 다시생성. 종료 시점에 테이블삭제
2020
# update 변경된 스키마 적용 (운영 DB 에서 사용X)

0 commit comments

Comments
 (0)