Skip to content

Commit

Permalink
Merge pull request #40 from maurobonfietti/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
maurobonfietti authored May 22, 2019
2 parents afb77fe + df94f38 commit 9fdded4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions database/database.sql
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion extras/bin/restart-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ echo -e "Reading environment variables..."
source .env

echo -e "Restarting demo database..."
mysql -u$DB_USERNAME -p$DB_PASSWORD -h$DB_HOSTNAME -e 'DROP DATABASE IF EXISTS $DB_DATABASE ; CREATE DATABASE $DB_DATABASE' 2> /dev/null
mysql -u$DB_USERNAME -p$DB_PASSWORD -h$DB_HOSTNAME -e "DROP DATABASE IF EXISTS $DB_DATABASE ; CREATE DATABASE $DB_DATABASE" 2> /dev/null

echo -e "Creating testing data..."
mysql -u$DB_USERNAME -p$DB_PASSWORD -h$DB_HOSTNAME $DB_DATABASE < database/database.sql 2> /dev/null
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class DefaultController extends BaseController
{
const API_VERSION = '0.21.3';
const API_VERSION = '0.22.0';

public function __construct(Container $container)
{
Expand Down
13 changes: 11 additions & 2 deletions src/Repository/TaskRepository.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 9fdded4

Please sign in to comment.