use of com.github.lybgeek.swagger.dto.BookDTO in project springboot-learning by lyb-geek.
the class BookController method upadteBook.
@PostMapping(value = "/update")
@ApiOperation(value = "更新书籍", notes = "更新书籍")
public Result<BookDTO> upadteBook(BookDTO bookDTO) {
Result<BookDTO> result = new Result<>();
if (bookDTO.getId() == null) {
result.setStatus(Result.fail);
result.setMessage("id不能为空");
return result;
}
BookDTO book = bookService.editBook(bookDTO);
result.setData(book);
return result;
}
use of com.github.lybgeek.swagger.dto.BookDTO in project springboot-learning by lyb-geek.
the class BookServiceImpl method addBook.
@Override
@Transactional
public // @DS("follow")
BookDTO addBook(BookDTO bookDTO) {
Book book = dozerMapper.map(bookDTO, Book.class);
boolean isExitBookByName = ObjectUtils.isNotEmpty(getBookByName(bookDTO.getBookName()));
if (isExitBookByName) {
throw new BizException("书名已经存在");
}
book.setCreateDate(new Date());
book.setUpdateDate(new Date());
baseMapper.insert(book);
bookDTO = dozerMapper.map(book, BookDTO.class);
return bookDTO;
}
use of com.github.lybgeek.swagger.dto.BookDTO in project springboot-learning by lyb-geek.
the class BookServiceImpl method pageBook.
@Override
public PageResult<BookDTO> pageBook(PageQuery<BookDTO> pageQuery) {
BookDTO bookDTO = pageQuery.getQueryParams();
Wrapper<Book> wrapper = wrapperQueryCondition(bookDTO);
IPage<Book> page = new Page<>(pageQuery.getPageNo(), pageQuery.getPageSize());
IPage<Book> bookIPage = baseMapper.selectPage(page, wrapper);
if (bookIPage != null) {
List<BookDTO> bookDTOS = new ArrayList<>();
if (CollectionUtils.isNotEmpty(bookIPage.getRecords())) {
bookDTOS = BeanMapperUtils.mapList(bookIPage.getRecords(), BookDTO.class);
}
return PageUtil.INSTANCE.getPage(bookIPage, bookDTOS);
}
return null;
}
use of com.github.lybgeek.swagger.dto.BookDTO in project springboot-learning by lyb-geek.
the class BookControllerTest method testAddBook.
@Test
public void testAddBook() throws Exception {
BookDTO params = BookDTO.builder().bookName("测试驱动").author("张三").price(BigDecimal.valueOf(20.1)).stock(10).build();
log.info("params", params);
String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/1.0.0/book/add").header(Constant.ACCESS_TOKEN, Constant.ACCESS_TOKEN_PASS_VALUE).param("bookName", "测试驱动").param("author", "战三").param("price", "20.1").param("stock", "10").contentType(MediaType.APPLICATION_FORM_URLENCODED).characterEncoding("utf-8")).andExpect(MockMvcResultMatchers.status().isOk()).andReturn().getResponse().getContentAsString();
log.info("输出结构化日志", "result", result);
}
use of com.github.lybgeek.swagger.dto.BookDTO in project springboot-learning by lyb-geek.
the class BookController method addBook.
@PostMapping(value = "/add")
@ApiOperation(value = "添加书籍", notes = "添加书籍")
public Result<BookDTO> addBook(@Valid BookDTO bookDTO, BindingResult bindingResult) {
Result<BookDTO> result = new Result<>();
if (bindingResult.hasErrors()) {
return ResultUtil.INSTANCE.getFailResult(bindingResult, result);
}
try {
BookDTO book = bookService.addBook(bookDTO);
result.setData(book);
} catch (Exception e) {
log.error("addBook error:" + e.getMessage(), e);
result.setStatus(Result.fail);
result.setMessage(e.getMessage());
}
return result;
}
Aggregations