sort papers
This commit is contained in:
parent
294ed1838a
commit
e9d81fef48
@ -12,7 +12,7 @@ import java.util.List;
|
|||||||
@Entity
|
@Entity
|
||||||
public class Paper extends BaseEntity {
|
public class Paper extends BaseEntity {
|
||||||
public enum PaperStatus {
|
public enum PaperStatus {
|
||||||
DRAFT("Черновик"), ON_PREPARATION("На подготовке"), COMPLETED("Завершена"), ATTENTION("Обратить внимание");
|
ATTENTION("Обратить внимание"), ON_PREPARATION("На подготовке"), DRAFT("Черновик"), COMPLETED("Завершена");
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ -3,5 +3,7 @@ package ru.ulstu.paper.repository;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface PaperRepository extends JpaRepository<Paper, Integer> {
|
public interface PaperRepository extends JpaRepository<Paper, Integer> {
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,9 @@ import ru.ulstu.paper.model.PaperDto;
|
|||||||
import ru.ulstu.paper.repository.PaperRepository;
|
import ru.ulstu.paper.repository.PaperRepository;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
@ -25,7 +27,17 @@ public class PaperService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<PaperDto> findAll() {
|
public List<PaperDto> findAll() {
|
||||||
return convert(paperRepository.findAll(), PaperDto::new);
|
List<Paper> allPapers = paperRepository.findAll();
|
||||||
|
allPapers = allPapers.stream().sorted((paper1, paper2) -> {
|
||||||
|
int statusCompareResult =
|
||||||
|
Integer.valueOf(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper1.getStatus()))
|
||||||
|
.compareTo(Integer.valueOf(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper2.getStatus())));
|
||||||
|
if (statusCompareResult != 0) {
|
||||||
|
return statusCompareResult;
|
||||||
|
}
|
||||||
|
return paper1.getTitle().compareTo(paper2.getTitle());
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return convert(allPapers, PaperDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
Loading…
Reference in New Issue
Block a user