Skip to content

Commit

Permalink
Merge pull request #27 from Sonjh1306/BE/feature/issue-create
Browse files Browse the repository at this point in the history
[#15] 이슈 추가하기 구현 완료
  • Loading branch information
ehdrhelr authored Jun 12, 2021
2 parents 890188f + f4a3a4d commit baa7fbb
Show file tree
Hide file tree
Showing 32 changed files with 409 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package team02.issue_tracker.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team02.issue_tracker.dto.wrapping.DataResponse;
import team02.issue_tracker.dto.wrapping.ListDataResponse;
import org.springframework.web.bind.annotation.*;
import team02.issue_tracker.dto.issue.DetailIssueResponse;
import team02.issue_tracker.dto.issue.IssueRequest;
import team02.issue_tracker.dto.issue.IssueResponse;
import team02.issue_tracker.dto.wrapping.ApiResult;
import team02.issue_tracker.service.IssueService;

import java.util.List;

@RestController
@RequestMapping("/api/issues")
public class IssueController {
Expand All @@ -19,12 +20,18 @@ public IssueController(IssueService issueService) {
}

@GetMapping
public ListDataResponse showAllIssues() {
public ApiResult<List<IssueResponse>> showAllIssues() {
return issueService.getAllIssueResponses();
}

@GetMapping("/{issueId}")
public DataResponse showDetailIssue(@PathVariable Long issueId) {
public ApiResult<DetailIssueResponse> showDetailIssue(@PathVariable Long issueId) {
return issueService.getDetailIssueResponse(issueId);
}

@PostMapping
public ApiResult<String> createIssue(@RequestBody IssueRequest issueRequest) {
return issueService.addIssue(issueRequest);

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team02.issue_tracker.domain;

import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.time.LocalDateTime;
Expand All @@ -9,8 +10,10 @@

@Entity
@Getter
@NoArgsConstructor
public class Comment {
@Id @GeneratedValue
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String content;
Expand All @@ -27,4 +30,15 @@ public class Comment {

@OneToMany(mappedBy = "comment")
private List<CommentEmoji> commentEmojis = new ArrayList<>();

public Comment(String content, String file, User writer) {
this.content = content;
this.file = file;
this.writer = writer;
this.createdTime = LocalDateTime.now();
}

public void addIssue(Issue issue) {
this.issue = issue;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team02.issue_tracker.domain;

import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.time.LocalDateTime;
Expand All @@ -9,11 +10,12 @@

@Entity
@Getter
@NoArgsConstructor
public class Issue {
@Id @GeneratedValue
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private int issueNumber;
private String title;

@OneToMany(mappedBy = "issue")
Expand All @@ -35,4 +37,15 @@ public class Issue {

@OneToMany(mappedBy = "issue")
private List<Comment> comments = new ArrayList<>();

public Issue(String title, User writer, boolean isOpen) {
this.title = title;
this.writer = writer;
this.isOpen = isOpen;
createdTime = LocalDateTime.now();
}

public void addMilestone(Milestone milestone) {
this.milestone = milestone;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package team02.issue_tracker.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import team02.issue_tracker.domain.composite_key.IssueAssigneeId;

import javax.persistence.*;

@IdClass(IssueAssigneeId.class)
@Entity
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class IssueAssignee {
@Id
@ManyToOne
Expand All @@ -18,4 +22,5 @@ public class IssueAssignee {
@ManyToOne
@JoinColumn(name = "user_id")
private User assignee;

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package team02.issue_tracker.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import team02.issue_tracker.domain.composite_key.IssueLabelId;

import javax.persistence.*;

@IdClass(IssueLabelId.class)
@Entity
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class IssueLabel {

@Id
@ManyToOne
@JoinColumn(name = "issue_id")
Expand All @@ -18,4 +23,5 @@ public class IssueLabel {
@ManyToOne
@JoinColumn(name = "label_id")
private Label label;

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package team02.issue_tracker.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
Expand All @@ -12,13 +13,17 @@

@Entity
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class Label {
@Id @GeneratedValue
private Long id;

private String title;
private String content;
private String color;

@OneToMany(mappedBy = "label")
private List<IssueLabel> issueLabels = new ArrayList<>();

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Getter;
import team02.issue_tracker.domain.Comment;
import team02.issue_tracker.domain.CommentEmoji;
import team02.issue_tracker.domain.Emoji;

import java.time.LocalDateTime;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public abstract class AbstractIssueResponse {

public AbstractIssueResponse(Issue issue) {
this.id = issue.getId();
this.issueNumber = issue.getIssueNumber();
this.title = issue.getTitle();
this.createdTime = issue.getCreatedTime();
this.isOpen = issue.isOpen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@

import lombok.Getter;
import team02.issue_tracker.domain.Issue;
import team02.issue_tracker.domain.Milestone;
import team02.issue_tracker.dto.CommentResponse;
import team02.issue_tracker.dto.MilestoneDetailResponse;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Getter
public class DetailIssueResponse extends AbstractIssueResponse {

private MilestoneDetailResponse milestone;
private Optional<MilestoneDetailResponse> milestone;
private List<CommentResponse> comments;

public DetailIssueResponse(Issue issue) {
super(issue);
this.milestone = new MilestoneDetailResponse(issue.getMilestone());
this.milestone = toMilestoneDetailResponse(issue.getMilestone());
this.comments = issue.getComments().stream()
.map(CommentResponse::new)
.collect(Collectors.toList());
}

private Optional<MilestoneDetailResponse> toMilestoneDetailResponse(Milestone milestone) {
if (milestone == null) {
return Optional.empty();
}
return Optional.of(new MilestoneDetailResponse(milestone));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package team02.issue_tracker.dto.issue;

import lombok.Getter;
import lombok.NoArgsConstructor;
import team02.issue_tracker.domain.*;

import java.util.List;

@NoArgsConstructor
@Getter
public class IssueRequest {

private String title;
private String comment;
private String file;
private Long userId;
private List<Long> labelIds;
private Long milestoneId;
private List<Long> assigneeIds;

public Issue toIssue(User writer) {
return new Issue(title, writer, true);
}

public Comment toComment(User writer) {
return new Comment(comment, file, writer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@

import lombok.Getter;
import team02.issue_tracker.domain.Issue;
import team02.issue_tracker.domain.Milestone;
import team02.issue_tracker.dto.MilestoneResponse;

import java.util.Optional;

@Getter
public class IssueResponse extends AbstractIssueResponse {

private MilestoneResponse milestone;
private Optional<MilestoneResponse> milestone;

public IssueResponse(Issue issue) {
super(issue);
this.milestone = new MilestoneResponse(issue.getMilestone());
this.milestone = toMilestoneResponse(issue.getMilestone());
}

private Optional<MilestoneResponse> toMilestoneResponse(Milestone milestone) {
if(milestone == null) {
return Optional.empty();
}
return Optional.of(new MilestoneResponse(milestone));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package team02.issue_tracker.dto.wrapping;

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public class ApiResult<T> {

private T data;
private String error;

public static <T> ApiResult<T> success(T data) {
return new ApiResult<>(data, null);
}

public static ApiResult<?> fail(String errorMessage) {
return new ApiResult<>(null, errorMessage);
}

public static ApiResult<?> fail(Throwable cause) {
return fail(cause.getMessage());
}

public static ApiResult<String> ok() {
return success("OK");
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package team02.issue_tracker.exception;

public class IssueNotFoundException extends RuntimeException{
public class IssueNotFoundException extends NotFoundException{

public IssueNotFoundException() {
super("issue not found!!!");
super("해당 이슈가 존재하지 않습니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package team02.issue_tracker.exception;

public class LabelNotFoundException extends NotFoundException{

public LabelNotFoundException() {
super("해당 라벨이 존재하지 않습니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package team02.issue_tracker.exception;

public class MilestoneNotFoundException extends NotFoundException{

public MilestoneNotFoundException() {
super("해당 마일스톤이 존재하지 않습니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package team02.issue_tracker.exception;

public class NotFoundException extends RuntimeException{

public NotFoundException(String message) {
super(message);
}
}
Loading

0 comments on commit baa7fbb

Please sign in to comment.