use of com.rafaelvieira.letmebuy.services.handlers.ResourceNotFoundException in project letmebuy by rafaelrok.
the class ProductService method findById.
@Transactional(readOnly = true)
public ProductDTO findById(Long id) {
Optional<Product> obj = productRepo.findById(id);
Product entity = obj.orElseThrow(() -> new ResourceNotFoundException("Produto não encontrada"));
return new ProductDTO(entity, entity.getCategories());
}
use of com.rafaelvieira.letmebuy.services.handlers.ResourceNotFoundException in project letmebuy by rafaelrok.
the class ProductService method update.
@Transactional
public ProductDTO update(Long id, ProductDTO dto) {
try {
// getOne salva em memoria o objeto para não acessr 2 vezes a base
Product entity = productRepo.getOne(id);
copyDtoToEntity(dto, entity);
entity = productRepo.save(entity);
return new ProductDTO(entity);
} catch (EntityNotFoundException e) {
throw new ResourceNotFoundException("Produto não encontrada " + id);
}
}
use of com.rafaelvieira.letmebuy.services.handlers.ResourceNotFoundException in project letmebuy by rafaelrok.
the class UserService method update.
@Transactional
public UserDTO update(Long id, UserUpdateDTO dto) {
try {
User entity = repository.getOne(id);
copyDtoToEntity(dto, entity);
entity = repository.save(entity);
return new UserDTO(entity);
} catch (EntityNotFoundException e) {
throw new ResourceNotFoundException("Id not found " + id);
}
}
use of com.rafaelvieira.letmebuy.services.handlers.ResourceNotFoundException in project letmebuy by rafaelrok.
the class UserService method findById.
@Transactional(readOnly = true)
public UserDTO findById(Long id) {
authService.validateSelfOrAdmin(id);
Optional<User> obj = repository.findById(id);
User entity = obj.orElseThrow(() -> new ResourceNotFoundException("Entity not found"));
return new UserDTO(entity);
}
use of com.rafaelvieira.letmebuy.services.handlers.ResourceNotFoundException in project letmebuy by rafaelrok.
the class CategoryService method findById.
@Transactional(readOnly = true)
public CategoryDTO findById(Long id) {
Optional<Category> obj = categoryRepo.findById(id);
Category entity = obj.orElseThrow(() -> new ResourceNotFoundException("Categoria não encontrada"));
return new CategoryDTO(entity);
}
Aggregations