@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)); }
@Override public BlogTO updateBlog(BlogTO blogTO) { BlogDO blogDO = blogRepository.findOne(blogTO.getId()); blogConverter.convertTOIntoEntity(blogTO, blogDO); return blogConverter.convertEntityIntoTO(blogRepository.save(blogDO), blogTO); }