Skip to content

Commit

Permalink
refactor: #24 - 코드 스타일 통일
Browse files Browse the repository at this point in the history
  • Loading branch information
2522001 authored May 28, 2024
2 parents 8090230 + 8fafd2b commit 6750ab5
Show file tree
Hide file tree
Showing 27 changed files with 422 additions and 369 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
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;
Expand All @@ -23,23 +21,29 @@ public class CommentController {
private final CommentService commentService;

@PostMapping
public void commentCreate(@RequestParam("issueId") Long issueid,@RequestBody CommentRequest commentRequest){
this.commentService.create(issueid,commentRequest.getMessage(),commentRequest.getAuthorid());
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);
List<CommentResponse> responses = new ArrayList<>();
for(Comment i : comments){
responses.add(new CommentResponse(i));
}
return ResponseEntity.ok(responses);
}

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

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

@GetMapping
public ResponseEntity<List<CommentResponse>> commentListGet(@RequestParam("issueId")Long issueid){
List<Comment> comments = this.commentService.getList(issueid);
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
@Setter
@Entity
public class Comment {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String message;

private LocalDateTime created_at;
private LocalDateTime createdAt;

@ManyToOne
private User author;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public class CommentRequest {
private String message;

@NotBlank
private Long authorid;
private Long authorId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,33 @@
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 LocalDateTime createdAt;

private Long authorid;
private Long authorId;

private String username;

private String role;

public CommentResponse(Comment comment) {
this.id = comment.getId();
this.message = comment.getMessage();
if (comment.getAuthor() != null) {
this.authorid = comment.getAuthor().getId();
this.authorId = comment.getAuthor().getId();
this.username = comment.getAuthor().getUsername();
this.role = comment.getAuthor().getRole();
}
this.created_at = comment.getCreated_at();
this.createdAt = comment.getCreatedAt();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,33 @@ public class CommentService {
private final IssueRepository issueRepository;
private final UserRepository userRepository;

public Comment create(Long issueid, String content, Long authorid){
public Comment create(Long issueId, String content, Long authorId){
Comment comment = new Comment();
Issue issue = this.issueRepository.findById(issueid).get();
Issue issue = this.issueRepository.findById(issueId).get();
comment.setIssue(issue);
User user = this.userRepository.findById(authorid).get();
User user = this.userRepository.findById(authorId).get();
comment.setAuthor(user);
comment.setMessage(content);
comment.setCreated_at(LocalDateTime.now());
comment.setCreatedAt(LocalDateTime.now());
this.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));
public Comment modify(Long commentId,String content){
Comment comment = this.commentRepository.findById(commentId).orElseThrow(()->new CustomException(ErrorCode.COMMENT_NOT_FOUND));
comment.setMessage(content);
this.commentRepository.save(comment);
return comment;
}

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

public List<Comment> getList(Long issueid){
Issue issue = this.issueRepository.findById(issueid).orElseThrow(()->new CustomException(ErrorCode.ISSUE_NOT_FOUND));
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);
return comments;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

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

@Slf4j
@RequestMapping("api/v1/issues")
Expand All @@ -24,13 +23,19 @@ public class IssueController {
private final IssueService issueService;

@PostMapping
public void issueCreate(@RequestBody IssueRequest issueRequest, @RequestParam("projectId") Long projectid){
this.issueService.create(projectid,issueRequest.getTitle(),issueRequest.getDescription(),issueRequest.getUserid(),issueRequest.getPriority());
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);
List<IssueResponse> responses = new ArrayList<>();
for(Issue i : issues){
responses.add(new IssueResponse(i));
}
return ResponseEntity.ok(responses);
}

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

@GetMapping("/details")
public ResponseEntity<IssueResponse> issueDetail(@RequestParam("issueId") Long issueid){
Issue issue = this.issueService.getIssue(issueid);
public ResponseEntity<IssueResponse> issueDetail(@RequestParam("issueId") Long issueId){
Issue issue = this.issueService.getIssue(issueId);
IssueResponse issueResponse = new IssueResponse(issue);
return ResponseEntity.ok(issueResponse);
}

@DeleteMapping
public void issueDelete(@RequestParam("issueId") Long issueid){
this.issueService.delete(issueid);
public ResponseEntity<IssueResponse> issueDelete(@RequestParam("issueId") Long issueId){
return ResponseEntity.ok(new IssueResponse(issueService.delete(issueId)));
}

@PatchMapping
public void issueModify(@RequestBody IssueRequest issueRequest,@RequestParam("issueId") Long issueid){
this.issueService.modify(issueid,issueRequest.getTitle(),issueRequest.getDescription(),issueRequest.getPriority());
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);
}

@PostMapping("/assignees")
public void issueSetAssignee(@RequestBody IssueRequest issueRequest,@RequestParam("issueId") Long issueid){
this.issueService.setAssignee(issueid,issueRequest.getUserid(),issueRequest.getAssigneeid());
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);
}

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

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/se/issuetrackingsystem/issue/domain/Issue.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public class Issue {
@Enumerated(EnumType.STRING)
private Priority priority = Priority.MAJOR;

private LocalDateTime updated_at;
private LocalDateTime updatedAt;

private LocalDateTime created_at;
private LocalDateTime createdAt;

@OneToMany(mappedBy = "issue", cascade = CascadeType.REMOVE)
private List<Comment> commentList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package se.issuetrackingsystem.issue.dto;

import jakarta.validation.constraints.NotEmpty;
import lombok.Getter;
import lombok.Setter;
import se.issuetrackingsystem.issue.domain.Issue;
Expand All @@ -18,6 +17,6 @@ public class IssueRequest {

private Long userid;

private Long assigneeid;
private Long assigneeId;

}
42 changes: 21 additions & 21 deletions src/main/java/se/issuetrackingsystem/issue/dto/IssueResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,6 @@
@Setter
public class IssueResponse {

public IssueResponse(Issue issue){
this.setTitle(issue.getTitle());
this.setId(issue.getId());
this.setDescription(issue.getDescription());
if(issue.getReporter()!=null) {
this.setReporter(issue.getReporter().getUsername());
}
if(issue.getAssignee()!=null) {
this.setReporter(issue.getAssignee().getUsername());
}
if(issue.getFixer()!=null) {
this.setReporter(issue.getFixer().getUsername());
}
this.setPriority(issue.getPriority());
this.setCreated_at(issue.getCreated_at());
this.setUpdated_at(issue.getUpdated_at());
this.setStatus(issue.getStatus());
}

@NotEmpty
private Long id;

Expand All @@ -49,6 +30,25 @@ public IssueResponse(Issue issue){

private Issue.Priority priority;

private LocalDateTime created_at;
private LocalDateTime updated_at;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;

public IssueResponse(Issue issue){
this.setTitle(issue.getTitle());
this.setId(issue.getId());
this.setDescription(issue.getDescription());
if(issue.getReporter()!=null) {
this.setReporter(issue.getReporter().getUsername());
}
if(issue.getAssignee()!=null) {
this.setReporter(issue.getAssignee().getUsername());
}
if(issue.getFixer()!=null) {
this.setReporter(issue.getFixer().getUsername());
}
this.setPriority(issue.getPriority());
this.setCreatedAt(issue.getCreatedAt());
this.setUpdatedAt(issue.getUpdatedAt());
this.setStatus(issue.getStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
@Getter
public class IssueStatisticsResponse {

private Map<Issue.Status, Long> statusDistribution;
private Map<String, Long> reporterDistribution;
private Map<String, Long> assigneeDistribution;
private List<String> topCommentedIssues;
private final Map<Issue.Status, Long> statusDistribution;
private final Map<String, Long> reporterDistribution;
private final Map<String, Long> assigneeDistribution;
private final List<String> topCommentedIssues;

public IssueStatisticsResponse(Map<Issue.Status, Long> statusDistribution,
Map<String, Long> reporterDistribution,
Expand Down
Loading

0 comments on commit 6750ab5

Please sign in to comment.