Skip to content

Commit

Permalink
Create Team entity
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Oct 20, 2024
1 parent 237578f commit 9dfd5aa
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package de.tum.in.www1.hephaestus.codereview.team;

import jakarta.persistence.Table;

import java.util.HashSet;
import java.util.Set;

import org.springframework.lang.NonNull;

import de.tum.in.www1.hephaestus.codereview.user.User;
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.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Entity
@Table(name = "team")
@Getter
@Setter
@NoArgsConstructor
@ToString(callSuper = true)
public class Team {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column
private String name;

@NonNull
private String color;

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "TEAM_MEMBERS", joinColumns = @JoinColumn(name = "team_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"))
@ToString.Exclude
private Set<User> members = new HashSet<>();

public void addMember(User user) {
members.add(user);
user.addTeam(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.tum.in.www1.hephaestus.codereview.team;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;

public interface TeamRepository extends JpaRepository<Team, Long> {

Optional<Team> findByName(String name);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.tum.in.www1.hephaestus.codereview.team;

import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class TeamService {
private static final Logger logger = LoggerFactory.getLogger(TeamService.class);

private final TeamRepository teamRepository;

public TeamService(TeamRepository teamRepository) {
this.teamRepository = teamRepository;
}

public Optional<Team> getTeam(String name) {
logger.info("Getting team with name: " + name);
return teamRepository.findByName(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
import de.tum.in.www1.hephaestus.codereview.comment.review.PullRequestReviewComment;
import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest;
import de.tum.in.www1.hephaestus.codereview.pullrequest.review.PullRequestReview;
import de.tum.in.www1.hephaestus.codereview.team.Team;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.OneToMany;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -63,6 +66,10 @@ public class User extends BaseGitServiceEntity {
@NonNull
private UserType type;

@ManyToMany(fetch = FetchType.EAGER, mappedBy = "members")
@ToString.Exclude
private Set<Team> teams = new HashSet<>();

@OneToMany(cascade = CascadeType.ALL, mappedBy = "author")
private Set<PullRequest> pullRequests = new HashSet<>();

Expand Down Expand Up @@ -90,4 +97,8 @@ public void addPullRequest(PullRequest pullRequest) {
public void addReview(PullRequestReview review) {
reviews.add(review);
}

public void addTeam(Team team) {
teams.add(team);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import de.tum.in.www1.hephaestus.admin.AdminService;
import de.tum.in.www1.hephaestus.codereview.comment.IssueComment;
import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentConverter;
import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentRepository;
Expand Down Expand Up @@ -59,9 +60,6 @@ public class GitHubDataSyncService {
@Value("${github.authToken:null}")
private String ghAuthToken;

@Value("${monitoring.repositories}")
private String[] repositoriesToMonitor;

@Value("${monitoring.timeframe}")
private int timeframe;
private OffsetDateTime cutOffTime;
Expand All @@ -75,6 +73,9 @@ public class GitHubDataSyncService {
private final PullRequestReviewCommentRepository reviewCommentRepository;
private final UserRepository userRepository;

@Autowired
private AdminService adminService;

@Autowired
private RepositoryConverter repositoryConverter;
@Autowired
Expand Down Expand Up @@ -109,6 +110,8 @@ public void syncData() {
logger.error("Aborted GitHub data sync due to error during initialization of GitHub client.");
return;
}

Set<String> repositoriesToMonitor = adminService.getAdminConfig().getRepositoriesToMonitor();
int successfullySyncedRepositories = 0;
for (String repositoryName : repositoriesToMonitor) {
try {
Expand All @@ -121,7 +124,7 @@ public void syncData() {
}
}
logger.info("GitHub data sync completed for " + successfullySyncedRepositories + "/"
+ repositoriesToMonitor.length + " repositories for the last " + timeframe + " day(s).");
+ repositoriesToMonitor.size() + " repositories for the last " + timeframe + " day(s).");
}

private boolean initGithubClient() {
Expand Down

0 comments on commit 9dfd5aa

Please sign in to comment.