Search in sources :

Example 1 with DuplicatedCategoryException

use of com.tvd12.ezydata.example.jpa.exception.DuplicatedCategoryException in project ezyfox-examples by tvd12.

the class CategoryService method saveCategory.

public CategoryData saveCategory(AddCategoryData data) {
    final Category existedCategory = categoryRepository.findByName(data.getCategoryName());
    if (existedCategory != null) {
        throw new DuplicatedCategoryException("category named: " + data.getCategoryName() + " existed");
    }
    final Category entity = dataToEntityConverter.toEntity(data);
    categoryRepository.save(entity);
    return entityToDataConverter.toData(entity);
}
Also used : DuplicatedCategoryException(com.tvd12.ezydata.example.jpa.exception.DuplicatedCategoryException) Category(com.tvd12.ezydata.example.jpa.entity.Category)

Aggregations

Category (com.tvd12.ezydata.example.jpa.entity.Category)1 DuplicatedCategoryException (com.tvd12.ezydata.example.jpa.exception.DuplicatedCategoryException)1