Skip to content

Commit

Permalink
Merge pull request #28 from se-cau/#27-Comment,Issue_Exception
Browse files Browse the repository at this point in the history
fix: Issue 역할제어 추가, DTO 미적용 부분 수정
  • Loading branch information
KEEKE132 authored May 28, 2024
2 parents 68cb7db + a109fd2 commit af7e928
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class CommentController {

@PostMapping
public ResponseEntity<List<CommentResponse>> commentCreate(@RequestParam("issueId") Long issueId,@RequestBody CommentRequest commentRequest){
this.commentService.create(issueId,commentRequest.getMessage(),commentRequest.getAuthorId());
List<Comment> comments = this.commentService.getList(issueId);
commentService.create(issueId,commentRequest.getMessage(),commentRequest.getAuthorId());
List<Comment> comments = commentService.getList(issueId);
List<CommentResponse> responses = new ArrayList<>();
for(Comment i : comments){
responses.add(new CommentResponse(i));
Expand All @@ -33,17 +33,17 @@ public ResponseEntity<List<CommentResponse>> commentCreate(@RequestParam("issueI

@DeleteMapping
public ResponseEntity<Comment> commentDelete(@RequestParam("commentId") Long commentId){
return ResponseEntity.ok(this.commentService.delete(commentId));
return ResponseEntity.ok(commentService.delete(commentId));
}

@PatchMapping
public ResponseEntity<Comment> commentModify(@RequestParam("commentId") Long commentId, @RequestBody CommentRequest commentRequest){
return ResponseEntity.ok(this.commentService.modify(commentId, commentRequest.getMessage()));
return ResponseEntity.ok(commentService.modify(commentId, commentRequest.getMessage()));
}

@GetMapping
public ResponseEntity<List<CommentResponse>> commentListGet(@RequestParam("issueId")Long issueId){
List<Comment> comments = this.commentService.getList(issueId);
List<Comment> comments = commentService.getList(issueId);
List<CommentResponse> responses = new ArrayList<>();
for(Comment i : comments){
responses.add(new CommentResponse(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ public class CommentService {

public Comment create(Long issueId, String content, Long authorId){
Comment comment = new Comment();
Issue issue = this.issueRepository.findById(issueId).get();
Issue issue = issueRepository.findById(issueId).get();
comment.setIssue(issue);
User user = this.userRepository.findById(authorId).get();
User user = userRepository.findById(authorId).get();
comment.setAuthor(user);
comment.setMessage(content);
comment.setCreatedAt(LocalDateTime.now());
this.commentRepository.save(comment);
commentRepository.save(comment);
return comment;
}

public Comment modify(Long commentId,String content){
Comment comment = this.commentRepository.findById(commentId).orElseThrow(()->new CustomException(ErrorCode.COMMENT_NOT_FOUND));
Comment comment = commentRepository.findById(commentId).orElseThrow(()->new CustomException(ErrorCode.COMMENT_NOT_FOUND));
comment.setMessage(content);
this.commentRepository.save(comment);
commentRepository.save(comment);
return comment;
}

public Comment delete(Long commentId){
Comment comment = this.commentRepository.findById(commentId).orElseThrow(()->new CustomException(ErrorCode.COMMENT_NOT_FOUND));
this.commentRepository.delete(comment);
Comment comment = commentRepository.findById(commentId).orElseThrow(()->new CustomException(ErrorCode.COMMENT_NOT_FOUND));
commentRepository.delete(comment);
return comment;
}

public List<Comment> getList(Long issueId){
Issue issue = this.issueRepository.findById(issueId).orElseThrow(()->new CustomException(ErrorCode.ISSUE_NOT_FOUND));
List<Comment> comments = this.commentRepository.findAllByIssue(issue);
Issue issue = issueRepository.findById(issueId).orElseThrow(()->new CustomException(ErrorCode.ISSUE_NOT_FOUND));
List<Comment> comments = commentRepository.findAllByIssue(issue);
return comments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import se.issuetrackingsystem.issue.dto.IssueRequest;
import se.issuetrackingsystem.issue.dto.IssueResponse;
import se.issuetrackingsystem.user.domain.User;
import se.issuetrackingsystem.user.dto.UserResponse;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -24,8 +25,8 @@ public class IssueController {

@PostMapping
public ResponseEntity<List<IssueResponse>> issueCreate(@RequestBody IssueRequest issueRequest, @RequestParam("projectId") Long projectId){
this.issueService.create(projectId,issueRequest.getTitle(),issueRequest.getDescription(),issueRequest.getUserid(),issueRequest.getPriority());
List<Issue> issues = this.issueService.getList(projectId);
issueService.create(projectId,issueRequest.getTitle(),issueRequest.getDescription(),issueRequest.getUserid(),issueRequest.getPriority());
List<Issue> issues = issueService.getList(projectId);
List<IssueResponse> responses = new ArrayList<>();
for(Issue i : issues){
responses.add(new IssueResponse(i));
Expand All @@ -35,7 +36,7 @@ public ResponseEntity<List<IssueResponse>> issueCreate(@RequestBody IssueRequest

@GetMapping
public ResponseEntity<List<IssueResponse>> issueCheck(@RequestParam("projectId") Long projectId){
List<Issue> issues = this.issueService.getList(projectId);
List<Issue> issues = issueService.getList(projectId);
List<IssueResponse> responses = new ArrayList<>();
for(Issue i : issues){
responses.add(new IssueResponse(i));
Expand All @@ -45,7 +46,7 @@ public ResponseEntity<List<IssueResponse>> issueCheck(@RequestParam("projectId")

@GetMapping("/details")
public ResponseEntity<IssueResponse> issueDetail(@RequestParam("issueId") Long issueId){
Issue issue = this.issueService.getIssue(issueId);
Issue issue = issueService.getIssue(issueId);
IssueResponse issueResponse = new IssueResponse(issue);
return ResponseEntity.ok(issueResponse);
}
Expand All @@ -56,20 +57,20 @@ public ResponseEntity<IssueResponse> issueDelete(@RequestParam("issueId") Long i
}

@PatchMapping
public ResponseEntity<Issue> issueModify(@RequestBody IssueRequest issueRequest,@RequestParam("issueId") Long issueId){
Issue issue = this.issueService.modify(issueId,issueRequest.getTitle(),issueRequest.getDescription(),issueRequest.getPriority());
return ResponseEntity.ok(issue);
public ResponseEntity<IssueResponse> issueModify(@RequestBody IssueRequest issueRequest,@RequestParam("issueId") Long issueId){
Issue issue = issueService.modify(issueId,issueRequest.getTitle(),issueRequest.getDescription(),issueRequest.getPriority(),issueRequest.getUserid());
return ResponseEntity.ok(new IssueResponse(issue));
}

@PostMapping("/assignees")
public ResponseEntity<Issue> issueSetAssignee(@RequestBody IssueRequest issueRequest,@RequestParam("issueId") Long issueId){
Issue issue = this.issueService.setAssignee(issueId,issueRequest.getUserid(),issueRequest.getAssigneeId());
return ResponseEntity.ok(issue);
public ResponseEntity<IssueResponse> issueSetAssignee(@RequestBody IssueRequest issueRequest,@RequestParam("issueId") Long issueId){
Issue issue = issueService.setAssignee(issueId,issueRequest.getUserid(),issueRequest.getAssigneeId());
return ResponseEntity.ok(new IssueResponse(issue));
}

@GetMapping("/{status}")
public ResponseEntity<List<IssueResponse>> issueCheckByStatus(@PathVariable("status") Issue.Status status,@RequestParam("projectId") Long projectId){
List<Issue> issues = this.issueService.getList(projectId,status);
List<Issue> issues = issueService.getList(projectId,status);
List<IssueResponse> responses = new ArrayList<>();
for(Issue i : issues){
responses.add(new IssueResponse(i));
Expand All @@ -78,14 +79,14 @@ public ResponseEntity<List<IssueResponse>> issueCheckByStatus(@PathVariable("sta
}

@PatchMapping("/status")
public ResponseEntity<Issue> issueChangeStatus(@RequestBody IssueRequest issueRequest,@RequestParam("issueId") Long issueId){
Issue issue = this.issueService.changeStatus(issueRequest.getUserid(),issueId);
return ResponseEntity.ok(issue);
public ResponseEntity<IssueResponse> issueChangeStatus(@RequestBody IssueRequest issueRequest,@RequestParam("issueId") Long issueId){
Issue issue = issueService.changeStatus(issueRequest.getUserid(),issueId);
return ResponseEntity.ok(new IssueResponse(issue));
}

@GetMapping("/assigned")
public ResponseEntity<List<IssueResponse>> issueCheckByAssignee(@RequestParam("userId") Long userId){
List<Issue> issues = this.issueService.getListByAssignee(userId);
List<Issue> issues = issueService.getListByAssignee(userId);
List<IssueResponse> responses = new ArrayList<>();
for(Issue i : issues){
responses.add(new IssueResponse(i));
Expand All @@ -94,9 +95,9 @@ public ResponseEntity<List<IssueResponse>> issueCheckByAssignee(@RequestParam("u
}

@GetMapping("/candidates")
public ResponseEntity<User> issueCandidate(@RequestParam("issueId") Long issueId) {
User user = this.issueService.candidateUser(issueId).get();
return ResponseEntity.ok(user);
public ResponseEntity<UserResponse> issueCandidate(@RequestParam("issueId") Long issueId) {
User user = issueService.candidateUser(issueId).get();
return ResponseEntity.ok(new UserResponse(user));
}

@GetMapping("/statistics/{projectId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public IssueResponse(Issue issue){
this.setReporter(issue.getReporter().getUsername());
}
if(issue.getAssignee()!=null) {
this.setReporter(issue.getAssignee().getUsername());
this.setAssignee(issue.getAssignee().getUsername());
}
if(issue.getFixer()!=null) {
this.setReporter(issue.getFixer().getUsername());
this.setFixer(issue.getFixer().getUsername());
}
this.setPriority(issue.getPriority());
this.setCreatedAt(issue.getCreatedAt());
Expand Down
Loading

0 comments on commit af7e928

Please sign in to comment.