Skip to content

Commit

Permalink
Add new field 'description' into the Task entity.
Browse files Browse the repository at this point in the history
  • Loading branch information
maurobonfietti committed May 22, 2019
1 parent cb56a75 commit 745e1b1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions database/database.sql
Expand Up @@ -6,6 +6,7 @@ DROP TABLE IF EXISTS `tasks`;
CREATE TABLE IF NOT EXISTS `tasks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`description` text,
`status` tinyint(1) NOT NULL DEFAULT '0',
`userId` int(11) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Expand Down
13 changes: 11 additions & 2 deletions src/Repository/TaskRepository.php
Expand Up @@ -54,9 +54,13 @@ public function searchTasks(string $tasksName, int $userId): array

public function createTask($task)
{
$query = 'INSERT INTO tasks (name, status, userId) VALUES (:name, :status, :userId)';
$query = '
INSERT INTO tasks (name, description, status, userId)
VALUES (:name, :description, :status, :userId)
';
$statement = $this->getDb()->prepare($query);
$statement->bindParam('name', $task->name);
$statement->bindParam('description', $task->description);
$statement->bindParam('status', $task->status);
$statement->bindParam('userId', $task->userId);
$statement->execute();
Expand All @@ -66,10 +70,15 @@ public function createTask($task)

public function updateTask($task)
{
$query = 'UPDATE tasks SET name=:name, status=:status WHERE id=:id AND userId = :userId';
$query = '
UPDATE tasks
SET name=:name, description=:description, status=:status
WHERE id=:id AND userId = :userId
';
$statement = $this->getDb()->prepare($query);
$statement->bindParam('id', $task->id);
$statement->bindParam('name', $task->name);
$statement->bindParam('description', $task->description);
$statement->bindParam('status', $task->status);
$statement->bindParam('userId', $task->userId);
$statement->execute();
Expand Down
7 changes: 7 additions & 0 deletions src/Service/TaskService.php
Expand Up @@ -50,6 +50,10 @@ public function createTask(array $input)
throw new TaskException('The field "name" is required.', 400);
}
$task->name = self::validateTaskName($data->name);
$task->description = null;
if (isset($data->description)) {
$task->description = $data->description;
}
$task->status = 0;
if (isset($data->status)) {
$task->status = self::validateTaskStatus($data->status);
Expand All @@ -69,6 +73,9 @@ public function updateTask(array $input, int $taskId)
if (isset($data->name)) {
$task->name = self::validateTaskName($data->name);
}
if (isset($data->description)) {
$task->description = $data->description;
}
if (isset($data->status)) {
$task->status = self::validateTaskStatus($data->status);
}
Expand Down

0 comments on commit 745e1b1

Please sign in to comment.