Skip to content

Commit

Permalink
Merge pull request #181 from woowacourse-teams/Feature/#179-대댓글_조회_AP…
Browse files Browse the repository at this point in the history
…I_구현

feat : 부모 ID로 대댓글 조회하는 API 추가
  • Loading branch information
java-saeng authored Aug 2, 2023
2 parents 72ce26a + 113e601 commit 983494e
Show file tree
Hide file tree
Showing 9 changed files with 2,994 additions and 3,397 deletions.
17 changes: 14 additions & 3 deletions backend/emm-sale/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@ include::{snippets}/delete-event/http-request.adoc[]
.HTTP response
include::{snippets}/delete-event/http-response.adoc[]

.HTTP response 설명
include::{snippets}/delete-event/response-fields.adoc[]

== Comment

=== `GET` : 댓글 모두 조회
Expand All @@ -221,6 +218,20 @@ include::{snippets}/get-comment/http-response.adoc[]
.HTTP response 설명
include::{snippets}/get-comment/response-fields.adoc[]

=== `GET` : 대댓글 모두 조회

.HTTP request 설명
include::{snippets}/get-children-comment/path-parameters.adoc[]

.HTTP request
include::{snippets}/get-children-comment/http-request.adoc[]

.HTTP response
include::{snippets}/get-children-comment/http-response.adoc[]

.HTTP response 설명
include::{snippets}/get-children-comment/response-fields.adoc[]

=== `POST` : 댓글 및 대댓글 생성

.HTTP request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public List<CommentHierarchyResponse> findAll(@RequestParam final Long eventId)
return commentQueryService.findAllCommentsByEventId(eventId);
}

@GetMapping("/comments/{comment-id}/children")
public List<CommentResponse> findChildren(
@PathVariable("comment-id") final Long commentId
) {
return commentQueryService.findChildrenComments(commentId);
}

@DeleteMapping("/comments/{comment-id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void delete(@PathVariable("comment-id") final Long commentId, final Member member) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.emmsale.comment.application;

import com.emmsale.base.BaseEntity;
import com.emmsale.comment.application.dto.CommentHierarchyResponse;
import com.emmsale.comment.application.dto.CommentResponse;
import com.emmsale.comment.domain.Comment;
import com.emmsale.comment.domain.CommentRepository;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -21,4 +25,14 @@ public List<CommentHierarchyResponse> findAllCommentsByEventId(final Long eventI

return CommentHierarchyResponse.from(comments);
}

public List<CommentResponse> findChildrenComments(final Long parentId) {

final List<Comment> childrenComments = commentRepository.findByParentId(parentId);

return childrenComments.stream()
.sorted(Comparator.comparing(BaseEntity::getCreatedAt))
.map(CommentResponse::from)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {

@Query("select c From Comment c inner join Event e on c.event.id = e.id where e.id = :eventId")
List<Comment> findByEventId(@Param("eventId") final Long eventId);

List<Comment> findByParentId(Long parentId);
}
3 changes: 3 additions & 0 deletions backend/emm-sale/src/main/resources/http/comment.http
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Authorization: bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNjkwMTk2OTY5L
GET http://localhost:8080/comments?eventId=1
Content-Type: application/json

### 부모 ID로 대댓글 조회하기
GET http://localhost:8080/comments/1/children

### 댓글 삭제 /comments/{comment-id}

DELETE http://localhost:8080/comments/2
Expand Down
Loading

0 comments on commit 983494e

Please sign in to comment.