Skip to content

Commit

Permalink
Merge pull request #23 from 2024-Iris/issue
Browse files Browse the repository at this point in the history
Issue 저장 로직 구현
  • Loading branch information
lvalentine6 authored Jul 3, 2024
2 parents ca74f9d + 8eb1158 commit d0c8d40
Show file tree
Hide file tree
Showing 26 changed files with 816 additions and 115 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ dependencies {
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.5'

// MapStruct
implementation 'org.mapstruct:mapstruct:1.5.5.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final'

// REST Docs
asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/site/iris/issuefy/controller/IssueController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package site.iris.issuefy.controller;

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.RequestAttribute;
import org.springframework.web.bind.annotation.RestController;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import site.iris.issuefy.response.RepositoryIssuesResponse;
import site.iris.issuefy.service.IssueService;

@RestController
Expand All @@ -15,10 +18,13 @@
public class IssueController {
private final IssueService issueService;

@GetMapping("/api/{repoName}/issues")
public ResponseEntity<String> getIssuesByRepoName(@PathVariable("repoName") String repoName) {
@GetMapping("/api/subscriptions/{org_name}/{repo_name}/issues")
public ResponseEntity<RepositoryIssuesResponse> getIssuesByRepoName(@PathVariable("org_name") String orgName,
@PathVariable("repo_name") String repoName,
@RequestAttribute String githubId) {
log.info("getIssuesByRepoName: {}", repoName);
String answer = issueService.getIssuesByRepoName(repoName);
return ResponseEntity.ok(answer);
RepositoryIssuesResponse response = issueService.initializeIssueSubscription(orgName, repoName, githubId);
log.info(repoName);
return ResponseEntity.status(HttpStatus.OK).body(response);
}
}
44 changes: 43 additions & 1 deletion src/main/java/site/iris/issuefy/entity/Issue.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package site.iris.issuefy.entity;

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

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -34,5 +39,42 @@ public class Issue {
private boolean isRead;

@Column
private long ghIssueNumber;
private String state;

@Column
private Date createdAt;

@Column
private Date updatedAt;

@Column
private Date closedAt;

@Column
private long ghIssueId;

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

private Issue(Repository repository, String title, boolean isStarred, boolean isRead, String state, Date createdAt,
Date updatedAt, Date closedAt, long ghIssueId, List<IssueLabel> issueLabels) {
this.repository = repository;
this.title = title;
this.isStarred = isStarred;
this.isRead = isRead;
this.state = state;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.closedAt = closedAt;
this.ghIssueId = ghIssueId;
this.issueLabels = issueLabels;
}

public static Issue of(Repository repository, String title, boolean isStarred, boolean isRead, String state,
Date createdAt,
Date updatedAt, Date closedAt, long ghIssueNumber, List<IssueLabel> issueLabels) {
return new Issue(repository, title, isStarred, isRead, state, createdAt, updatedAt, closedAt, ghIssueNumber,
issueLabels);
}
}

38 changes: 38 additions & 0 deletions src/main/java/site/iris/issuefy/entity/IssueLabel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package site.iris.issuefy.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor
@Table(name = "issue_label")
public class IssueLabel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@JoinColumn(name = "issue_id")
private Issue issue;

@ManyToOne
@JoinColumn(name = "label_id")
private Label label;

private IssueLabel(Issue issue, Label label) {
this.issue = issue;
this.label = label;
}

public static IssueLabel of(Issue issue, Label label) {
return new IssueLabel(issue, label);
}
}
21 changes: 21 additions & 0 deletions src/main/java/site/iris/issuefy/entity/Label.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package site.iris.issuefy.entity;

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

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinTable;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -20,4 +25,20 @@ public class Label {

@Column(name = "name")
private String name;

@Column(name = "color")
private String color;

@OneToMany
@JoinTable(name = "issue_label")
private List<Issue> issue = new ArrayList<>();

private Label(String name, String color) {
this.name = name;
this.color = color;
}

public static Label of(String name, String color) {
return new Label(name, color);
}
}
2 changes: 1 addition & 1 deletion src/main/java/site/iris/issuefy/entity/Org.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import lombok.NoArgsConstructor;

@Entity
@Table(name = "org")
@Table(name = "organization")
@Getter
@NoArgsConstructor
public class Org {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@RequiredArgsConstructor
public enum ErrorCode {
REQUIRED_KEYS_MISSING(HttpStatus.BAD_REQUEST, "Required keys are missing"),
NOT_EXIST_REPOSITORY(HttpStatus.NOT_FOUND, "Repository does not exist"),
NOT_EXIST_REPOSITORY(HttpStatus.NOT_FOUND, "Repository does not exist - Details: "),
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Internal Server Error");

private final HttpStatus status;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/site/iris/issuefy/mapper/LabelMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package site.iris.issuefy.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import site.iris.issuefy.entity.Label;
import site.iris.issuefy.response.LabelResponse;

@Mapper
public interface LabelMapper {
LabelMapper INSTANCE = Mappers.getMapper(LabelMapper.class);

LabelResponse labelEntityToLabelDto(Label label);
}
40 changes: 40 additions & 0 deletions src/main/java/site/iris/issuefy/model/dto/IssueDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package site.iris.issuefy.model.dto;

import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AllArgsConstructor;
import lombok.Data;
import site.iris.issuefy.entity.Label;

@Data
@AllArgsConstructor
public class IssueDto {
@JsonProperty("id")
private Long ghIssueId;

private String title;
private boolean isStarred;
private boolean isRead;
private String state;

@JsonProperty("created_at")
private Date createdAt;

@JsonProperty("updated_at")
private Date updatedAt;

@JsonProperty("closed_at")
private Date closedAt;

private List<Label> labels;

public static IssueDto of(Long ghIssueId, String title, boolean isStarred, boolean isRead, String state,
Date createdAt,
Date updatedAt, Date closedAt, List<Label> labels) {
return new IssueDto(ghIssueId, title, isStarred, isRead, state, createdAt, updatedAt, closedAt,
labels);
}
}
14 changes: 14 additions & 0 deletions src/main/java/site/iris/issuefy/model/dto/LabelDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package site.iris.issuefy.model.dto;

import lombok.Data;
import lombok.Getter;

@Data
@Getter
public class LabelDto {
Long id;
String name;
String color;
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package site.iris.issuefy.repository;

import org.springframework.data.repository.CrudRepository;

import site.iris.issuefy.entity.IssueLabel;

public interface IssueLabelRepository extends CrudRepository<IssueLabel, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package site.iris.issuefy.repository;

import org.springframework.data.repository.CrudRepository;

import site.iris.issuefy.entity.Issue;

public interface IssueRepository extends CrudRepository<Issue, Long> {
}
13 changes: 13 additions & 0 deletions src/main/java/site/iris/issuefy/repository/LabelRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package site.iris.issuefy.repository;

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

import org.springframework.data.repository.CrudRepository;

import site.iris.issuefy.entity.Label;

public interface LabelRepository extends CrudRepository<Label, Long> {
Optional<Label> findByNameAndColor(String name, String color);
Optional<List<Label>> findByIssue_id(Long issueId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import site.iris.issuefy.entity.Repository;

public interface RepositoryRepository extends CrudRepository<Repository, Long> {
Optional<Repository> findByNameAndOrgId(String repositoryName, Long orgId);

Optional<Repository> findByGhRepoId(Long ghRepoId);

Optional<Repository> findByName(String name);
}
39 changes: 35 additions & 4 deletions src/main/java/site/iris/issuefy/response/IssueResponse.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
package site.iris.issuefy.response;

import java.util.Date;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class IssueResponse {
private Long id;
private int githubIssueNumber;
private Long githubIssueId;
private String state;
private String title;
private String label;
private List<LabelResponse> labels;
private boolean isRead;
private boolean isStarred;
private Date createdAt;
private Date updatedAt;
private Date closedAt;

public static IssueResponse of(Long id, int githubIssueNumber, String title, String label) {
return new IssueResponse(id, githubIssueNumber, title, label);
public static IssueResponse of(
Long id,
Long githubIssueId,
String state,
String title,
List<LabelResponse> labels,
boolean isRead,
boolean isStarred,
Date createdAt,
Date updatedAt,
Date closedAt) {
return new IssueResponse(
id,
githubIssueId,
state,
title,
labels,
isRead,
isStarred,
createdAt,
updatedAt,
closedAt
);
}

}
9 changes: 9 additions & 0 deletions src/main/java/site/iris/issuefy/response/LabelResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package site.iris.issuefy.response;

import lombok.Data;

@Data
public class LabelResponse {
String name;
String color;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package site.iris.issuefy.response;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class RepositoryIssuesResponse {
private String repositoryName;
private List<IssueResponse> issues;
}
Loading

0 comments on commit d0c8d40

Please sign in to comment.