Exemplo n.º 1
0
 @Override
 public BlogTO getBlog(Integer id) {
   return Optional.ofNullable(blogRepository.findOne(id))
       .map(blog -> this.setVoteCounter(blog))
       .map(blog -> blogConverter.convertEntityIntoTO(blog, new BlogTO()))
       .orElseThrow(() -> new IllegalArgumentException("There's no blog with the ID" + id));
 }
Exemplo n.º 2
0
 @Override
 public BlogTO createBlog(BlogTO blogTO) {
   CustomerTO customer = customerService.getCustomer(blogTO.getCustomer().getId());
   blogTO.setCustomer(customer);
   BlogDO savedDO = blogRepository.save(blogConverter.convertTOIntoEntity(blogTO, new BlogDO()));
   return blogConverter.convertEntityIntoTO(savedDO, blogTO);
 }
Exemplo n.º 3
0
  @Override
  public List<BlogTO> getAll() {
    List<BlogDO> blogs = (List<BlogDO>) blogRepository.findAll();

    return blogs
        .parallelStream()
        .map(blog -> this.setVoteCounter(blog))
        .map(blog -> blogConverter.convertEntityIntoTO(blog, new BlogTO()))
        .collect(Collectors.toList());
  }
Exemplo n.º 4
0
 @Override
 public void deleteBlog(Integer id) {
   blogRepository.delete(id);
 }
Exemplo n.º 5
0
 @Override
 public BlogTO updateBlog(BlogTO blogTO) {
   BlogDO blogDO = blogRepository.findOne(blogTO.getId());
   blogConverter.convertTOIntoEntity(blogTO, blogDO);
   return blogConverter.convertEntityIntoTO(blogRepository.save(blogDO), blogTO);
 }