diff --git a/app/database_init.php b/app/database_init.php index 8df2e5d..7fadbe4 100644 --- a/app/database_init.php +++ b/app/database_init.php @@ -12,7 +12,7 @@ class DatabaseInit public function __construct() { - if (getenv("IS_DB_INIT") === false) { + //if (getenv("IS_DB_INIT") === false) { try { $this->con = (new DatabaseCon)->connect(); $this->createUserTable(); @@ -20,8 +20,8 @@ class DatabaseInit } catch (PDOException $e) { throw new PDOException($e->getMessage(), $e->getCode(), $e); } - putenv("IS_DB_INIT=true"); - } + // putenv("IS_DB_INIT=true"); + //} } private function createUserTable() @@ -41,10 +41,10 @@ class DatabaseInit $query = 'CREATE TABLE IF NOT EXISTS file ( id UUID PRIMARY KEY, user_id UUID REFERENCES `user`(`id`) ON DELETE CASCADE, - filename VARCHAR(100) DEFAULT CURDATE(), + filename VARCHAR(100), category VARCHAR(50), creation_date DATETIME, - import_date DATE);'; + info VARCHAR(1000));'; $this->con->executeQuery($query); } diff --git a/app/gateway/file_gateway.php b/app/gateway/file_gateway.php index 1a0ba32..2744ec1 100644 --- a/app/gateway/file_gateway.php +++ b/app/gateway/file_gateway.php @@ -20,17 +20,18 @@ class FileGateway } } - public function createFile(string $filename, string $user_uuid, string $category, string $creation_date) + public function createFile(string $filename, string $user_uuid, string $category, string $creation_date, string $infoAsJson) { - $query = "INSERT INTO file VALUES(UUID(), :user_uuid, :filename, :category, :creation_date ,CURDATE());"; + $query = "INSERT INTO file VALUES(UUID(), :user_uuid, :filename, :category, :creation_date , :info);"; try { $this->con->executeQuery($query, array( ':user_uuid' => array($user_uuid, PDO::PARAM_STR), ':filename' => array($filename, PDO::PARAM_STR), ':category' => array($category, PDO::PARAM_STR), - ':creation_date' => array($creation_date, PDO::PARAM_STR) + ':creation_date' => array($creation_date, PDO::PARAM_STR), + ':info' => array($infoAsJson, PDO::PARAM_STR) )); - } catch (PDOException $e) { + } catch (PDOException) { return -1; } @@ -45,7 +46,7 @@ class FileGateway $this->con->executeQuery($query, array( ':file_uuid' => array($file_uuid, PDO::PARAM_STR) )); - } catch (PDOException $e) { + } catch (PDOException) { return -1; } @@ -71,13 +72,13 @@ class FileGateway public function listFiles(string $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;"; + $query = "SELECT f.id, f.filename, f.category, f.creation_date, f.info 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) )); $results = $this->con->getResults(); - } catch (PDOException $e) { + } catch (PDOException) { return -1; } @@ -87,7 +88,8 @@ class FileGateway 'uuid' => $row['id'], 'filename' => $row['filename'], 'category' => $row['category'], - 'creation_date' => $row['creation_date'] + 'creation_date' => $row['creation_date'], + 'info' => json_decode($row['info']) ]; } diff --git a/app/routes.php b/app/routes.php index 9fbfe93..f9c3709 100644 --- a/app/routes.php +++ b/app/routes.php @@ -170,7 +170,6 @@ return function (App $app) { #### FILES #### // Get list of files $app->get('/user/files', function (Request $req, Response $res) { - $save_folder = '/home/hel/smartfit_hdd'; if (!(new Token)->verifyToken($req->getHeader('Authorization'))) { return $res->withStatus(401); } @@ -245,6 +244,8 @@ return function (App $app) { $uuid = (new Token)->getUuidFromToken($token); $file = $req->getUploadedFiles()['file']; + + $info = $req->getParsedBody()['info']; $category = $req->getParsedBody()['SmartFit_Category']; $creation_date = $req->getParsedBody()['SmartFit_Date']; $filename = $file->getClientFilename(); @@ -258,7 +259,7 @@ return function (App $app) { } $file->moveTo($file_save_folder . '/' . $filename); - $code = (new FileGateway)->createFile($filename, $uuid, $category, $creation_date); + $code = (new FileGateway)->createFile($filename, $uuid, $category, $creation_date, $info); if ($code === -1) return $res->withStatus(500); return $res->withStatus(200);