sort filtered papers

This commit is contained in:
Anton Romanov 2018-12-18 23:02:48 +04:00
parent 7dc34e1a82
commit fbaaac3a91

View File

@ -47,15 +47,7 @@ public class PaperService {
}
public List<Paper> findAll() {
return paperRepository.findAll().stream().sorted((paper1, paper2) -> {
int statusCompareResult =
Integer.valueOf(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper1.getStatus()))
.compareTo(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper2.getStatus()));
if (statusCompareResult != 0) {
return statusCompareResult;
}
return paper1.getTitle().compareTo(paper2.getTitle());
}).collect(Collectors.toList());
return sortPapers(paperRepository.findAll());
}
public List<PaperDto> findAllDto() {
@ -145,9 +137,21 @@ public class PaperService {
}
public List<PaperDto> filter(PaperFilterDto filterDto) {
return convert(paperRepository.filter(
return convert(sortPapers(paperRepository.filter(
filterDto.getFilterAuthorId() == null ? null : userService.findById(filterDto.getFilterAuthorId()),
filterDto.getYear()), PaperDto::new);
filterDto.getYear())), PaperDto::new);
}
private List<Paper> sortPapers(List<Paper> papers) {
return papers.stream().sorted((paper1, paper2) -> {
int statusCompareResult =
Integer.valueOf(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper1.getStatus()))
.compareTo(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper2.getStatus()));
if (statusCompareResult != 0) {
return statusCompareResult;
}
return paper1.getTitle().compareTo(paper2.getTitle());
}).collect(Collectors.toList());
}
public PaperDto findPaper(int id) {