mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-01 22:53:29 +08:00
删除书籍功能实现
This commit is contained in:
@@ -169,6 +169,22 @@ public class BookController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "【管理员】删除书籍", notes = "管理员在后台删除书籍")
|
||||
@RequestMapping(value = "delete", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
public CommonReturnType deleteBook(@RequestParam(value = "token", required = false) String token,
|
||||
@RequestParam(required = true, value = "id") Integer bookId) throws BusinessException {
|
||||
// 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断
|
||||
UserModel userModel = userService.getUserByToken(redisTemplate, token);
|
||||
|
||||
Integer affectRows = bookService.deleteBook(bookId);
|
||||
if (affectRows > 0) {
|
||||
return CommonReturnType.create("success");
|
||||
} else {
|
||||
return CommonReturnType.create("failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private BookVO convertFromModel(BookModel bookModel) {
|
||||
BookVO bookVO = new BookVO();
|
||||
|
@@ -35,6 +35,11 @@ public class BookServiceImpl implements BookService {
|
||||
@Autowired
|
||||
ValidatorImpl validator;
|
||||
|
||||
/**
|
||||
* 通过 书籍id 查找图书
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public BookModel getBookById(Integer id) {
|
||||
@@ -44,6 +49,12 @@ public class BookServiceImpl implements BookService {
|
||||
return bookModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找图书
|
||||
* @param bookModel
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
@Override
|
||||
public List<BookModel> searchBooks(BookModel bookModel) throws BusinessException {
|
||||
|
||||
@@ -72,6 +83,12 @@ public class BookServiceImpl implements BookService {
|
||||
return convertFromDataObjecctList(bookDOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加图书
|
||||
* @param bookModel
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
@Override
|
||||
public Integer addBook(BookModel bookModel) throws BusinessException {
|
||||
// 校验入参
|
||||
@@ -84,6 +101,12 @@ public class BookServiceImpl implements BookService {
|
||||
return bookDOMapper.insertSelective(bookDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改图书信息
|
||||
* @param bookModel
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
@Override
|
||||
public Integer modifyBook(BookModel bookModel) throws BusinessException {
|
||||
// 校验入参
|
||||
@@ -96,6 +119,20 @@ public class BookServiceImpl implements BookService {
|
||||
return bookDOMapper.updateByPrimaryKeySelective(bookDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 id 删除图书
|
||||
* @param bookId
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
@Override
|
||||
public Integer deleteBook(Integer bookId) throws BusinessException {
|
||||
if(bookId == null || bookId == 0) {
|
||||
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "书籍id不能为空");
|
||||
}
|
||||
return bookDOMapper.deleteByPrimaryKey(bookId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户收藏书籍
|
||||
*
|
||||
|
@@ -39,6 +39,14 @@ public interface BookService {
|
||||
*/
|
||||
Integer modifyBook(BookModel bookModel) throws BusinessException;
|
||||
|
||||
/**
|
||||
* 删除书籍信息
|
||||
* @param bookId
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
Integer deleteBook(Integer bookId) throws BusinessException;
|
||||
|
||||
/**
|
||||
* 用户收藏书籍
|
||||
*
|
||||
|
Reference in New Issue
Block a user