Skip to content

Commit

Permalink
tasks: hide task.done
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Aug 19, 2021
1 parent 6d64483 commit 8a9e535
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tasks/src/driver/list_console_presenter.rs
Expand Up @@ -16,7 +16,7 @@ impl ListPresenter for ListConsolePresenter {
.map(|task| format!(
"{} {} {}",
task.id(),
if task.done { "☑" } else { "☐" },
if task.done() { "☑" } else { "☐" },
task.text
))
.collect::<Vec<String>>()
Expand Down
2 changes: 1 addition & 1 deletion tasks/src/driver/task_json_repository.rs
Expand Up @@ -18,7 +18,7 @@ struct TaskData {
impl From<Task> for TaskData {
fn from(task: Task) -> Self {
Self {
done: task.done,
done: task.done(),
id: task.id(),
text: task.text,
}
Expand Down
6 changes: 5 additions & 1 deletion tasks/src/entity/task.rs
@@ -1,6 +1,6 @@
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Task {
pub done: bool,
done: bool,
id: usize,
pub text: String,
}
Expand All @@ -18,6 +18,10 @@ impl Task {
}
}

pub fn done(&self) -> bool {
self.done
}

pub fn id(&self) -> usize {
self.id
}
Expand Down
2 changes: 1 addition & 1 deletion tasks/src/use_case/list_use_case.rs
Expand Up @@ -20,7 +20,7 @@ impl ListUseCase {
.repository
.find_all()
.into_iter()
.filter(|task| all || !task.done)
.filter(|task| all || !task.done())
.collect::<Vec<Task>>();
self.presenter.complete(&tasks);
}
Expand Down
4 changes: 2 additions & 2 deletions tasks/src/use_case/task_memory_repository.rs
Expand Up @@ -54,8 +54,8 @@ impl TaskRepository for TaskMemoryRepository {
.iter()
.position(|t| t.id() == task.id())
.unwrap();
let task = tasks.tasks.get_mut(task_position).unwrap();
task.done = true;
let task_mut = tasks.tasks.get_mut(task_position).unwrap();
*task_mut = task;
}
}

Expand Down

0 comments on commit 8a9e535

Please sign in to comment.