Implementation of category creation.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package org.codiki.domain.category.exception;
|
||||
|
||||
import org.codiki.domain.exception.FunctionnalException;
|
||||
|
||||
public class CategoryEditionException extends FunctionnalException {
|
||||
public CategoryEditionException(String reason) {
|
||||
super(String.format("Impossible to edit a category because : %s.", reason));
|
||||
}
|
||||
|
||||
public CategoryEditionException(FunctionnalException cause) {
|
||||
super("Impossible to edit a category due to a root cause.", cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.codiki.domain.category.model.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.codiki.domain.category.model.Category;
|
||||
|
||||
public class CategoryBuilder {
|
||||
private UUID id;
|
||||
private String name;
|
||||
private List<Category> subCategories;
|
||||
|
||||
public static CategoryBuilder aCategory() {
|
||||
return new CategoryBuilder();
|
||||
}
|
||||
|
||||
private CategoryBuilder() {}
|
||||
|
||||
public CategoryBuilder withId(UUID id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CategoryBuilder withName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CategoryBuilder withSubCategories(List<Category> subCategories) {
|
||||
this.subCategories = subCategories;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CategoryBuilder withSubCategory(Category subCategory) {
|
||||
if (subCategories == null) {
|
||||
subCategories = new ArrayList<>();
|
||||
}
|
||||
subCategories.add(subCategory);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Category build() {
|
||||
return new Category(id, name, subCategories);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,15 @@
|
||||
package org.codiki.domain.category.port;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.codiki.domain.category.model.Category;
|
||||
|
||||
public interface CategoryPort {
|
||||
Optional<Category> findById(final UUID uuid);
|
||||
Optional<Category> findById(UUID uuid);
|
||||
|
||||
void save(Category category);
|
||||
|
||||
List<Category> findAllByIds(List<UUID> subCategoryIds);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user