refactor(models): refactor task model to reflect schema field names
This commit is contained in:
parent
713c8e5137
commit
0e0ca6d16a
@ -97,11 +97,11 @@ class TaskController
|
||||
}
|
||||
|
||||
$task = new Task();
|
||||
$task->setTitle($params['tasks']['name'])
|
||||
->setStatus(TaskStatus::tryFrom((int) $params['tasks']['status']))
|
||||
$task->setName($params['tasks']['name'])
|
||||
->setStatusId(TaskStatus::tryFrom((int) $params['tasks']['status']))
|
||||
->setDescription($params['tasks']['description'])
|
||||
->setStartDt($params['tasks']['start'])
|
||||
->setEndDt($params['tasks']['end']);
|
||||
->setStart($params['tasks']['start'])
|
||||
->setEnd($params['tasks']['end']);
|
||||
|
||||
|
||||
$createdTask = $this->repository->create($task);
|
||||
|
@ -20,20 +20,22 @@ class Task
|
||||
|
||||
|
||||
// NOTE: This is actually the "name" in the db.
|
||||
private string $title;
|
||||
private string $name;
|
||||
|
||||
private string $description;
|
||||
|
||||
private TaskStatus $status;
|
||||
private TaskStatus $statusId;
|
||||
|
||||
private string $endDt;
|
||||
private string $end;
|
||||
|
||||
private string $start;
|
||||
|
||||
private string $startDt;
|
||||
|
||||
|
||||
public function __construct($status = TaskStatus::STARTED)
|
||||
{
|
||||
$this->status = $status;
|
||||
$this->statusId = $status;
|
||||
|
||||
}
|
||||
|
||||
@ -53,14 +55,14 @@ class Task
|
||||
$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;
|
||||
}
|
||||
|
||||
@ -75,36 +77,36 @@ class Task
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -128,11 +130,11 @@ class Task
|
||||
// task owner is discarded from input array
|
||||
$task->createdAt = Carbon::parse($data['created_at']);
|
||||
$task->updatedAt = Carbon::parse($data['updated_at']);
|
||||
$task->title = $data['name'] ?? '';
|
||||
$task->name = $data['name'] ?? '';
|
||||
$task->description = $data['description'] ?? '';
|
||||
$task->startDt = $data['start'] ?? '';
|
||||
$task->endDt = $data['end'] ?? '';
|
||||
$task->status = TaskStatus::tryFrom($data['status_id']) ?? TaskStatus::STARTED;
|
||||
$task->start = $data['start'] ?? '';
|
||||
$task->end = $data['end'] ?? '';
|
||||
$task->statusId = TaskStatus::tryFrom($data['status_id']) ?? TaskStatus::STARTED;
|
||||
|
||||
return $task;
|
||||
}
|
||||
@ -146,13 +148,13 @@ class Task
|
||||
return [
|
||||
'id' => $this->id ?? null,
|
||||
'task_owner' => 1, // fake hard-coded user for now
|
||||
'created_at' => Carbon::now()->toDateTimeString(),
|
||||
'updated_at' => Carbon::now()->toDateTimeString(),
|
||||
'name' => $this->getTitle(),
|
||||
'created_at' => $this->createdAt->toDateTimeString(),
|
||||
'updated_at' => $this->updatedAt->toDateTimeString(),
|
||||
'name' => $this->getName(),
|
||||
'description' => $this->getDescription(),
|
||||
'start' => $this->getStartDt(),
|
||||
'end' => $this->getEndDt(),
|
||||
'status_id' => $this->getStatus()->value
|
||||
'start' => $this->getStart(),
|
||||
'end' => $this->getEnd(),
|
||||
'status_id' => $this->getStatusId()->value
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -74,11 +74,11 @@ class TaskRepository implements TaskDao
|
||||
return $stmt->execute([
|
||||
1, // Mock user ID for now, we haven't implemented authentication yet
|
||||
Carbon::now(),
|
||||
$task->getTitle(),
|
||||
$task->getName(),
|
||||
$task->getDescription(),
|
||||
$task->getStartDt(),
|
||||
$task->getEndDt(),
|
||||
$task->getStatus(),
|
||||
$task->getStart(),
|
||||
$task->getEnd(),
|
||||
$task->getStatusId(),
|
||||
$task->getTaskId()
|
||||
]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user