Implementation of category updating.
This commit is contained in:
@@ -7,7 +7,9 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.codiki.domain.category.model.builder.CategoryBuilder.aCategory;
|
||||
import static org.springframework.util.CollectionUtils.isEmpty;
|
||||
import org.codiki.domain.category.exception.CategoryEditionException;
|
||||
import org.codiki.domain.category.exception.CategoryNotFoundException;
|
||||
import org.codiki.domain.category.model.Category;
|
||||
import org.codiki.domain.category.port.CategoryPort;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -44,4 +46,21 @@ public class CategoryUseCases {
|
||||
|
||||
return newCategory;
|
||||
}
|
||||
|
||||
public Category updateCategory(UUID categoryId, String name, List<UUID> subCategoryIds) {
|
||||
if (isNull(name) && isEmpty(subCategoryIds)) {
|
||||
throw new CategoryEditionException("no any field is filled");
|
||||
}
|
||||
|
||||
Category categoryToUpdate = categoryPort.findById(categoryId)
|
||||
.orElseThrow(() -> new CategoryNotFoundException(categoryId));
|
||||
|
||||
Category updatedCategory = aCategory()
|
||||
.basedOn(categoryToUpdate)
|
||||
.build();
|
||||
|
||||
categoryPort.save(updatedCategory);
|
||||
|
||||
return updatedCategory;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user