Merge pull request 'feat(service): создан универсальный EntityService для операций CRUD (close #48)' (#57) from feature/entity-service into dev
Reviewed-on: #57
This commit is contained in:
commit
728cb4f84f
@ -0,0 +1,35 @@
|
|||||||
|
package ru.kamask.pet.todo.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import ru.kamask.pet.todo.model.Identifiable;
|
||||||
|
import ru.kamask.pet.todo.repo.Repository;
|
||||||
|
|
||||||
|
public class EntityService<T extends Identifiable> {
|
||||||
|
private final Repository<T> repo;
|
||||||
|
|
||||||
|
protected EntityService(Repository<T> repo) {
|
||||||
|
this.repo = repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void save(T obj) {
|
||||||
|
repo.save(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Optional<T> getById(int id) {
|
||||||
|
return repo.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<T> getAll() {
|
||||||
|
return repo.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void remove(int id) {
|
||||||
|
repo.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean has(int id) {
|
||||||
|
return repo.has(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user