Merge branch '10-create-author-table' into 'master'
Resolve "Создание и вывод таблицы с автором и датой" Closes #10 See merge request romanov73/git-extractor!7merge-requests/9/head
commit
7a9b174f3b
@ -0,0 +1,40 @@
|
||||
package ru.ulstu.extractor.service;
|
||||
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.extractor.model.Commit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CommitService {
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public CommitService(GitRepositoryService gitRepositoryService) {
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
public Page<Commit> findPaginated(Pageable pageable, String url) throws GitAPIException, IOException {
|
||||
int pageSize = pageable.getPageSize();
|
||||
int currentPage = pageable.getPageNumber();
|
||||
int startItem = currentPage * pageSize;
|
||||
List<Commit> commits = gitRepositoryService.getCommits(url);
|
||||
;
|
||||
|
||||
if (commits.size() < startItem) {
|
||||
commits = Collections.emptyList();
|
||||
} else {
|
||||
int toIndex = Math.min(startItem + pageSize, commits.size());
|
||||
commits = commits.subList(startItem, toIndex);
|
||||
}
|
||||
return new PageImpl<>(commits, PageRequest.of(currentPage, pageSize), commits.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue