fix: add missing task logic to task repo

This commit is contained in:
Miguel Nogueira 2025-04-13 23:25:04 +01:00
parent b48fd48f24
commit c0871bf214

View File

@ -4,6 +4,7 @@ namespace Repositories;
use Carbon\Carbon;
use Database\Connection;
use Exceptions\TaskNotFoundException;
use Interfaces\TaskDao;
use Models\Task;
use PDO;
@ -48,12 +49,20 @@ class TaskRepository implements TaskDao
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
/**
* @throws TaskNotFoundException
*/
public function readById($id): Task
{
$stmt = $this->conn->prepare('SELECT * FROM Tasks WHERE id = ?');
$stmt->execute([$id]);
return Task::fromArray($stmt->fetch(PDO::FETCH_ASSOC));
if (!$data = $stmt->fetch(PDO::FETCH_ASSOC))
{
throw new TaskNotFoundException('Task not found.');
}
return Task::fromArray($data);
}
public function update(Task $task): bool