use of com.tvd12.ezydata.example.jpa.data.CategoryData 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);
}
use of com.tvd12.ezydata.example.jpa.data.CategoryData in project ezyfox-examples by tvd12.
the class CategoryController method addCategory.
@DoPost("/add")
public CategoryResponse addCategory(@RequestBody AddCategoryRequest request) {
categoryValidator.validate(request);
final AddCategoryData addCategoryData = requestToDataConverter.toData(request);
final CategoryData categoryData = categoryService.saveCategory(addCategoryData);
return dataToResponseConverter.toResponse(categoryData);
}
Aggregations