forked from codesquad-members-2023/issue-tracker-max
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] 댓글 목록 조회 #82
Merged
Merged
[BE] 댓글 목록 조회 #82
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,20 @@ | |
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import kr.codesquad.issuetracker.application.CommentService; | ||
import kr.codesquad.issuetracker.presentation.auth.AuthPrincipal; | ||
import kr.codesquad.issuetracker.presentation.request.CommentRequest; | ||
import kr.codesquad.issuetracker.presentation.response.CommentsResponse; | ||
import kr.codesquad.issuetracker.presentation.response.Slice; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequestMapping("/api/issues/{issueId}/comments") | ||
|
@@ -36,4 +40,10 @@ public ResponseEntity<Void> modify(@RequestBody CommentRequest request, @PathVar | |
commentService.modify(request.getContent(), commentId, userId); | ||
return ResponseEntity.status(HttpStatus.OK).build(); | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<Slice<CommentsResponse>> commentList(@PathVariable Integer issueId, | ||
@RequestParam Integer cursor) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 개인적으로는 slice size를 SQL에서 고정하지않고 RequestParam으로(default 10) 줘도 좋을 것 같습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 좋은 방법이네용 |
||
return ResponseEntity.status(HttpStatus.OK).body(commentService.getComments(issueId, cursor)); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
backend/src/main/java/kr/codesquad/issuetracker/presentation/response/CommentsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package kr.codesquad.issuetracker.presentation.response; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class CommentsResponse { | ||
|
||
private Integer id; | ||
private String username; | ||
private String profileUrl; | ||
private String content; | ||
private LocalDateTime createdAt; | ||
} |
17 changes: 17 additions & 0 deletions
17
backend/src/main/java/kr/codesquad/issuetracker/presentation/response/Slice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package kr.codesquad.issuetracker.presentation.response; | ||
|
||
import java.util.List; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Slice<T> { | ||
|
||
private List<T> data; | ||
private Boolean hasMore; | ||
private Integer nextCursor; | ||
} |
66 changes: 66 additions & 0 deletions
66
backend/src/test/java/kr/codesquad/issuetracker/application/CommentServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package kr.codesquad.issuetracker.application; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import kr.codesquad.issuetracker.ApplicationTest; | ||
import kr.codesquad.issuetracker.domain.Issue; | ||
import kr.codesquad.issuetracker.domain.UserAccount; | ||
import kr.codesquad.issuetracker.infrastructure.persistence.IssueRepository; | ||
import kr.codesquad.issuetracker.infrastructure.persistence.UserAccountRepository; | ||
import kr.codesquad.issuetracker.presentation.response.CommentsResponse; | ||
import kr.codesquad.issuetracker.presentation.response.Slice; | ||
|
||
@ApplicationTest | ||
class CommentServiceTest { | ||
|
||
@Autowired | ||
private CommentService commentService; | ||
@Autowired | ||
private IssueRepository issueRepository; | ||
@Autowired | ||
private UserAccountRepository accountRepository; | ||
|
||
@DisplayName("댓글 목록 조회에 성공한다.") | ||
@Test | ||
void getCommentsTest() { | ||
// given | ||
accountRepository.save(new UserAccount("pieeee", "123123")); | ||
issueRepository.save(new Issue("제목", "내용", true, 1, null)); | ||
for (int i = 0; i < 15; i++) { | ||
commentService.register(1, "댓글", 1); | ||
} | ||
|
||
// when | ||
Slice<CommentsResponse> comments = commentService.getComments(1, 0); | ||
|
||
// then | ||
assertAll( | ||
() -> assertThat(comments.getHasMore()).isTrue(), | ||
() -> assertThat(comments.getNextCursor()).isEqualTo(10), | ||
() -> assertThat(comments.getData().size()).isEqualTo(10) | ||
); | ||
} | ||
|
||
@DisplayName("해당 이슈에 아무 댓글이 없을 시 빈 리스트를 반환한다.") | ||
@Test | ||
void emptyCommentList() { | ||
// given | ||
accountRepository.save(new UserAccount("pieeee", "123123")); | ||
issueRepository.save(new Issue("제목", "내용", true, 1, null)); | ||
|
||
// when | ||
Slice<CommentsResponse> comments = commentService.getComments(1, 0); | ||
|
||
// then | ||
assertAll( | ||
() -> assertThat(comments.getData()).isEmpty(), | ||
() -> assertThat(comments.getHasMore()).isFalse(), | ||
() -> assertThat(comments.getNextCursor()).isEqualTo(0) | ||
); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List의 size가 10 미만이면 hasMore이 false인 것을 알 수 있지 않을까요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10의 배수이면 모를 수도 있을 것 같아요!