Search in sources :

Example 1 with AddCategoryData

use of com.tvd12.ezydata.example.jpa.data.AddCategoryData 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)

Example 2 with AddCategoryData

use of com.tvd12.ezydata.example.jpa.data.AddCategoryData 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);
}
Also used : AddCategoryData(com.tvd12.ezydata.example.jpa.data.AddCategoryData) CategoryData(com.tvd12.ezydata.example.jpa.data.CategoryData) AddCategoryData(com.tvd12.ezydata.example.jpa.data.AddCategoryData)

Example 3 with AddCategoryData

use of com.tvd12.ezydata.example.jpa.data.AddCategoryData in project ezyfox-examples by tvd12.

the class DataToEntityConverter method toEntity.

public Category toEntity(AddCategoryData data) {
    final Category entity = new Category();
    entity.setName(data.getCategoryName());
    entity.setCreatedTime(LocalDateTime.now());
    entity.setUpdatedTime(LocalDateTime.now());
    return entity;
}
Also used : Category(com.tvd12.ezydata.example.jpa.entity.Category)

Aggregations

Category (com.tvd12.ezydata.example.jpa.entity.Category)2 AddCategoryData (com.tvd12.ezydata.example.jpa.data.AddCategoryData)1 CategoryData (com.tvd12.ezydata.example.jpa.data.CategoryData)1 DuplicatedCategoryException (com.tvd12.ezydata.example.jpa.exception.DuplicatedCategoryException)1