Skip to content

Commit

Permalink
#144: create activities endpoint for dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-flo committed Nov 12, 2024
1 parent 0b707ef commit ab885c8
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.tum.in.www1.hephaestus.activitydashboard;

import de.tum.in.www1.hephaestus.gitprovider.issue.IssueInfoDTO;
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequestInfoDTO;
import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReviewInfoDTO;
import io.micrometer.common.lang.NonNull;

import java.util.List;

public record ActivitiesDTO(
@NonNull List<PullRequestInfoDTO> pullRequests,
@NonNull List<IssueInfoDTO> issues,
@NonNull List<PullRequestReviewInfoDTO> reviews) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.tum.in.www1.hephaestus.activitydashboard;

import org.springframework.beans.factory.annotation.Autowired;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/activity")
public class ActivityDashboardController {

@Autowired
private ActivityDashboardService activityDashboardService;

@GetMapping("/{login}")
public ResponseEntity<ActivitiesDTO> getActivitiesByUser(@PathVariable String login) {
return ResponseEntity.ok(activityDashboardService.getActivities(login));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package de.tum.in.www1.hephaestus.activitydashboard;

import de.tum.in.www1.hephaestus.gitprovider.issue.Issue;
import de.tum.in.www1.hephaestus.gitprovider.issue.IssueInfoDTO;
import de.tum.in.www1.hephaestus.gitprovider.issue.IssueRepository;
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequest;
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequestInfoDTO;
import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequestRepository;
import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReview;
import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReviewInfoDTO;
import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReviewRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
public class ActivityDashboardService {

@Autowired
private PullRequestRepository pullRequestRepository;

@Autowired
private IssueRepository issueRepository;

@Autowired
private PullRequestReviewRepository pullRequestReviewRepository;

public ActivitiesDTO getActivities(String login) {

List<PullRequest> pullRequests = pullRequestRepository.findAssignedByLoginAndStates(login, Set.of(PullRequest.State.OPEN));
List<Issue> issues = List.of();//issueRepository.findAssignedByLoginAndStates(login, Set.of(Issue.State.OPEN));
List<PullRequestReview> reviews = List.of(); //TODO: which reviews to return here: all reviews of open PRs of others? what about where review is requested?
return new ActivitiesDTO(
pullRequests.stream().map(PullRequestInfoDTO::fromPullRequest).toList(),
issues.stream().map(IssueInfoDTO::fromIssue).toList(),
reviews.stream().map(PullRequestReviewInfoDTO::fromPullRequestReview).toList()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,27 @@ public record IssueInfoDTO(
OffsetDateTime createdAt,
OffsetDateTime updatedAt
) {

public static IssueInfoDTO fromIssue(Issue issue) {
return new IssueInfoDTO(
issue.getId(),
issue.getNumber(),
issue.getTitle(),
issue.getState(),
issue.getCommentsCount(),
UserInfoDTO.fromUser(issue.getAuthor()),
issue.getLabels()
.stream()
.map(LabelInfoDTO::fromLabel)
.toList(),
issue.getAssignees()
.stream()
.map(UserInfoDTO::fromUser)
.toList(),
issue.getRepository().getNameWithOwner(),
issue.getHtmlUrl(),
issue.getCreatedAt(),
issue.getUpdatedAt()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
package de.tum.in.www1.hephaestus.gitprovider.issue;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Set;

public interface IssueRepository extends JpaRepository<Issue, Long> {

@Query("""
SELECT i
FROM Issue i
LEFT JOIN FETCH i.labels
JOIN FETCH i.author
LEFT JOIN FETCH i.assignees
LEFT JOIN FETCH i.repository
WHERE (i.author.login ILIKE :assigneeLogin OR LOWER(:assigneeLogin) IN (SELECT LOWER(u.login) FROM i.assignees u)) AND i.state IN :states
ORDER BY i.createdAt DESC
""")
List<Issue> findAssignedByLoginAndStates(
@Param("assigneeLogin") String assigneeLogin,
@Param("states") Set<Issue.State> states);
}

0 comments on commit ab885c8

Please sign in to comment.