-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#144: create activities endpoint for dashboard
- Loading branch information
Showing
5 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...ation-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ActivitiesDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} |
21 changes: 21 additions & 0 deletions
21
...rc/main/java/de/tum/in/www1/hephaestus/activitydashboard/ActivityDashboardController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...r/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ActivityDashboardService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ion-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issue/IssueRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |