diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index 972f9241..b2f8959d 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -10,7 +10,6 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; import org.springframework.data.domain.Example; -import org.springframework.graphql.client.ClientGraphQlResponse; import org.springframework.graphql.client.HttpSyncGraphQlClient; import de.tum.in.www1.hephaestus.EnvConfig; @@ -64,19 +63,18 @@ public Repository getHephaestusRepository() { variables.put("name", "hephaestus"); variables.put("first", 10); - ClientGraphQlResponse response = graphQlClient.documentName("getrepositoryprs") + Repository repository = graphQlClient.documentName("getrepositoryprs") .variables(variables) - .executeSync(); + .retrieveSync("repository") + .toEntity(Repository.class); - logger.info("Response: " + response.getData()); - if (response.getErrors().size() > 0) { - logger.error("Error while fetching repository: " + response.getErrors().toString()); + if (repository == null) { + logger.error("Error while fetching repository!"); return null; } - Repository repository = response.toEntity(Repository.class); repository.setAddedAt(Instant.now()); - System.out.println("Repository: " + repository.getName()); + System.out.println("Repository: " + repository.toString()); codeReviewRepository.save(repository); return repository; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java index b20a46ff..562e6cdb 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -3,7 +3,6 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; import de.tum.in.www1.hephaestus.codereview.actor.Actor; -import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -26,6 +25,9 @@ public class Comment { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "github_id") + private String githubId; + /** * Body of the Comment entity. * This field is mandatory. @@ -38,14 +40,14 @@ public class Comment { * This field is mandatory. */ @Column(nullable = false) - private Long createdAt; + private String createdAt; /** * Timestamp of when the Comment entity was updated. * This field is mandatory. */ @Column(nullable = false) - private Long updatedAt; + private String updatedAt; /** * The author of the Comment entity. @@ -58,6 +60,6 @@ public class Comment { * The pullrequest of the Comment entity. */ @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "pullrequest_id") - private Pullrequest pullrequest; + @JoinColumn(name = "c_connection_id") + private CommentConnection connection; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java new file mode 100644 index 00000000..b4a5cc5e --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java @@ -0,0 +1,31 @@ +package de.tum.in.www1.hephaestus.codereview.comment; + +import java.util.List; + +import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.Setter; + +@Entity +@Table +@Getter +@Setter +public class CommentConnection { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToMany(mappedBy = "connection", fetch = FetchType.LAZY) + private List nodes; + + @OneToOne(mappedBy = "comments", fetch = FetchType.LAZY) + private Pullrequest pullrequest; +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index 4b46c7e9..1cdf1095 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -1,11 +1,9 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; import java.time.Instant; -import java.util.List; import de.tum.in.www1.hephaestus.codereview.actor.Actor; -import de.tum.in.www1.hephaestus.codereview.comment.Comment; -import de.tum.in.www1.hephaestus.codereview.repository.Repository; +import de.tum.in.www1.hephaestus.codereview.comment.CommentConnection; import jakarta.persistence.Id; import jakarta.persistence.Table; import jakarta.persistence.Column; @@ -15,7 +13,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; import lombok.Getter; import lombok.Setter; @@ -32,6 +30,9 @@ public class Pullrequest { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "github_id") + private String githubId; + /** * Title of the Pullrequest. * This field is mandatory. @@ -58,20 +59,20 @@ public class Pullrequest { * This field is mandatory. */ @Column(nullable = false) - private Instant createdAt; + private String createdAt; /** * Timestamp of when the Pullrequest entity was updated. * This field is mandatory. */ @Column(nullable = false) - private Instant updatedAt; + private String updatedAt; /** * Timestamp of when the Pullrequest entity was merged. */ @Column(nullable = true) - private Instant mergedAt; + private String mergedAt; /** * The author of the Pullrequest entity. @@ -83,13 +84,14 @@ public class Pullrequest { /** * The comments of the Pullrequest entity. */ - @OneToMany(mappedBy = "pullrequest", fetch = FetchType.LAZY) - private List comments; + @OneToOne(optional = false) + @JoinColumn(name = "c_connection_id") + private CommentConnection comments; /** * The repository of the Pullrequest entity. */ @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "repository_id") - private Repository repository; + @JoinColumn(name = "pr_connection_id") + private PullrequestConnection connection; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java new file mode 100644 index 00000000..01df35ad --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java @@ -0,0 +1,31 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import java.util.List; + +import de.tum.in.www1.hephaestus.codereview.repository.Repository; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import lombok.Getter; +import lombok.Setter; + +@Entity +@Table +@Getter +@Setter +public class PullrequestConnection { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToMany(mappedBy = "connection", fetch = FetchType.LAZY) + private List nodes; + + @OneToOne(mappedBy = "pullRequests", fetch = FetchType.LAZY) + private Repository repository; +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 30afcd60..6904ec10 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -1,18 +1,16 @@ package de.tum.in.www1.hephaestus.codereview.repository; import java.time.Instant; -import java.util.List; -import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; +import de.tum.in.www1.hephaestus.codereview.pullrequest.PullrequestConnection; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; import jakarta.persistence.Table; -import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; @@ -27,26 +25,32 @@ public class Repository { */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long uid; + private Long id; - @NotNull - private String id; + @Column(name = "github_id") + private String githubId; - @NotNull + @Column private String name; - @NotNull + @Column(name = "name_with_owner") private String nameWithOwner; - @NotNull + @Column private String description; - @NotNull + @Column private String url; - @OneToMany(mappedBy = "repository", fetch = FetchType.LAZY) - private List pullRequests; + @OneToOne(optional = false) + @JoinColumn(name = "connection_id") + private PullrequestConnection pullRequests; - @NotNull + @Column(name = "added_at") private Instant addedAt; + + public String toString() { + return "Repository [id=" + id + ", name=" + name + ", nameWithOwner=" + nameWithOwner + ", description=" + + description + ", url=" + url + ", pullRequests=" + pullRequests + ", addedAt=" + addedAt + "]"; + } } diff --git a/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql b/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql index 32c1aa5a..fd8d82e8 100644 --- a/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql +++ b/server/application-server/src/main/resources/graphql-documents/getrepositoryprs.gql @@ -1,13 +1,13 @@ query GetRepositoryPRs($owner: String!, $name: String!, $first: Int!) { repository(owner: $owner, name: $name) { - id + githubId: id name nameWithOwner description url pullRequests(first: $first, states: [OPEN, MERGED]) { nodes { - id + githubId: id title url state @@ -15,20 +15,16 @@ query GetRepositoryPRs($owner: String!, $name: String!, $first: Int!) { updatedAt mergedAt author { - avatarUrl - login - url + ...authorFields } comments(last: 100) { nodes { - id + githubId: id body createdAt updatedAt author { - avatarUrl - login - url + ...authorFields } } } @@ -36,3 +32,9 @@ query GetRepositoryPRs($owner: String!, $name: String!, $first: Int!) { } } } + +fragment authorFields on Actor { + avatarUrl + login + url +}