Search in sources :

Example 6 with ResourceNotFoundException

use of com.rafaelvieira.letmebuy.services.handlers.ResourceNotFoundException in project letmebuy by rafaelrok.

the class CategoryService method update.

@Transactional
public CategoryDTO update(Long id, CategoryDTO dto) {
    try {
        // getOne salva em memoria o objeto para não acessr 2 vezes a base
        Category entity = categoryRepo.getOne(id);
        entity.setName(dto.getName());
        entity = categoryRepo.save(entity);
        return new CategoryDTO(entity);
    } catch (EntityNotFoundException e) {
        throw new ResourceNotFoundException("Categoria não encontrada " + id);
    }
}
Also used : CategoryDTO(com.rafaelvieira.letmebuy.dto.CategoryDTO) Category(com.rafaelvieira.letmebuy.entities.Category) EntityNotFoundException(javax.persistence.EntityNotFoundException) ResourceNotFoundException(com.rafaelvieira.letmebuy.services.handlers.ResourceNotFoundException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ResourceNotFoundException (com.rafaelvieira.letmebuy.services.handlers.ResourceNotFoundException)6 Transactional (org.springframework.transaction.annotation.Transactional)6 EntityNotFoundException (javax.persistence.EntityNotFoundException)3 CategoryDTO (com.rafaelvieira.letmebuy.dto.CategoryDTO)2 ProductDTO (com.rafaelvieira.letmebuy.dto.ProductDTO)2 UserDTO (com.rafaelvieira.letmebuy.dto.UserDTO)2 Category (com.rafaelvieira.letmebuy.entities.Category)2 Product (com.rafaelvieira.letmebuy.entities.Product)2 User (com.rafaelvieira.letmebuy.entities.User)2