Skip to content

Commit

Permalink
Autowire Converters in WebMVC (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums authored Sep 25, 2024
1 parent 5f050e4 commit 7b9c90c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.tum.in.www1.hephaestus;

import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import de.tum.in.www1.hephaestus.codereview.comment.IssueCommentConverter;
import de.tum.in.www1.hephaestus.codereview.comment.review.PullRequestReviewCommentConverter;
import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestConverter;
import de.tum.in.www1.hephaestus.codereview.pullrequest.review.PullRequestReviewConverter;
import de.tum.in.www1.hephaestus.codereview.repository.RepositoryConverter;
import de.tum.in.www1.hephaestus.codereview.user.UserConverter;

@Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addFormatters(@NonNull FormatterRegistry registry) {
registry.addConverter(new UserConverter());
registry.addConverter(new RepositoryConverter());
registry.addConverter(new PullRequestConverter());
registry.addConverter(new PullRequestReviewConverter());
registry.addConverter(new IssueCommentConverter());
registry.addConverter(new PullRequestReviewCommentConverter());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.kohsuke.github.GHPullRequestQueryBuilder.Sort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -68,23 +69,26 @@ public class GitHubDataSyncService {
private final PullRequestReviewCommentRepository reviewCommentRepository;
private final UserRepository userRepository;

private final RepositoryConverter repositoryConverter;
private final PullRequestConverter pullRequestConverter;
private final PullRequestReviewConverter reviewConverter;
private final IssueCommentConverter commentConverter;
private final PullRequestReviewCommentConverter reviewCommentConverter;
private final UserConverter userConverter;
@Autowired
private RepositoryConverter repositoryConverter;
@Autowired
private PullRequestConverter pullRequestConverter;
@Autowired
private PullRequestReviewConverter reviewConverter;
@Autowired
private IssueCommentConverter commentConverter;
@Autowired
private PullRequestReviewCommentConverter reviewCommentConverter;
@Autowired
private UserConverter userConverter;

private Set<User> users = new HashSet<>();
private Set<PullRequestReview> reviews = new HashSet<>();

public GitHubDataSyncService(RepositoryRepository repositoryRepository, PullRequestRepository pullRequestRepository,
PullRequestReviewRepository prReviewRepository,
IssueCommentRepository commentRepository, PullRequestReviewCommentRepository reviewCommentRepository,
UserRepository userRepository,
RepositoryConverter repositoryConverter, PullRequestConverter pullRequestConverter,
PullRequestReviewConverter reviewConverter, IssueCommentConverter commentConverter,
PullRequestReviewCommentConverter reviewCommentConverter, UserConverter userConverter) {
UserRepository userRepository) {
logger.info("Hello from GitHubDataSyncService!");

this.repositoryRepository = repositoryRepository;
Expand All @@ -93,13 +97,6 @@ public GitHubDataSyncService(RepositoryRepository repositoryRepository, PullRequ
this.commentRepository = commentRepository;
this.reviewCommentRepository = reviewCommentRepository;
this.userRepository = userRepository;

this.repositoryConverter = repositoryConverter;
this.pullRequestConverter = pullRequestConverter;
this.reviewConverter = reviewConverter;
this.commentConverter = commentConverter;
this.reviewCommentConverter = reviewCommentConverter;
this.userConverter = userConverter;
}

public void syncData() {
Expand Down

0 comments on commit 7b9c90c

Please sign in to comment.