Add add Link usecase
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
qvalentin 2022-04-22 11:22:46 +02:00
parent e634fbd1aa
commit 1861bdfe74
Signed by: qvalentin
GPG key ID: C979FA1EAFCABF1C
4 changed files with 72 additions and 3 deletions

View file

@ -1,9 +1,10 @@
package category;
import abstraction.CustomSet;
import abstraction.PersistenceAdapter;
import abstraction.CustomSetPersistenceDecorator;
import abstraction.PersistenceAdapter;
import exeptions.CategoryAlreadyExists;
import exeptions.CategroyDoesNotExist;
import exeptions.NonUniqueId;
import java.util.Optional;
@ -11,7 +12,6 @@ import java.util.Set;
public class CategoryRepository {
final private CustomSet<Category> categories;
public CategoryRepository(PersistenceAdapter<Category> categoryPersistenceAdapter) {
@ -22,11 +22,19 @@ public class CategoryRepository {
return categories.stream().filter(category -> category.getName().equals(name)).findFirst();
}
public CategoryId getIdByName(CategoryName name) {
return getByName(name)
.orElseThrow(() -> new CategroyDoesNotExist("A Category with name " + name + " does not exits. You must create it first."))
.getId();
}
public Optional<Category> getById(CategoryId id) {
return categories.stream().filter(category -> category.getId().equals(id)).findFirst();
}
public Set<Category> getAll(){
public Set<Category> getAll() {
return categories.getSet();
}
@ -37,6 +45,7 @@ public class CategoryRepository {
/**
* Check for duplicates with the domain rules
*
* @param category
*/
private void checkDuplicates(Category category) {

View file

@ -0,0 +1,8 @@
package exeptions;
public class CategroyDoesNotExist extends RuntimeException {
public CategroyDoesNotExist(String message) {
super(message);
}
}