Skip to content

Commit

Permalink
feat: CommentGet 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
KEEKE132 committed May 26, 2024
1 parent d6a8954 commit 77cdc9d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import se.issuetrackingsystem.comment.dto.CommentRequest;
import se.issuetrackingsystem.comment.dto.CommentResponse;
import se.issuetrackingsystem.comment.service.CommentService;
import se.issuetrackingsystem.comment.domain.Comment;
import se.issuetrackingsystem.issue.domain.Issue;
import se.issuetrackingsystem.issue.dto.IssueResponse;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RequestMapping("api/v1/comments")
Expand All @@ -29,4 +36,14 @@ public void commentDelete(@RequestParam("commentId") Long commentid){
public void commentModify(@RequestParam("commentId") Long commentid, @RequestBody CommentRequest commentRequest){
this.commentService.modify(commentid,commentRequest.getMessage());
}

@GetMapping
public ResponseEntity<List<CommentResponse>> commentListGet(@RequestParam("issueId")Long issueid){
List<Comment> comments = this.commentService.getList(issueid);
List<CommentResponse> responses = new ArrayList<>();
for(Comment i : comments){
responses.add(new CommentResponse(i));
}
return ResponseEntity.ok(responses);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package se.issuetrackingsystem.comment.dto;

import lombok.Getter;
import lombok.Setter;
import se.issuetrackingsystem.comment.domain.Comment;
import se.issuetrackingsystem.user.domain.User;

import java.time.LocalDateTime;

@Getter
@Setter
public class CommentResponse {
private Long id;

private String message;

private LocalDateTime created_at;

private Long authorid;

public CommentResponse(Comment comment){
this.id= comment.getId();
this.message=comment.getMessage();
if(comment.getAuthor()!=null){
this.authorid= comment.getAuthor().getId();
}
this.created_at=comment.getCreated_at();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void delete(Long commentid){
}

public List<Comment> getList(Long issueid){
Issue issue = this.issueRepository.findById(issueid).get();
Issue issue = this.issueRepository.findById(issueid).orElseThrow(()->new CustomException(ErrorCode.ISSUE_NOT_FOUND));
List<Comment> comments = this.commentRepository.findAllByIssue(issue);
return comments;
}
Expand Down

0 comments on commit 77cdc9d

Please sign in to comment.