Compare commits
No commits in common. "18acbd3b327999cabc4aec0c3321d2f017198d7d" and "728cb4f84fd7b2417341f371a820fc2dee19a226" have entirely different histories.
18acbd3b32
...
728cb4f84f
@ -17,7 +17,7 @@ public class ListCommand implements Command {
|
||||
if (args.length > 0)
|
||||
return Optional.of(Command.errorMessage);
|
||||
|
||||
var res = formatWithTable(service.getAll(), "Список задач пуст.");
|
||||
var res = formatWithTable(service.list(), "Список задач пуст.");
|
||||
|
||||
return Optional.of(res);
|
||||
}
|
||||
|
||||
@ -13,23 +13,23 @@ public class EntityService<T extends Identifiable> {
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
public void save(T obj) {
|
||||
protected void save(T obj) {
|
||||
repo.save(obj);
|
||||
}
|
||||
|
||||
public Optional<T> getById(int id) {
|
||||
protected Optional<T> getById(int id) {
|
||||
return repo.findById(id);
|
||||
}
|
||||
|
||||
public List<T> getAll() {
|
||||
protected List<T> getAll() {
|
||||
return repo.findAll();
|
||||
}
|
||||
|
||||
public void remove(int id) {
|
||||
protected void remove(int id) {
|
||||
repo.delete(id);
|
||||
}
|
||||
|
||||
public boolean has(int id) {
|
||||
protected boolean has(int id) {
|
||||
return repo.has(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,23 +1,28 @@
|
||||
package ru.kamask.pet.todo.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import ru.kamask.pet.todo.model.SimpleTask;
|
||||
import ru.kamask.pet.todo.repo.Repository;
|
||||
import ru.kamask.pet.todo.repo.InMemoryRepository;
|
||||
|
||||
public class TaskService extends EntityService<SimpleTask> {
|
||||
public class TaskService {
|
||||
private final InMemoryRepository<SimpleTask> repo;
|
||||
|
||||
public TaskService(Repository<SimpleTask> repo) {
|
||||
super(repo);
|
||||
public TaskService(InMemoryRepository<SimpleTask> repo) {
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
public void create(String title) {
|
||||
super.save(new SimpleTask(title));
|
||||
repo.save(new SimpleTask(title));
|
||||
}
|
||||
|
||||
public Optional<SimpleTask> getById(int id) {
|
||||
return repo.findById(id);
|
||||
}
|
||||
|
||||
public boolean complete(int id) {
|
||||
var taskOpt = super.getById(id);
|
||||
var taskOpt = repo.findById(id);
|
||||
if (taskOpt.isPresent()) {
|
||||
taskOpt.get().markAsCompleted();
|
||||
return true;
|
||||
@ -25,9 +30,20 @@ public class TaskService extends EntityService<SimpleTask> {
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<SimpleTask> list() {
|
||||
return repo.findAll();
|
||||
}
|
||||
|
||||
public void remove(int id) {
|
||||
repo.delete(id);
|
||||
}
|
||||
|
||||
public boolean has(int id) {
|
||||
return repo.has(id);
|
||||
}
|
||||
|
||||
public List<SimpleTask> search(String query) {
|
||||
return super.getAll().stream()
|
||||
return repo.findAll().stream()
|
||||
.filter(task -> task.data().title().contains(query))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user