From 29f303cee3190939c6b5d0989907ad7ef01bde68 Mon Sep 17 00:00:00 2001 From: Florian Ehrenstorfer Date: Mon, 25 Nov 2024 14:18:45 +0100 Subject: [PATCH] #140: Update to DTO --- ...assImportIntegratorIntegratorProvider.java | 4 +-- .../activitydashboard/ActivityDTO.java | 2 +- .../activitydashboard/ActivityService.java | 15 ++++------ ...ctivityDto.java => ReviewActivityDTO.java} | 28 +++++++++---------- 4 files changed, 23 insertions(+), 26 deletions(-) rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/{ReviewActivityDto.java => ReviewActivityDTO.java} (66%) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/ClassImportIntegratorIntegratorProvider.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/ClassImportIntegratorIntegratorProvider.java index cf30043f..109dc265 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/ClassImportIntegratorIntegratorProvider.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/ClassImportIntegratorIntegratorProvider.java @@ -4,7 +4,7 @@ import java.util.List; import de.tum.in.www1.hephaestus.activitydashboard.ActivityDTO; -import de.tum.in.www1.hephaestus.activitydashboard.ReviewActivityDto; +import de.tum.in.www1.hephaestus.activitydashboard.ReviewActivityDTO; import org.hibernate.integrator.spi.Integrator; import org.hibernate.jpa.boot.spi.IntegratorProvider; @@ -36,7 +36,7 @@ public List getIntegrators() { classes.add(PullRequestReviewInfoDTO.class); classes.add(RepositoryInfoDTO.class); classes.add(ActivityDTO.class); - classes.add(ReviewActivityDto.class); + classes.add(ReviewActivityDTO.class); return List.of(new ClassImportIntegrator(classes)); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ActivityDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ActivityDTO.java index f934c528..8c559881 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ActivityDTO.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ActivityDTO.java @@ -9,5 +9,5 @@ public record ActivityDTO( @NonNull List pullRequests, @NonNull List issues, - @NonNull List reviews) { + @NonNull List reviews) { } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ActivityService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ActivityService.java index efb703fe..90f45408 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ActivityService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ActivityService.java @@ -3,11 +3,8 @@ 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 jakarta.transaction.Transactional; import org.springframework.stereotype.Service; @@ -44,7 +41,7 @@ public ActivityDTO getActivity(String login) { .map(IssueInfoDTO::fromIssue) .toList(); - List reviews = getReviewedOrRequestedPullRequests(login); + List reviews = getReviewedOrRequestedPullRequests(login); return new ActivityDTO( openPullRequests, @@ -53,15 +50,15 @@ public ActivityDTO getActivity(String login) { ); } - private List getReviewedOrRequestedPullRequests(String login) { - List reviews = pullRequestReviewRepository.findAllOpenReviewsByAuthorLogin(login) + private List getReviewedOrRequestedPullRequests(String login) { + List reviews = pullRequestReviewRepository.findAllOpenReviewsByAuthorLogin(login) .stream() - .map(ReviewActivityDto::fromPullRequestReview) + .map(ReviewActivityDTO::fromPullRequestReview) .toList(); - List requestedReviews = pullRequestRepository.findReviewRequestedByLogin(login) + List requestedReviews = pullRequestRepository.findReviewRequestedByLogin(login) .stream() - .map(ReviewActivityDto::fromPullRequest) + .map(ReviewActivityDTO::fromPullRequest) .toList(); requestedReviews.addAll(reviews); diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ReviewActivityDto.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ReviewActivityDTO.java similarity index 66% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ReviewActivityDto.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ReviewActivityDTO.java index 3139123b..88607e86 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ReviewActivityDto.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/activitydashboard/ReviewActivityDTO.java @@ -9,37 +9,37 @@ import de.tum.in.www1.hephaestus.gitprovider.user.UserInfoDTO; @JsonInclude(JsonInclude.Include.NON_EMPTY) -public record ReviewActivityDto( +public record ReviewActivityDTO( @NonNull Long id, @NonNull Boolean isDismissed, - @NonNull ReviewActivityStateDto state, + @NonNull ReviewActivityStateDTO state, @NonNull Integer codeComments, UserInfoDTO author, PullRequestInfoDTO pullRequest) { - public static ReviewActivityDto fromPullRequestReview(PullRequestReview pullRequestReview) { - return new ReviewActivityDto( + public static ReviewActivityDTO fromPullRequestReview(PullRequestReview pullRequestReview) { + return new ReviewActivityDTO( pullRequestReview.getId(), pullRequestReview.isDismissed(), - ReviewActivityDto.fromPullRequestReviewState(pullRequestReview.getState()), + ReviewActivityDTO.fromPullRequestReviewState(pullRequestReview.getState()), pullRequestReview.getComments().size(), UserInfoDTO.fromUser(pullRequestReview.getAuthor()), PullRequestInfoDTO.fromPullRequest(pullRequestReview.getPullRequest()) ); } - public static ReviewActivityDto fromPullRequest(PullRequest pullRequest) { - return new ReviewActivityDto( + public static ReviewActivityDTO fromPullRequest(PullRequest pullRequest) { + return new ReviewActivityDTO( pullRequest.getId(), false, - ReviewActivityStateDto.REVIEW_REQUESTED, + ReviewActivityStateDTO.REVIEW_REQUESTED, 0, UserInfoDTO.fromUser(pullRequest.getAuthor()), PullRequestInfoDTO.fromPullRequest(pullRequest) ); } - public enum ReviewActivityStateDto { + public enum ReviewActivityStateDTO { COMMENTED, APPROVED, CHANGES_REQUESTED, @@ -47,12 +47,12 @@ public enum ReviewActivityStateDto { UNKNOWN; } - public static ReviewActivityStateDto fromPullRequestReviewState(PullRequestReview.State state) { + public static ReviewActivityStateDTO fromPullRequestReviewState(PullRequestReview.State state) { return switch (state) { - case COMMENTED -> ReviewActivityStateDto.COMMENTED; - case APPROVED -> ReviewActivityStateDto.APPROVED; - case CHANGES_REQUESTED -> ReviewActivityStateDto.CHANGES_REQUESTED; - default -> ReviewActivityStateDto.UNKNOWN; + case COMMENTED -> ReviewActivityStateDTO.COMMENTED; + case APPROVED -> ReviewActivityStateDTO.APPROVED; + case CHANGES_REQUESTED -> ReviewActivityStateDTO.CHANGES_REQUESTED; + default -> ReviewActivityStateDTO.UNKNOWN; }; } } \ No newline at end of file