diff --git a/backend/composer.json b/backend/composer.json new file mode 100644 index 0000000..a9c51dc --- /dev/null +++ b/backend/composer.json @@ -0,0 +1,27 @@ +{ + "name": "tpsoft/nutrio", + "description": "Backend pre jedalnicky s vypoctom kalorii.", + "type": "project", + "license": "MIT", + "autoload": { + "psr-4": { + "TPsoft\\Nutrio\\": "src/" + }, + "files": [ + "config/Configuration.php" + ] + }, + "authors": [ + { + "name": "igor", + "email": "mino@tpsoft.org" + } + ], + "require": { + "tpsoft/apilite": "^1.0", + "tpsoft/dbmodel": "^1.1" + }, + "scripts": { + "model": "php scripts/createModel.php" + } +} \ No newline at end of file diff --git a/backend/composer.lock b/backend/composer.lock new file mode 100644 index 0000000..3a0878b --- /dev/null +++ b/backend/composer.lock @@ -0,0 +1,113 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "9b92dc81ccf6b0cc7f350c56793c6523", + "packages": [ + { + "name": "tpsoft/apilite", + "version": "v1.0.3", + "source": { + "type": "git", + "url": "https://gitea.tpsoft.org/TPsoft.org/APIlite.git", + "reference": "c0fd7b3fe5270ee44a84a92e9255ada2438812b7" + }, + "require": { + "php": ">=8.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "TPsoft\\APIlite\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0-or-later" + ], + "authors": [ + { + "name": "Igor Mino", + "email": "mino@tpsoft.org", + "homepage": "https://www.tpsoft.org", + "role": "Developer" + } + ], + "description": "A set of tools to simplify the work of creating backend APIs for your frontend projects.", + "keywords": [ + "api", + "json", + "php", + "rest", + "typescript" + ], + "funding": [ + { + "url": "https://www.anycoin.cz/donate/igormino", + "type": "other" + } + ], + "time": "2025-10-13T21:36:34+00:00" + }, + { + "name": "tpsoft/dbmodel", + "version": "v1.1.1", + "source": { + "type": "git", + "url": "https://gitea.tpsoft.org/TPsoft.org/DBmodel.git", + "reference": "ff5663282f1efaa6c79d36760afca25ac25c16e6" + }, + "require": { + "ext-pdo": "*", + "php": ">=8.2" + }, + "bin": [ + "bin/dbmodel-files" + ], + "type": "library", + "autoload": { + "psr-4": { + "TPsoft\\DBmodel\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0-or-later" + ], + "authors": [ + { + "name": "Igor Mino", + "email": "mino@tpsoft.org", + "homepage": "https://www.tpsoft.org", + "role": "Developer" + } + ], + "description": "This library extends the builtin PDO object by several useful features. ", + "keywords": [ + "db", + "model", + "mysql", + "pdo", + "sqlite" + ], + "funding": [ + { + "url": "https://www.anycoin.cz/donate/igormino", + "type": "other" + } + ], + "time": "2026-02-09T05:39:02+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": {}, + "prefer-stable": false, + "prefer-lowest": false, + "platform": {}, + "platform-dev": {}, + "plugin-api-version": "2.6.0" +} diff --git a/backend/config/Configuration.php b/backend/config/Configuration.php new file mode 100644 index 0000000..b0e58f4 --- /dev/null +++ b/backend/config/Configuration.php @@ -0,0 +1,31 @@ +rootDir(realpath(__DIR__.'/../src/')); +$creator->interact(); diff --git a/backend/src/Init.php b/backend/src/Init.php new file mode 100644 index 0000000..4c35042 --- /dev/null +++ b/backend/src/Init.php @@ -0,0 +1,20 @@ +database(); diff --git a/backend/src/Maintenance.php b/backend/src/Maintenance.php new file mode 100644 index 0000000..75ebda0 --- /dev/null +++ b/backend/src/Maintenance.php @@ -0,0 +1,58 @@ +existsTable('options')) { + $this->checkDBTable('options', ' + `key` VARCHAR(255) NOT NULL PRIMARY KEY, + `value` VARCHAR(255) NOT NULL + '); + $this->dbver(1); + } + $dbver = $this->dbver(); + if ($dbver == 1) { + // create new + } + } + + protected function settings(string $key, ?string $value = null): string|false + { + if (is_null($value)) { + return $this->dbh->getOne(sprintf('SELECT `value` FROM `options` WHERE `key` = %s', $this->dbh->quote($key))); + } else { + $db_type = $this->dbh->getDBtype(); + switch ($db_type) { + case 'mysql': + return $this->dbh->query(sprintf( + 'INSERT INTO `options` (`key`, `value`) VALUES (%s, %s) ON DUPLICATE KEY UPDATE `value` = %s', + $this->dbh->quote($key), + $this->dbh->quote($value), + $this->dbh->quote($value) + )) !== false; + break; + case 'sqlite': + return $this->dbh->query(sprintf( + 'INSERT INTO `options` (`key`, `value`) VALUES (%s, %s) ON CONFLICT(`key`) DO UPDATE SET `value` = %s', + $this->dbh->quote($key), + $this->dbh->quote($value), + $this->dbh->quote($value) + )) !== false; + break; + default: + new \Exception('Unknown DB type: ' . $db_type); + return false; + break; + } + } + } + + protected function dbver(?string $ver = null) + { + return $this->settings('version', $ver); + } +}