diff --git a/src/main/java/org/ntlab/citrusserver/repositories/PublicBookManager.java b/src/main/java/org/ntlab/citrusserver/repositories/PublicBookManager.java index bfd3b7a..a32600b 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/PublicBookManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/PublicBookManager.java @@ -38,7 +38,7 @@ for(Book book : getAllPublicBooks()){ books.add(new BookForSort(book, favoriteManager.getFavorited(book.getAccountId(), book.getBookId()).size())); } - books.sort(Comparator.comparing(BookForSort::favoriteNum)); + books.sort(Comparator.comparing(BookForSort::favoriteNum).reversed()); ArrayList res = new ArrayList<>(); for(BookForSort book : books){ res.add(book.book()); @@ -72,7 +72,7 @@ for(Book book : searchBooksByTitle(title)){ books.add(new BookForSort(book, favoriteManager.getFavorited(book.getAccountId(), book.getBookId()).size())); } - books.sort(Comparator.comparing(BookForSort::favoriteNum)); + books.sort(Comparator.comparing(BookForSort::favoriteNum).reversed()); ArrayList res = new ArrayList<>(); for(BookForSort book : books){ res.add(book.book()); @@ -105,7 +105,7 @@ for(Book book : searchBooksByAccount(accountId)){ books.add(new BookForSort(book, favoriteManager.getFavorited(book.getAccountId(), book.getBookId()).size())); } - books.sort(Comparator.comparing(BookForSort::favoriteNum)); + books.sort(Comparator.comparing(BookForSort::favoriteNum).reversed()); ArrayList res = new ArrayList<>(); for(BookForSort book : books){ res.add(book.book()); @@ -136,7 +136,7 @@ for(Book book : searchBooksByTitleAndAccount(title, accountId)){ books.add(new BookForSort(book, favoriteManager.getFavorited(book.getAccountId(), book.getBookId()).size())); } - books.sort(Comparator.comparing(BookForSort::favoriteNum)); + books.sort(Comparator.comparing(BookForSort::favoriteNum).reversed()); ArrayList res = new ArrayList<>(); for(BookForSort book : books){ res.add(book.book()); @@ -164,6 +164,26 @@ public void bookDeleted(Account account, Book book) { } + +// private List sort(List books, int sortMode){ +// if(sortMode == 0){ +// ArrayList books = getAllPublicBooks(); +// books.sort(Comparator.comparing(Book::getTime).reversed()); +// return books; +// } else if(sortMode == 1){ +// ArrayList books = new ArrayList<>(); +// for(Book book : getAllPublicBooks()){ +// books.add(new BookForSort(book, favoriteManager.getFavorited(book.getAccountId(), book.getBookId()).size())); +// } +// books.sort(Comparator.comparing(BookForSort::favoriteNum).reversed()); +// ArrayList res = new ArrayList<>(); +// for(BookForSort book : books){ +// res.add(book.book()); +// } +// return res; +// } +// } + } record BookForSort(Book book, Integer favoriteNum) {