Skip to content

Commit

Permalink
#140: Update to DTO
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-flo committed Nov 25, 2024
1 parent 3e6a6c0 commit 29f303c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -36,7 +36,7 @@ public List<Integrator> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
public record ActivityDTO(
@NonNull List<PullRequestInfoDTO> pullRequests,
@NonNull List<IssueInfoDTO> issues,
@NonNull List<ReviewActivityDto> reviews) {
@NonNull List<ReviewActivityDTO> reviews) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,7 +41,7 @@ public ActivityDTO getActivity(String login) {
.map(IssueInfoDTO::fromIssue)
.toList();

List<ReviewActivityDto> reviews = getReviewedOrRequestedPullRequests(login);
List<ReviewActivityDTO> reviews = getReviewedOrRequestedPullRequests(login);

return new ActivityDTO(
openPullRequests,
Expand All @@ -53,15 +50,15 @@ public ActivityDTO getActivity(String login) {
);
}

private List<ReviewActivityDto> getReviewedOrRequestedPullRequests(String login) {
List<ReviewActivityDto> reviews = pullRequestReviewRepository.findAllOpenReviewsByAuthorLogin(login)
private List<ReviewActivityDTO> getReviewedOrRequestedPullRequests(String login) {
List<ReviewActivityDTO> reviews = pullRequestReviewRepository.findAllOpenReviewsByAuthorLogin(login)
.stream()
.map(ReviewActivityDto::fromPullRequestReview)
.map(ReviewActivityDTO::fromPullRequestReview)
.toList();

List<ReviewActivityDto> requestedReviews = pullRequestRepository.findReviewRequestedByLogin(login)
List<ReviewActivityDTO> requestedReviews = pullRequestRepository.findReviewRequestedByLogin(login)
.stream()
.map(ReviewActivityDto::fromPullRequest)
.map(ReviewActivityDTO::fromPullRequest)
.toList();

requestedReviews.addAll(reviews);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,50 @@
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,
REVIEW_REQUESTED,
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;
};
}
}

0 comments on commit 29f303c

Please sign in to comment.