diff --git a/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainService.java b/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainService.java new file mode 100644 index 0000000000000000000000000000000000000000..9376c423afb2511fd4ff23761f1a9a861d71b121 --- /dev/null +++ b/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainService.java @@ -0,0 +1,56 @@ +package cz.fi.muni.pa165.flea.market.manager.domain; + +import lombok.NonNull; + +import java.util.List; + +/** + * Service interface for ENTITY with basic CRUD operations + * + * @param entity for the service + * + * @author Michal Cizek + */ +public interface DomainService { + /** + * Creates new entity. + * + * @param object entity to store in database + * @return created entity + * @throws NullPointerException if given object is null + */ + ENTITY create(@NonNull ENTITY object); + + /** + * Finds entity by id and returns it. + * + * @param id id of the entity to look for + * @return entity with given id + * @throws NullPointerException if given id is null + */ + ENTITY findById(@NonNull String id); + + /** + * Finds all entities. + * + * @return all stored entities + */ + List findAll(); + + /** + * Updates entity. + * + * @param object entity with new values to update + * @return updated entity + * @throws NullPointerException if given object is null + */ + ENTITY update(@NonNull ENTITY object); + + /** + * Deletes given entity. + * + * @param object entity to delete + * @throws NullPointerException if given object is null + */ + void delete(@NonNull ENTITY object); +} diff --git a/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainServiceImpl.java b/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..30de34300a65a925b6f1db2ce7496fa7e85cf924 --- /dev/null +++ b/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainServiceImpl.java @@ -0,0 +1,46 @@ +package cz.fi.muni.pa165.flea.market.manager.domain; + +import lombok.NonNull; + +import java.util.List; + +/** + * Implementation of {@link DomainService} + * + * @param entity for the service + * + * @author Michal Cizek + */ +public abstract class DomainServiceImpl implements DomainService { + + protected final DomainDao dao; + + public DomainServiceImpl(DomainDao dao) { + this.dao = dao; + } + + @Override + public ENTITY create(@NonNull ENTITY object) { + return dao.create(object); + } + + @Override + public ENTITY findById(@NonNull String id) { + return dao.findById(id); + } + + @Override + public List findAll() { + return dao.findAll(); + } + + @Override + public ENTITY update(@NonNull ENTITY object) { + return dao.update(object); + } + + @Override + public void delete(@NonNull ENTITY object) { + dao.delete(object); + } +}