Esempio 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));
 }
Esempio 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);
 }
Esempio 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());
  }
Esempio n. 4
0
 @Override
 public void deleteBlog(Integer id) {
   blogRepository.delete(id);
 }
Esempio 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);
 }