Skip to content

Commit f1506c4

Browse files
authored
Merge pull request #23 from DMU-DebugVisual/feat/limit-comment-depth
feat: 대댓글 중첩 기능 제한 (#22)
2 parents 93887df + ce1c379 commit f1506c4

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

src/main/java/com/dmu/debug_visual/community/entity/Comment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class Comment {
2626
@ManyToOne
2727
private Comment parent; // 대댓글일 경우 상위 댓글
2828

29+
@Builder.Default
2930
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
3031
private List<Comment> children = new ArrayList<>();
3132

src/main/java/com/dmu/debug_visual/community/entity/Post.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ public class Post {
2727
@Column(name = "tag")
2828
private List<PostTag> tags;
2929

30-
31-
// private String imageUrl;
32-
3330
@ManyToOne
3431
private User writer;
3532

src/main/java/com/dmu/debug_visual/community/service/CommentService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public Long createComment(CommentRequestDTO dto, User user) {
3434
if (dto.getParentId() != null && dto.getParentId() != 0) {
3535
parent = commentRepository.findById(dto.getParentId())
3636
.orElseThrow(() -> new RuntimeException("상위 댓글 없음"));
37+
38+
// 대댓글의 부모가 null이 아니면(즉, 대댓글에 대댓글을 다는 경우) 에러 발생
39+
if (parent.getParent() != null) {
40+
throw new IllegalArgumentException("대댓글에는 답글을 달 수 없습니다.");
41+
}
42+
3743
builder.parent(parent);
3844

3945
if (!user.getUserNum().equals(parent.getWriter().getUserNum())) {

src/main/java/com/dmu/debug_visual/community/service/PostService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public Long createPost(PostRequestDTO dto, User user) {
2727
.title(dto.getTitle())
2828
.content(dto.getContent())
2929
.tags(dto.getTags())
30-
// .imageUrl(dto.getImageUrl())
3130
.writer(user)
3231
.build();
3332

@@ -62,7 +61,6 @@ public PostResponseDTO getPost(Long id) {
6261
.content(post.getContent())
6362
.writer(post.getWriter().getName()) // 수정
6463
.tags(post.getTags())
65-
// .imageUrl(post.getImageUrl())
6664
.createdAt(post.getCreatedAt())
6765
.likeCount(likeRepository.countByPost(post))
6866
.build();

src/main/resources/application.properties

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ spring.profiles.active=dev
66

77

88
# MySQL - RDS
9-
#spring.datasource.url=jdbc:mysql://debugvisual-rds-mysql.cl2o2mce4l8e.ap-northeast-2.rds.amazonaws.com:3306/DebugVisual_RDS?useSSL=false&serverTimezone=Asia/Seoul
10-
#spring.datasource.username=admin
11-
#spring.datasource.password=debugvi33!
12-
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
9+
spring.datasource.url=jdbc:mysql://zivorp-rds-mysql.cl2o2mce4l8e.ap-northeast-2.rds.amazonaws.com:3306/Zivorp_RDS_MySQL?useSSL=false&serverTimezone=Asia/Seoul
10+
spring.datasource.username=admin
11+
spring.datasource.password=zivorp33!
12+
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
1313

1414
# MySQL - Local
15-
spring.datasource.url=jdbc:mysql://localhost:3306/debugdb?serverTimezone=Asia/Seoul
16-
spring.datasource.username=root
17-
spring.datasource.password=hmjeoung33
18-
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
15+
#spring.datasource.url=jdbc:mysql://localhost:3306/debugdb?serverTimezone=Asia/Seoul
16+
#spring.datasource.username=root
17+
#spring.datasource.password=hmjeoung33
18+
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
1919

2020
# MYSQL - Docker
2121
#spring.datasource.url=${SPRING_DATASOURCE_URL}

0 commit comments

Comments
 (0)