use of org.springside.examples.bootapi.domain.Book in project springside4 by springside.
the class BookBorrowService method markBookReturned.
@Transactional
public void markBookReturned(Long id, Account owner) {
Book book = bookDao.findOne(id);
if (!book.status.equals(Book.STATUS_OUT)) {
logger.error("User return the book not out, user id:" + owner.id + ",book id:" + id + ",status:" + book.status);
throw new ServiceException("The book is not borrowing", ErrorCode.BOOK_STATUS_WRONG);
}
if (!owner.id.equals(book.owner.id)) {
logger.error("User return the book not himself, user id:" + owner.id + ",book id:" + id + ",owner id" + book.owner.id);
throw new ServiceException("User can't make others book returned", ErrorCode.BOOK_OWNERSHIP_WRONG);
}
book.status = Book.STATUS_IDLE;
book.borrowDate = null;
book.borrower = null;
bookDao.save(book);
Message message = new Message(book.borrower, String.format("Mark book <%s> returned by %s", book.title, owner.name), ClockUtil.currentDate());
messageDao.save(message);
}
use of org.springside.examples.bootapi.domain.Book in project springside4 by springside.
the class BookDaoTest method findByOwnerId.
@Test
public void findByOwnerId() {
List<Book> books = bookDao.findByOwnerId(1L, new PageRequest(0, 10));
assertThat(books).hasSize(2);
assertThat(books.get(0).title).isEqualTo("Big Data日知录");
}
use of org.springside.examples.bootapi.domain.Book in project springside4 by springside.
the class BookDaoTest method findByBorrowerId.
@Test
public void findByBorrowerId() {
List<Book> books = bookDao.findByBorrowerId(1L, new PageRequest(0, 10));
assertThat(books).hasSize(0);
}
use of org.springside.examples.bootapi.domain.Book in project springside4 by springside.
the class BookEndpoint method modifyBook.
@RequestMapping(value = "/api/books/{id}/modify", method = RequestMethod.POST, consumes = MediaTypes.JSON_UTF_8)
public void modifyBook(@RequestBody BookDto bookDto, @RequestParam(value = "token", required = false) String token) {
checkToken(token);
Account currentUser = accountService.getLoginUser(token);
Book book = BeanMapper.map(bookDto, Book.class);
adminService.modifyBook(book, currentUser.id);
}
use of org.springside.examples.bootapi.domain.Book in project springside4 by springside.
the class BookEndpoint method listMyBorrowedBook.
@RequestMapping(value = "/api/myborrowedbook", produces = MediaTypes.JSON_UTF_8)
public List<BookDto> listMyBorrowedBook(@RequestParam(value = "token", required = false) String token, Pageable pageable) {
checkToken(token);
Account currentUser = accountService.getLoginUser(token);
List<Book> books = borrowService.listMyBorrowedBook(currentUser.id, pageable);
return BeanMapper.mapList(books, Book.class, BookDto.class);
}
Aggregations