Search in sources :

Example 1 with BookDTO

use of com.github.lybgeek.spilt.dto.BookDTO in project springboot-learning by lyb-geek.

the class BookController method addBook.

@PostMapping(value = "/add")
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;
}
Also used : BookDTO(com.github.lybgeek.spilt.dto.BookDTO) Result(com.github.lybgeek.common.model.Result) PageResult(com.github.lybgeek.common.model.PageResult) BindingResult(org.springframework.validation.BindingResult) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with BookDTO

use of com.github.lybgeek.spilt.dto.BookDTO in project springboot-learning by lyb-geek.

the class SplitTableApplicationTest method testListBook.

@Test
public void testListBook() {
    BookDTO bookDTO = new BookDTO();
    bookDTO.setAuthor("张三");
    bookDTO.setBookName("docker");
    // bookDTO.setId(5L);
    List<BookDTO> bookDTOS = bookService.listBooks(bookDTO);
    if (CollectionUtils.isNotEmpty(bookDTOS)) {
        bookDTOS.forEach(book -> System.out.println(book));
    }
}
Also used : BookDTO(com.github.lybgeek.spilt.dto.BookDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with BookDTO

use of com.github.lybgeek.spilt.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;
}
Also used : BookDTO(com.github.lybgeek.spilt.dto.BookDTO) Book(com.github.lybgeek.spilt.model.Book) BizException(com.github.lybgeek.common.exception.BizException) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with BookDTO

use of com.github.lybgeek.spilt.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;
}
Also used : BookDTO(com.github.lybgeek.spilt.dto.BookDTO) Book(com.github.lybgeek.spilt.model.Book) ArrayList(java.util.ArrayList) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage)

Example 5 with BookDTO

use of com.github.lybgeek.spilt.dto.BookDTO in project springboot-learning by lyb-geek.

the class BookServiceImpl method getBookById.

@Override
public BookDTO getBookById(Long id) {
    Book dbBook = baseMapper.selectById(id);
    BookDTO bookDTO = dozerMapper.map(dbBook, BookDTO.class);
    return bookDTO;
}
Also used : BookDTO(com.github.lybgeek.spilt.dto.BookDTO) Book(com.github.lybgeek.spilt.model.Book)

Aggregations

BookDTO (com.github.lybgeek.spilt.dto.BookDTO)7 Book (com.github.lybgeek.spilt.model.Book)3 PageResult (com.github.lybgeek.common.model.PageResult)2 Result (com.github.lybgeek.common.model.Result)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 BindingResult (org.springframework.validation.BindingResult)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 BizException (com.github.lybgeek.common.exception.BizException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Transactional (org.springframework.transaction.annotation.Transactional)1