Skip to content

Commit a65be91

Browse files
authored
Refactor isAdopted, 게시글 좋아요 트랜젝션 추가, Dto - memberId 제거 (#115)
* refactor : LazyInitalizationException Transactional 추가 * refactor : PostCommentController Autowired삭제 후 @requiredargsconstructor로 교체 * refactor : PostComment 채택 시 Post의 isResolve state 병경 * refactor : Dto 에서 memberId 제거 * refactor : Dto 에서 memberId 제거 * refactor : 게시글 좋아요 -> 싫어요 토글 기능 Transactional 추가
1 parent 71144c5 commit a65be91

File tree

7 files changed

+11
-16
lines changed

7 files changed

+11
-16
lines changed

back/src/main/java/com/back/domain/post/comment/controller/PostCommentController.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121

2222
@RestController
2323
@RequestMapping("/post/comment")
24-
24+
@RequiredArgsConstructor
2525
public class PostCommentController {
26-
@Autowired
27-
private Rq rq;
28-
@Autowired
29-
private PostCommentService postCommentService;
26+
27+
private final Rq rq;
28+
private final PostCommentService postCommentService;
3029

3130
@Operation(summary = "댓글 생성")
3231
@PostMapping("/post/{post_id}")

back/src/main/java/com/back/domain/post/comment/dto/CommentCreateRequest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
@Data
77
public class CommentCreateRequest {
8-
private Long postId;
98
private String role;
109
@NotBlank(message = "댓글을 입력해주세요")
1110
private String comment;

back/src/main/java/com/back/domain/post/comment/entity/PostComment.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,5 @@ public void updatePost(Post post) {
6161
public void adoptComment() {
6262
this.isAdopted = true;
6363
}
64-
/*
65-
* Post 단위 테스트 작성
66-
* isAdopted 테스트
67-
* PracticePost 작성 권한 테스트
68-
* API 명세서 수정
69-
* */
7064

7165
}

back/src/main/java/com/back/domain/post/comment/service/PostCommentService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private PostComment getPostCommentById(Long commentId) {
108108
return postCommentRepository.findById(commentId).orElseThrow(() -> new ServiceException("400", "해당 Id의 댓글이 없습니다."));
109109
}
110110

111-
111+
@Transactional
112112
public void adoptComment(Long commentId, Member member) {
113113
PostComment postComment = postCommentRepository.findById(commentId)
114114
.orElseThrow(() -> new ServiceException("400", "해당 Id의 댓글이 없습니다."));
@@ -134,5 +134,7 @@ public void adoptComment(Long commentId, Member member) {
134134
}
135135

136136
postComment.adoptComment();
137+
138+
post.updateResolveStatus(true);
137139
}
138140
}

back/src/main/java/com/back/domain/post/like/entity/PostLike.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import jakarta.persistence.ManyToOne;
1111
import jakarta.persistence.Table;
1212
import jakarta.persistence.UniqueConstraint;
13+
import jakarta.transaction.Transactional;
1314
import lombok.AccessLevel;
1415
import lombok.Builder;
1516
import lombok.Getter;
@@ -60,7 +61,10 @@ public static PostLike create(Member member, Post post, LikeStatus status) {
6061
.build();
6162
}
6263

64+
@Transactional
6365
public void updateStatus(LikeStatus status) {
66+
67+
6468
this.status = status;
6569
}
6670
}

back/src/main/java/com/back/domain/post/post/dto/PostCreateRequest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
@Data
77
public class PostCreateRequest {
8-
private Long memberId;
98
private String postType;
109
@NotBlank(message = "제목은 null 혹은 공백일 수 없습니다.")
1110
private String title;

back/src/main/java/com/back/domain/post/post/service/PostService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,4 @@ public List<PostAllResponse> getAllPostResponse() {
127127
.toList();
128128
}
129129

130-
//채택된 comment 받아오기
131-
132130
}

0 commit comments

Comments
 (0)