#19 - Add filter by author

merge-requests/16/head
Anton Romanov 3 years ago
parent 7c59b3630c
commit 3cdc712a2c

@ -29,6 +29,7 @@ public class GitFilteringController {
private final static int DEFAULT_PAGE_SIZE = 20;
private final FilteringService filteringService;
public GitFilteringController(FilteringService filteringService) {
this.filteringService = filteringService;
}
@ -43,9 +44,11 @@ public class GitFilteringController {
@RequestParam String branchName) {
int currentPage = page.orElse(1);
int pageSize = size.orElse(DEFAULT_PAGE_SIZE);
String author = "Anton Romanov";
Page<Commit> commitsPage = filteringService.getCommits(repositoryUrl,
branchName,
author,
new OffsetablePageRequest(currentPage - 1, pageSize));
int totalPages = commitsPage.getTotalPages();
if (totalPages > 0) {
@ -61,4 +64,24 @@ public class GitFilteringController {
model.addAttribute("authors", filteringService.getRepositoryAuthors(repositoryUrl, branchName));
return FILTER_COMMITS;
}
// @RequestMapping(value = FILTER_COMMITS, method = RequestMethod.POST)
// public ModelAndView listFilterCommits(
// Model model,
// @ModelAttribute FilterForm filterForm) {
// Page<Commit> commitsPage = filteringService.getCommits(filterForm.getUrl(),
// filterForm.getBranch(),
// new OffsetablePageRequest(0, DEFAULT_PAGE_SIZE));
// int totalPages = commitsPage.getTotalPages();
// if (totalPages > 0) {
// List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
// .boxed()
// .collect(Collectors.toList());
// model.addAttribute("pageNumbers", pageNumbers);
// }
// filterForm.setCommitsPage(commitsPage);
// model.addAttribute("filterForm", filterForm);
// model.addAttribute("authors", filteringService.getRepositoryAuthors(filterForm.getUrl(), filterForm.getBranch()));
// return new ModelAndView()FILTER_COMMITS + "?repositoryUrl="+filterForm.getUrl() + "&branchName=" +filterForm.getBranch() ;
// }
}

@ -19,8 +19,8 @@ import ru.ulstu.extractor.model.Repository;
import java.util.List;
public interface CommitRepository extends JpaRepository<Commit, Integer> {
@Query("SELECT c FROM Commit c, Repository r, Branch b WHERE c.branch = b AND r = b.repository AND r = :repository AND b.name = :branchName")
Page<Commit> findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName);
@Query("SELECT c FROM Commit c, Repository r, Branch b, Author a WHERE c.branch = b AND r = b.repository AND a = c.author AND r = :repository AND b.name = :branchName AND a.name = :author")
Page<Commit> findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName, @Param("author") String author);
@Query("SELECT new ru.ulstu.extractor.model.CommitAuthorStatistic(c.author.name, COUNT(DISTINCT c.hash)) FROM Commit c GROUP by c.author.name")
List<CommitAuthorStatistic> getCommitAuthorStatistic();

@ -40,11 +40,13 @@ public class FilteringService {
public Page<Commit> getCommits(@NotNull String repositoryUrl,
@NotNull String branchName,
@NotNull String author,
Pageable pageable) {
return commitRepository.findByRepositoryAndBranch(
pageable,
repositoryRepository.findByUrl(repositoryUrl),
branchName
branchName,
author
);
}

@ -74,6 +74,7 @@
</div>
<input type="hidden" th:field="*{url}">
<input type="hidden" th:field="*{branch}">
<table class="table table-striped">
<thead class="thead-dark">
<tr>

Loading…
Cancel
Save