diff --git a/app/database_init.php b/app/database_init.php index b3e152e..eeb6c36 100644 --- a/app/database_init.php +++ b/app/database_init.php @@ -35,6 +35,8 @@ class DatabaseInit { id UUID PRIMARY KEY, user_id UUID REFERENCES `user`(`id`) ON DELETE CASCADE, filename VARCHAR(100) DEFAULT CURDATE(), + category VARCHAR(50), + creation_date DATETIME, import_date DATE);'; $this->con->executeQuery($query); diff --git a/app/gateway/file_gateway.php b/app/gateway/file_gateway.php index 8b8db99..c4d249f 100644 --- a/app/gateway/file_gateway.php +++ b/app/gateway/file_gateway.php @@ -16,12 +16,14 @@ class FileGateway { } } - public function createFile(string $filename, string $user_uuid) { - $query = "INSERT INTO file VALUES(UUID(), :user_uuid, :filename, CURDATE());"; + public function createFile(string $filename, string $user_uuid, string $category, string $creation_date) { + $query = "INSERT INTO file VALUES(UUID(), :user_uuid, :filename, :category, :creation_date ,CURDATE());"; try { $this->con->executeQuery($query, array( + ':user_uuid' => array($user_uuid, PDO::PARAM_STR), ':filename' => array($filename, PDO::PARAM_STR), - ':user_uuid' => array($user_uuid, PDO::PARAM_STR) + ':category' => array($category, PDO::PARAM_STR), + ':creation_date' => array($creation_date, PDO::PARAM_STR) )); } catch (PDOException $e) { return -1; @@ -61,7 +63,7 @@ class FileGateway { } public function listFiles(string $user_uuid) { - $query = "SELECT f.id, f.filename FROM file f, user u WHERE f.user_id=u.id and u.id=:user_uuid;"; + $query = "SELECT f.id, f.filename, f.category, f.creation_date FROM file f, user u WHERE f.user_id=u.id and u.id=:user_uuid;"; try { $this->con->executeQuery($query, array( ':user_uuid' => array($user_uuid, PDO::PARAM_STR) @@ -76,9 +78,11 @@ class FileGateway { $rows[] = [ 'uuid' => $row['id'], 'filename' => $row['filename'], + 'category' => $row['category'], + 'creation_date' => $row['creation_date'] ]; } return $rows; } -} \ No newline at end of file +} diff --git a/app/gateway/user_gateway.php b/app/gateway/user_gateway.php index f8d4303..1f75dbd 100644 --- a/app/gateway/user_gateway.php +++ b/app/gateway/user_gateway.php @@ -6,8 +6,6 @@ use PDOException; use PDO; use Config\Token; -use function PHPUnit\Framework\isEmpty; - class UserGateway { private Connection $con; private Token $token; @@ -113,4 +111,4 @@ class UserGateway { return 0; } -} \ No newline at end of file +} diff --git a/app/routes.php b/app/routes.php index 7cfc944..d5c4a4b 100644 --- a/app/routes.php +++ b/app/routes.php @@ -225,9 +225,12 @@ return function (App $app) { $uuid = (new Token)->getUuidFromToken($token); $file = $req->getUploadedFiles()['file']; + $category = $req->getParsedBody()['SmartFit_Category']; + $creation_date = $req->getParsedBody()['SmartFit_Date']; $filename = $file->getClientFilename(); + $code = (new FileGateway)->listFiles($uuid); - if(in_array($filename, $code, false)) return $res->withStatus(409); + if(array_search($filename, array_column($code, 'filename'), false) !== false) return $res->withStatus(409); $file_save_folder = $save_folder.'/'.$uuid.'/'; if(!is_dir($file_save_folder)) { @@ -235,8 +238,9 @@ return function (App $app) { } $file->moveTo($file_save_folder.'/'.$filename); - $code = (new FileGateway)->createFile($filename, $uuid); + $code = (new FileGateway)->createFile($filename, $uuid, $category, $creation_date); if($code === -1) return $res->withStatus(500); + return $res->withStatus(200); });