Skip to content

Commit db6b06f

Browse files
authored
Merge pull request #231 from prgrms-web-devcourse-final-project/feature/EA3-138-recruitment-post-implement
[EA3-138] Refactor: 모집글 댓글 작성 URL 변경
2 parents 5c6dea5 + 87c7e40 commit db6b06f

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

src/main/java/grep/neogulcoder/domain/recruitment/comment/controller/RecruitmentPostCommentController.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,30 @@
1010
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1111
import org.springframework.web.bind.annotation.*;
1212

13-
@RequestMapping("/recruitment-posts/comments")
13+
@RequestMapping("/recruitment-posts")
1414
@RequiredArgsConstructor
1515
@RestController
1616
public class RecruitmentPostCommentController implements RecruitmentPostCommentSpecification {
1717

1818
private final RecruitmentPostCommentService commentService;
1919

20-
@PostMapping
21-
public ApiResponse<Long> save(@RequestBody @Valid RecruitmentCommentSaveRequest request,
20+
@PostMapping("/{post-id}/comments")
21+
public ApiResponse<Long> save(@PathVariable("post-id") long postId,
22+
@RequestBody @Valid RecruitmentCommentSaveRequest request,
2223
@AuthenticationPrincipal Principal userDetails) {
23-
long commentId = commentService.save(request, userDetails.getUserId());
24+
long commentId = commentService.save(postId, request, userDetails.getUserId());
2425
return ApiResponse.success(commentId);
2526
}
2627

27-
@PutMapping("/{comment-id}")
28+
@PutMapping("/comments/{comment-id}")
2829
public ApiResponse<Void> update(@PathVariable("comment-id") long commentId,
2930
@RequestBody RecruitmentCommentUpdateRequest request,
3031
@AuthenticationPrincipal Principal userDetails) {
3132
commentService.update(request, commentId, userDetails.getUserId());
3233
return ApiResponse.noContent();
3334
}
3435

35-
@DeleteMapping("/{comment-id}")
36+
@DeleteMapping("/comments/{comment-id}")
3637
public ApiResponse<Void> delete(@PathVariable("comment-id") long commentId,
3738
@AuthenticationPrincipal Principal userDetails) {
3839
commentService.delete(commentId, userDetails.getUserId());

src/main/java/grep/neogulcoder/domain/recruitment/comment/controller/RecruitmentPostCommentSpecification.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public interface RecruitmentPostCommentSpecification {
1212

1313
@Operation(summary = "모집글 댓글 작성", description = "모집글에 대한 댓글을 작성 합니다.")
14-
ApiResponse<Long> save(RecruitmentCommentSaveRequest request, Principal userDetails);
14+
ApiResponse<Long> save(long postId, RecruitmentCommentSaveRequest request, Principal userDetails);
1515

1616
@Operation(summary = "모집글 댓글 수정", description = "모집글에 대한 댓글을 수정 합니다.")
1717
ApiResponse<Void> update(long commentId, RecruitmentCommentUpdateRequest request, Principal userDetails);

src/main/java/grep/neogulcoder/domain/recruitment/comment/controller/dto/request/RecruitmentCommentSaveRequest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88
@Getter
99
public class RecruitmentCommentSaveRequest {
1010

11-
@Schema(example = "2", description = "모집글 ID")
12-
private long postId;
13-
1411
@Schema(example = "저도 참여 할래요!", description = "모집글 내용")
1512
private String content;
1613

1714
private RecruitmentCommentSaveRequest() {
1815
}
1916

20-
public RecruitmentPostComment toEntity(RecruitmentPost post, long userId){
17+
public RecruitmentPostComment toEntity(RecruitmentPost post, long userId) {
2118
return RecruitmentPostComment.builder()
2219
.recruitmentPost(post)
2320
.userId(userId)

src/main/java/grep/neogulcoder/domain/recruitment/comment/service/RecruitmentPostCommentService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public class RecruitmentPostCommentService {
2525
private final RecruitmentPostCommentQueryRepository commentQueryRepository;
2626

2727
@Transactional
28-
public long save(RecruitmentCommentSaveRequest request, long userId) {
29-
RecruitmentPost post = postRepository.findPostBy(request.getPostId())
28+
public long save(long postId, RecruitmentCommentSaveRequest request, long userId) {
29+
RecruitmentPost post = postRepository.findPostBy(postId)
3030
.orElseThrow(() -> new NotFoundException(NOT_FOUND));
3131

3232
return commentRepository.save(request.toEntity(post, userId)).getId();

0 commit comments

Comments
 (0)