#16 -- Show commits page
parent
cf9f4ea82b
commit
c89a27d495
@ -0,0 +1,93 @@
|
||||
package ru.ulstu.extractor.model;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class OffsetablePageRequest implements Pageable, Serializable {
|
||||
private final int offset;
|
||||
private final int count;
|
||||
private final Sort sort;
|
||||
|
||||
public OffsetablePageRequest(int page, long pageSize) {
|
||||
this(pageSize * page, pageSize, Sort.by("id"));
|
||||
}
|
||||
|
||||
public OffsetablePageRequest(long offset, long count, Sort sort) {
|
||||
if (offset < 0) {
|
||||
throw new IllegalArgumentException("Offset value must not be less than zero!");
|
||||
}
|
||||
if (count < 1) {
|
||||
throw new IllegalArgumentException("Count value must not be less than one!");
|
||||
}
|
||||
this.offset = (int) offset;
|
||||
this.count = (int) count;
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sort getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPageSize() {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPageNumber() {
|
||||
return offset / count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return offset > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pageable next() {
|
||||
return new OffsetablePageRequest(getOffset() + getPageSize(), getPageSize(), getSort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pageable previousOrFirst() {
|
||||
return hasPrevious() ? previous() : first();
|
||||
}
|
||||
|
||||
public Pageable previous() {
|
||||
return getOffset() == 0 ? this : new OffsetablePageRequest(getOffset() - getPageSize(), getPageSize(), getSort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pageable first() {
|
||||
return new OffsetablePageRequest(0, getPageSize(), getSort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final OffsetablePageRequest other = (OffsetablePageRequest) obj;
|
||||
return this.offset == other.offset && this.count == other.count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + offset;
|
||||
result = prime * result + count;
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package ru.ulstu.extractor.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import ru.ulstu.extractor.model.Author;
|
||||
import ru.ulstu.extractor.model.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AuthorRepository extends JpaRepository<Author, Integer> {
|
||||
@Query("SELECT a FROM Commit c, Repository r, Branch b, Author a WHERE c.author = a AND c.branch = b AND r = b.repository AND r = :repository AND b.name = :branchName")
|
||||
List<Author> findByRepositoryAndBranch(@Param("repository") Repository repository, @Param("branchName") String branchName);
|
||||
}
|
@ -1,7 +1,14 @@
|
||||
package ru.ulstu.extractor.repository;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import ru.ulstu.extractor.model.Commit;
|
||||
import ru.ulstu.extractor.model.Repository;
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -1,32 +1,13 @@
|
||||
package ru.ulstu.extractor.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.extractor.model.Commit;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class FilteringService {
|
||||
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
|
||||
public FilteringService(GitRepositoryService gitRepositoryService) {
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
}
|
||||
|
||||
public List<Commit> getCommits(String urlRepo) {
|
||||
return getCommits(urlRepo, null);
|
||||
}
|
||||
private final IndexService indexService;
|
||||
|
||||
public List<Commit> getCommits(String urlRepo, String filterCommitMessage) {
|
||||
if (filterCommitMessage != null) {
|
||||
return getCommits(urlRepo)
|
||||
.stream()
|
||||
.filter(commit -> commit.getMessage().contains(filterCommitMessage))
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
return getCommits(urlRepo);
|
||||
}
|
||||
public FilteringService(IndexService indexService) {
|
||||
this.indexService = indexService;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue