fix likes filtration
This commit is contained in:
parent
a64bb9104e
commit
38823a4479
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
SpringApp/data.mv.db
|
SpringApp/data.mv.db
|
||||||
SpringApp/library/data.mv.db
|
SpringApp/library/data.mv.db
|
||||||
SpringApp/library/data.trace.db
|
SpringApp/library/data.trace.db
|
||||||
|
SpringApp/data.trace.db
|
||||||
|
@ -52,8 +52,14 @@ public class BookEntity extends BaseEntity {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BookEntity(boolean isChosen) {
|
public BookEntity(BookEntity book, boolean isChosen) {
|
||||||
this.isChosen = isChosen;
|
this.isChosen = isChosen;
|
||||||
|
this.name = book.name;
|
||||||
|
this.type = book.type;
|
||||||
|
this.authorsBooks =book.authorsBooks;
|
||||||
|
this.fans = book.fans;
|
||||||
|
this.fansNumber = book.fansNumber;
|
||||||
|
this.id = book.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeEntity getType() {
|
public TypeEntity getType() {
|
||||||
|
@ -16,10 +16,27 @@ public interface BookRepository extends
|
|||||||
PagingAndSortingRepository<BookEntity, Long> {
|
PagingAndSortingRepository<BookEntity, Long> {
|
||||||
Optional<BookEntity> findByNameIgnoreCase(String name);
|
Optional<BookEntity> findByNameIgnoreCase(String name);
|
||||||
|
|
||||||
|
@Query(
|
||||||
|
"select new com.ip.library.controllers.books.BookEntity(b, " +
|
||||||
|
"case when f.id.bookId is null then false else true end) " +
|
||||||
|
"from BookEntity b left join FavoriteEntity f " +
|
||||||
|
"on b.id = f.id.bookId and f.user.id = ?1 " +
|
||||||
|
"order by b.id")
|
||||||
|
Page<BookEntity> findAll(long userId, Pageable pageable);
|
||||||
|
|
||||||
List<BookEntity> findByTypeId(long typeId);
|
List<BookEntity> findByTypeId(long typeId);
|
||||||
|
|
||||||
Page<BookEntity> findByTypeId(long typeId, Pageable pageable);
|
Page<BookEntity> findByTypeId(long typeId, Pageable pageable);
|
||||||
|
|
||||||
|
@Query(
|
||||||
|
"select new com.ip.library.controllers.books.BookEntity(b, " +
|
||||||
|
"case when f.id.bookId is null then false else true end) " +
|
||||||
|
"from BookEntity b left join FavoriteEntity f " +
|
||||||
|
"on b.id = f.id.bookId and f.user.id = ?2 " +
|
||||||
|
"where b.type.id = ?1 " +
|
||||||
|
"order by b.id")
|
||||||
|
Page<BookEntity> findByTypeId(long typeId, long userId, Pageable pageable);
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"select ab.book " +
|
"select ab.book " +
|
||||||
"from AuthorsBooksEntity ab " +
|
"from AuthorsBooksEntity ab " +
|
||||||
@ -34,6 +51,16 @@ public interface BookRepository extends
|
|||||||
"order by ab.book.id")
|
"order by ab.book.id")
|
||||||
Page<BookEntity> findByAuthorId(Long authorId, Pageable pageable);
|
Page<BookEntity> findByAuthorId(Long authorId, Pageable pageable);
|
||||||
|
|
||||||
|
@Query(
|
||||||
|
"select new com.ip.library.controllers.books.BookEntity(b, " +
|
||||||
|
"case when f.id.bookId is null then false else true end) " +
|
||||||
|
"from BookEntity b " +
|
||||||
|
"left join FavoriteEntity f on b.id = f.id.bookId and f.user.id = ?2 " +
|
||||||
|
"left join AuthorsBooksEntity ab on b.id = ab.id.bookId " +
|
||||||
|
"where ab.id.authorId = ?1 " +
|
||||||
|
"order by b.id")
|
||||||
|
Page<BookEntity> findByAuthorId(Long authorId, long userId, Pageable pageable);
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"select ab.book " +
|
"select ab.book " +
|
||||||
"from AuthorsBooksEntity ab " +
|
"from AuthorsBooksEntity ab " +
|
||||||
@ -50,6 +77,16 @@ public interface BookRepository extends
|
|||||||
"order by ab.book.id")
|
"order by ab.book.id")
|
||||||
Page<BookEntity> findByAuthorIdAndTypeId(Long authorId, Long typeId, Pageable pageable);
|
Page<BookEntity> findByAuthorIdAndTypeId(Long authorId, Long typeId, Pageable pageable);
|
||||||
|
|
||||||
|
@Query(
|
||||||
|
"select new com.ip.library.controllers.books.BookEntity(b, " +
|
||||||
|
"case when f.id.bookId is null then false else true end) " +
|
||||||
|
"from BookEntity b " +
|
||||||
|
"left join FavoriteEntity f on b.id = f.id.bookId and f.user.id = ?3 " +
|
||||||
|
"left join AuthorsBooksEntity ab on b.id = ab.id.bookId " +
|
||||||
|
"where ab.id.authorId = ?1 and b.type.id = ?2 " +
|
||||||
|
"order by b.id")
|
||||||
|
Page<BookEntity> findByAuthorIdAndTypeId(Long authorId, Long typeId, long userId, Pageable pageable);
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"select count(*) as number " +
|
"select count(*) as number " +
|
||||||
"from FavoriteEntity f " +
|
"from FavoriteEntity f " +
|
||||||
|
@ -62,26 +62,16 @@ public class BookService {
|
|||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public Page<BookEntity> getAll(long typeId, long authorId, long userId, int page, int size) {
|
public Page<BookEntity> getAll(long typeId, long authorId, long userId, int page, int size) {
|
||||||
PageRequest pageRequest = PageRequest.of(page, size);
|
PageRequest pageRequest = PageRequest.of(page, size);
|
||||||
Page<BookEntity> result = null;
|
|
||||||
if (typeId <= 0L && authorId <= 0L) {
|
if (typeId <= 0L && authorId <= 0L) {
|
||||||
result = bookRepository.findAll(pageRequest);
|
return bookRepository.findAll(userId, pageRequest);
|
||||||
}
|
}
|
||||||
else if (authorId <= 0L){
|
else if (authorId <= 0L){
|
||||||
result = bookRepository.findByTypeId(typeId, pageRequest);
|
return bookRepository.findByTypeId(typeId, userId, pageRequest);
|
||||||
}
|
}
|
||||||
else if (typeId <= 0L) {
|
else if (typeId <= 0L) {
|
||||||
result = bookRepository.findByAuthorId(authorId, pageRequest);
|
return bookRepository.findByAuthorId(authorId, userId, pageRequest);
|
||||||
}
|
}
|
||||||
else {
|
return bookRepository.findByAuthorIdAndTypeId(authorId, typeId, userId, pageRequest);
|
||||||
result = bookRepository.findByAuthorIdAndTypeId(authorId, typeId, pageRequest);
|
|
||||||
}
|
|
||||||
List<BookEntity> favorites = getUserFavorities(userId);
|
|
||||||
for (BookEntity book : result.getContent()) {
|
|
||||||
if (favorites.contains(book)) {
|
|
||||||
book.setIsChosen(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
|
Loading…
Reference in New Issue
Block a user