refactor(models): refactor task model to reflect schema field names

This commit is contained in:
Miguel Nogueira 2025-04-14 15:06:31 +01:00
parent 713c8e5137
commit 0e0ca6d16a
3 changed files with 40 additions and 38 deletions

View File

@ -97,11 +97,11 @@ class TaskController
} }
$task = new Task(); $task = new Task();
$task->setTitle($params['tasks']['name']) $task->setName($params['tasks']['name'])
->setStatus(TaskStatus::tryFrom((int) $params['tasks']['status'])) ->setStatusId(TaskStatus::tryFrom((int) $params['tasks']['status']))
->setDescription($params['tasks']['description']) ->setDescription($params['tasks']['description'])
->setStartDt($params['tasks']['start']) ->setStart($params['tasks']['start'])
->setEndDt($params['tasks']['end']); ->setEnd($params['tasks']['end']);
$createdTask = $this->repository->create($task); $createdTask = $this->repository->create($task);

View File

@ -20,20 +20,22 @@ class Task
// NOTE: This is actually the "name" in the db. // NOTE: This is actually the "name" in the db.
private string $title; private string $name;
private string $description; private string $description;
private TaskStatus $status; private TaskStatus $statusId;
private string $endDt; private string $end;
private string $start;
private string $startDt; private string $startDt;
public function __construct($status = TaskStatus::STARTED) public function __construct($status = TaskStatus::STARTED)
{ {
$this->status = $status; $this->statusId = $status;
} }
@ -53,14 +55,14 @@ class Task
$this->updatedAt = Carbon::now(); $this->updatedAt = Carbon::now();
} }
public function getTitle(): string public function getName(): string
{ {
return $this->title; return $this->name;
} }
public function setTitle(string $title): self public function setName(string $name): self
{ {
$this->title = $title; $this->name = $name;
return $this; return $this;
} }
@ -75,36 +77,36 @@ class Task
return $this; return $this;
} }
public function getStartDt(): string public function getStart(): string
{ {
return $this->startDt; return $this->start;
} }
public function setStartDt(string $startDt): self public function setStart(string $start): self
{ {
$this->startDt = Carbon::parse($startDt)->toDateTimeString(); $this->start = Carbon::parse($start)->toDateTimeString();
return $this; return $this;
} }
public function getEndDt(): string public function getEnd(): string
{ {
return $this->endDt; return $this->end;
} }
public function setEndDt(string $endDt): self public function setEnd(string $end): self
{ {
$this->endDt = Carbon::parse($endDt)->toDateTimeString(); $this->end = Carbon::parse($end)->toDateTimeString();
return $this; return $this;
} }
public function getStatus(): TaskStatus public function getStatusId(): TaskStatus
{ {
return $this->status; return $this->statusId;
} }
public function setStatus(TaskStatus $status): self public function setStatusId(TaskStatus $statusId): self
{ {
$this->status = $status; $this->statusId = $statusId;
return $this; return $this;
} }
@ -128,11 +130,11 @@ class Task
// task owner is discarded from input array // task owner is discarded from input array
$task->createdAt = Carbon::parse($data['created_at']); $task->createdAt = Carbon::parse($data['created_at']);
$task->updatedAt = Carbon::parse($data['updated_at']); $task->updatedAt = Carbon::parse($data['updated_at']);
$task->title = $data['name'] ?? ''; $task->name = $data['name'] ?? '';
$task->description = $data['description'] ?? ''; $task->description = $data['description'] ?? '';
$task->startDt = $data['start'] ?? ''; $task->start = $data['start'] ?? '';
$task->endDt = $data['end'] ?? ''; $task->end = $data['end'] ?? '';
$task->status = TaskStatus::tryFrom($data['status_id']) ?? TaskStatus::STARTED; $task->statusId = TaskStatus::tryFrom($data['status_id']) ?? TaskStatus::STARTED;
return $task; return $task;
} }
@ -146,13 +148,13 @@ class Task
return [ return [
'id' => $this->id ?? null, 'id' => $this->id ?? null,
'task_owner' => 1, // fake hard-coded user for now 'task_owner' => 1, // fake hard-coded user for now
'created_at' => Carbon::now()->toDateTimeString(), 'created_at' => $this->createdAt->toDateTimeString(),
'updated_at' => Carbon::now()->toDateTimeString(), 'updated_at' => $this->updatedAt->toDateTimeString(),
'name' => $this->getTitle(), 'name' => $this->getName(),
'description' => $this->getDescription(), 'description' => $this->getDescription(),
'start' => $this->getStartDt(), 'start' => $this->getStart(),
'end' => $this->getEndDt(), 'end' => $this->getEnd(),
'status_id' => $this->getStatus()->value 'status_id' => $this->getStatusId()->value
]; ];
} }

View File

@ -74,11 +74,11 @@ class TaskRepository implements TaskDao
return $stmt->execute([ return $stmt->execute([
1, // Mock user ID for now, we haven't implemented authentication yet 1, // Mock user ID for now, we haven't implemented authentication yet
Carbon::now(), Carbon::now(),
$task->getTitle(), $task->getName(),
$task->getDescription(), $task->getDescription(),
$task->getStartDt(), $task->getStart(),
$task->getEndDt(), $task->getEnd(),
$task->getStatus(), $task->getStatusId(),
$task->getTaskId() $task->getTaskId()
]); ]);
} }