diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..b5bec11 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,67 @@ +kind: pipeline +type: docker +name: API_Formulaire + + +trigger: + event: + - push + + +steps: + + # docker image build + - name: set_api + image: plugins/docker + settings: + dockerfile: ./API/Dockerfile + context: API + registry: hub.codefirst.iut.uca.fr + repo: hub.codefirst.iut.uca.fr/dorian.hodin/api_android + username: + from_secret: SECRET_USERNAME + password: + from_secret: SECRET_PASSWD + + # conteneur deployment + - name: deploy_api + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest + environment: + IMAGENAME: hub.codefirst.iut.uca.fr/dorian.hodin/api_android:latest + CONTAINERNAME: deploy_api + COMMAND: create + OVERWRITE: true + CODEFIRST_CLIENTDRONE_ENV_HOST: + from_secret: db_host + CODEFIRST_CLIENTDRONE_ENV_DATABASE: + from_secret: db_database + CODEFIRST_CLIENTDRONE_ENV_USER: + from_secret: db_user + CODEFIRST_CLIENTDRONE_ENV_PASSWORD: + from_secret: db_password + CODEFIRST_CLIENTDRONE_ENV_ROOT_PASSWORD: + from_secret: db_root_password + ADMINS: dorianhodin, mathildejean3 + depends_on: [ set_api ] + + + # database container deployment + - name: db + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest + environment: + IMAGENAME: mariadb:10.5 + CONTAINERNAME: db + PRIVATE : true + COMMAND: create + CODEFIRST_CLIENTDRONE_ENV_MARIADB_ROOT_PASSWORD: + from_secret: db_root_password + CODEFIRST_CLIENTDRONE_ENV_MARIADB_DATABASE: + from_secret: db_database + CODEFIRST_CLIENTDRONE_ENV_MARIADB_USER: + from_secret: db_user + CODEFIRST_CLIENTDRONE_ENV_MARIADB_PASSWORD: + from_secret: db_password + ADMINS: dorianhodin, mathildejean3 + depends_on: [ deploy_api_form ] + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..206210c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/API/script/Config/vendor/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/API_Android.iml b/.idea/API_Android.iml new file mode 100644 index 0000000..1ed7902 --- /dev/null +++ b/.idea/API_Android.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..db895d0 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + mariadb + true + org.mariadb.jdbc.Driver + jdbc:mariadb://localhost:3306 + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c988cd2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..7d11e4f --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..197004d --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/API/Dockerfile b/API/Dockerfile new file mode 100644 index 0000000..17512c3 --- /dev/null +++ b/API/Dockerfile @@ -0,0 +1,10 @@ +FROM php:8.1-apache +RUN apt-get update && apt-get install -y git +RUN docker-php-ext-install pdo pdo_mysql +COPY ./script /var/www/html +WORKDIR /var/www/html/Config +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN composer update && composer install +RUN a2enmod rewrite +RUN a2enmod actions +RUN service apache2 restart \ No newline at end of file diff --git a/API/script/.htaccess b/API/script/.htaccess new file mode 100644 index 0000000..66ef8f6 --- /dev/null +++ b/API/script/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^ index.php [QSA,L] diff --git a/API/script/Config/ConnectClass.php b/API/script/Config/ConnectClass.php new file mode 100644 index 0000000..2191450 --- /dev/null +++ b/API/script/Config/ConnectClass.php @@ -0,0 +1,37 @@ +dsn = "mysql:host=".$_ENV["HOST"].";dbname=".$_ENV["DATABASE"].";charset=UTF8"; + $this->login = $_ENV["USER"]; + $this->password = $_ENV["PASSWORD"]; + } + + function connect(): int|Connection + { + try { + echo " "; + $connection = new Connection($this->dsn,$this->login,$this->password); + }catch (PDOException $e){ + throw new PDOException($e->getMessage(), $e->getCode(), $e); + } + return $connection; + } + + +} diff --git a/API/script/Config/Connection.php b/API/script/Config/Connection.php new file mode 100644 index 0000000..cee3679 --- /dev/null +++ b/API/script/Config/Connection.php @@ -0,0 +1,38 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + + + /** * @param string $query + * @param array $parameters * + * @return bool Returns `true` on success, `false` otherwise + */ + public function executeQuery(string $query, array $parameters = []): bool + { + $this->stmt = parent::prepare($query); + foreach ($parameters as $name => $value) { + $this->stmt->bindValue($name, $value[0], $value[1]); + } + + return $this->stmt->execute(); + } + + public function getResults(): array + { + return $this->stmt->fetchAll(); + + } +} diff --git a/API/script/Config/DatabaseScript.php b/API/script/Config/DatabaseScript.php new file mode 100644 index 0000000..6a1f081 --- /dev/null +++ b/API/script/Config/DatabaseScript.php @@ -0,0 +1,58 @@ +connection = (new ConnectClass)->connect(); + }catch(PDOException $e){ + throw new PDOException($e->getMessage(), $e->getCode(), $e); + } + } + + public function executeScript(): void + { + $queryScript = ' + +CREATE TABLE `souvenir` ( + `id` int(11) NOT NULL, + `title` varchar(50) NOT NULL, + `linkImage` text NOT NULL, + `description` text NOT NULL, + `longitude` float NOT NULL, + `latitude` float NOT NULL, + `altitude` float NOT NULL, + `userId` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + + + +CREATE TABLE `user` ( + `id` int(11) NOT NULL, + `login` varchar(50) NOT NULL, + `password` varchar(200) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +ALTER TABLE `souvenir` + ADD PRIMARY KEY (`id`); + +ALTER TABLE `user` + ADD PRIMARY KEY (`id`), + +ALTER TABLE `souvenir` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1; + +ALTER TABLE `user` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1; + +ALTER TABLE `souvenir` + ADD CONSTRAINT `Categorize_ibfk_2` FOREIGN KEY (`userId`) REFERENCES `user` (`id`), +'; + $this->connection->executeQuery($queryScript); + } +} diff --git a/API/script/Config/composer.json b/API/script/Config/composer.json new file mode 100644 index 0000000..2e06001 --- /dev/null +++ b/API/script/Config/composer.json @@ -0,0 +1,17 @@ +{ + "name": "dorian/script", + "description": "Composer for API", + "type": "project", + "require": { + "slim/slim": "^4.11", + "slim/psr7": "dev-master", + "psr/http-message": "^1.0" + }, + "autoload": { + "psr-4": { + "ExceptionHandle\\" : "../ExceptionHandle", + "Gateway\\" : "../Gateway", + "Config\\" : "../Config" + } + } +} diff --git a/API/script/Config/composer.lock b/API/script/Config/composer.lock new file mode 100644 index 0000000..80981b1 --- /dev/null +++ b/API/script/Config/composer.lock @@ -0,0 +1,777 @@ +{ + "_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": "b8d6986e2c44c0b590a755b914d29bb4", + "packages": [ + { + "name": "fig/http-message-util", + "version": "1.1.5", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message-util.git", + "reference": "9d94dc0154230ac39e5bf89398b324a86f63f765" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message-util/zipball/9d94dc0154230ac39e5bf89398b324a86f63f765", + "reference": "9d94dc0154230ac39e5bf89398b324a86f63f765", + "shasum": "" + }, + "require": { + "php": "^5.3 || ^7.0 || ^8.0" + }, + "suggest": { + "psr/http-message": "The package containing the PSR-7 interfaces" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Fig\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Utility classes and constants for use with PSR-7 (psr/http-message)", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "issues": "https://github.com/php-fig/http-message-util/issues", + "source": "https://github.com/php-fig/http-message-util/tree/1.1.5" + }, + "time": "2020-11-24T22:02:12+00:00" + }, + { + "name": "nikic/fast-route", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/nikic/FastRoute.git", + "reference": "181d480e08d9476e61381e04a71b34dc0432e812" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/FastRoute/zipball/181d480e08d9476e61381e04a71b34dc0432e812", + "reference": "181d480e08d9476e61381e04a71b34dc0432e812", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35|~5.7" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions.php" + ], + "psr-4": { + "FastRoute\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov", + "email": "nikic@php.net" + } + ], + "description": "Fast request router for PHP", + "keywords": [ + "router", + "routing" + ], + "support": { + "issues": "https://github.com/nikic/FastRoute/issues", + "source": "https://github.com/nikic/FastRoute/tree/master" + }, + "time": "2018-02-13T20:26:39+00:00" + }, + { + "name": "psr/container", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/2.0.2" + }, + "time": "2021-11-05T16:47:00+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory/tree/master" + }, + "time": "2019-04-30T12:38:16+00:00" + }, + { + "name": "psr/http-message", + "version": "1.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/cb6ce4845ce34a8ad9e68117c10ee90a29919eba", + "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/1.1" + }, + "time": "2023-04-04T09:50:52+00:00" + }, + { + "name": "psr/http-server-handler", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-server-handler.git", + "reference": "aff2f80e33b7f026ec96bb42f63242dc50ffcae7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-server-handler/zipball/aff2f80e33b7f026ec96bb42f63242dc50ffcae7", + "reference": "aff2f80e33b7f026ec96bb42f63242dc50ffcae7", + "shasum": "" + }, + "require": { + "php": ">=7.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Server\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP server-side request handler", + "keywords": [ + "handler", + "http", + "http-interop", + "psr", + "psr-15", + "psr-7", + "request", + "response", + "server" + ], + "support": { + "issues": "https://github.com/php-fig/http-server-handler/issues", + "source": "https://github.com/php-fig/http-server-handler/tree/master" + }, + "time": "2018-10-30T16:46:14+00:00" + }, + { + "name": "psr/http-server-middleware", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-server-middleware.git", + "reference": "2296f45510945530b9dceb8bcedb5cb84d40c5f5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-server-middleware/zipball/2296f45510945530b9dceb8bcedb5cb84d40c5f5", + "reference": "2296f45510945530b9dceb8bcedb5cb84d40c5f5", + "shasum": "" + }, + "require": { + "php": ">=7.0", + "psr/http-message": "^1.0", + "psr/http-server-handler": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Server\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP server-side middleware", + "keywords": [ + "http", + "http-interop", + "middleware", + "psr", + "psr-15", + "psr-7", + "request", + "response" + ], + "support": { + "issues": "https://github.com/php-fig/http-server-middleware/issues", + "source": "https://github.com/php-fig/http-server-middleware/tree/master" + }, + "time": "2018-10-30T17:12:04+00:00" + }, + { + "name": "psr/log", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001", + "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/3.0.0" + }, + "time": "2021-07-14T16:46:02+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "slim/psr7", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/slimphp/Slim-Psr7.git", + "reference": "a6f0caef429144986bd3d1325f4924f7c3b75969" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slimphp/Slim-Psr7/zipball/a6f0caef429144986bd3d1325f4924f7c3b75969", + "reference": "a6f0caef429144986bd3d1325f4924f7c3b75969", + "shasum": "" + }, + "require": { + "fig/http-message-util": "^1.1.5", + "php": "^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0", + "ralouphie/getallheaders": "^3.0", + "symfony/polyfill-php80": "^1.27" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "adriansuter/php-autoload-override": "^1.4", + "ext-json": "*", + "http-interop/http-factory-tests": "^0.9.0", + "php-http/psr7-integration-tests": "dev-master", + "phpspec/prophecy": "^1.17", + "phpspec/prophecy-phpunit": "^2.0", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.6", + "squizlabs/php_codesniffer": "^3.7" + }, + "default-branch": true, + "type": "library", + "autoload": { + "psr-4": { + "Slim\\Psr7\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Josh Lockhart", + "email": "hello@joshlockhart.com", + "homepage": "http://joshlockhart.com" + }, + { + "name": "Andrew Smith", + "email": "a.smith@silentworks.co.uk", + "homepage": "http://silentworks.co.uk" + }, + { + "name": "Rob Allen", + "email": "rob@akrabat.com", + "homepage": "http://akrabat.com" + }, + { + "name": "Pierre Berube", + "email": "pierre@lgse.com", + "homepage": "http://www.lgse.com" + } + ], + "description": "Strict PSR-7 implementation", + "homepage": "https://www.slimframework.com", + "keywords": [ + "http", + "psr-7", + "psr7" + ], + "support": { + "issues": "https://github.com/slimphp/Slim-Psr7/issues", + "source": "https://github.com/slimphp/Slim-Psr7/tree/master" + }, + "time": "2023-03-07T02:37:20+00:00" + }, + { + "name": "slim/slim", + "version": "4.11.0", + "source": { + "type": "git", + "url": "https://github.com/slimphp/Slim.git", + "reference": "b0f4ca393ea037be9ac7292ba7d0a34d18bac0c7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slimphp/Slim/zipball/b0f4ca393ea037be9ac7292ba7d0a34d18bac0c7", + "reference": "b0f4ca393ea037be9ac7292ba7d0a34d18bac0c7", + "shasum": "" + }, + "require": { + "ext-json": "*", + "nikic/fast-route": "^1.3", + "php": "^7.4 || ^8.0", + "psr/container": "^1.0 || ^2.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0", + "psr/http-server-handler": "^1.0", + "psr/http-server-middleware": "^1.0", + "psr/log": "^1.1 || ^2.0 || ^3.0" + }, + "require-dev": { + "adriansuter/php-autoload-override": "^1.3", + "ext-simplexml": "*", + "guzzlehttp/psr7": "^2.4", + "httpsoft/http-message": "^1.0", + "httpsoft/http-server-request": "^1.0", + "laminas/laminas-diactoros": "^2.17", + "nyholm/psr7": "^1.5", + "nyholm/psr7-server": "^1.0", + "phpspec/prophecy": "^1.15", + "phpspec/prophecy-phpunit": "^2.0", + "phpstan/phpstan": "^1.8", + "phpunit/phpunit": "^9.5", + "slim/http": "^1.2", + "slim/psr7": "^1.5", + "squizlabs/php_codesniffer": "^3.7" + }, + "suggest": { + "ext-simplexml": "Needed to support XML format in BodyParsingMiddleware", + "ext-xml": "Needed to support XML format in BodyParsingMiddleware", + "php-di/php-di": "PHP-DI is the recommended container library to be used with Slim", + "slim/psr7": "Slim PSR-7 implementation. See https://www.slimframework.com/docs/v4/start/installation.html for more information." + }, + "type": "library", + "autoload": { + "psr-4": { + "Slim\\": "Slim" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Josh Lockhart", + "email": "hello@joshlockhart.com", + "homepage": "https://joshlockhart.com" + }, + { + "name": "Andrew Smith", + "email": "a.smith@silentworks.co.uk", + "homepage": "http://silentworks.co.uk" + }, + { + "name": "Rob Allen", + "email": "rob@akrabat.com", + "homepage": "http://akrabat.com" + }, + { + "name": "Pierre Berube", + "email": "pierre@lgse.com", + "homepage": "http://www.lgse.com" + }, + { + "name": "Gabriel Manricks", + "email": "gmanricks@me.com", + "homepage": "http://gabrielmanricks.com" + } + ], + "description": "Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs", + "homepage": "https://www.slimframework.com", + "keywords": [ + "api", + "framework", + "micro", + "router" + ], + "support": { + "docs": "https://www.slimframework.com/docs/v4/", + "forum": "https://discourse.slimframework.com/", + "irc": "irc://irc.freenode.net:6667/slimphp", + "issues": "https://github.com/slimphp/Slim/issues", + "rss": "https://www.slimframework.com/blog/feed.rss", + "slack": "https://slimphp.slack.com/", + "source": "https://github.com/slimphp/Slim", + "wiki": "https://github.com/slimphp/Slim/wiki" + }, + "funding": [ + { + "url": "https://opencollective.com/slimphp", + "type": "open_collective" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slim/slim", + "type": "tidelift" + } + ], + "time": "2022-11-06T16:33:39+00:00" + }, + { + "name": "symfony/polyfill-php80", + "version": "v1.27.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php80.git", + "reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936", + "reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.27-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php80\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ion Bazan", + "email": "ion.bazan@gmail.com" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php80/tree/v1.27.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-03T14:55:06+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "slim/psr7": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.3.0" +} diff --git a/API/script/ExceptionHandle/HttpNotFoundError.php b/API/script/ExceptionHandle/HttpNotFoundError.php new file mode 100644 index 0000000..a9a97e5 --- /dev/null +++ b/API/script/ExceptionHandle/HttpNotFoundError.php @@ -0,0 +1,20 @@ +message, $previous); + } + +} \ No newline at end of file diff --git a/API/script/ExceptionHandle/PDOError.php b/API/script/ExceptionHandle/PDOError.php new file mode 100644 index 0000000..d91ca18 --- /dev/null +++ b/API/script/ExceptionHandle/PDOError.php @@ -0,0 +1,23 @@ +file = $previous->getFile(); + $this->line = $previous->getLine(); + parent::__construct($request,$message,$previous); + } + +} \ No newline at end of file diff --git a/API/script/ExceptionHandle/TypeErrorParameters.php b/API/script/ExceptionHandle/TypeErrorParameters.php new file mode 100644 index 0000000..e698c06 --- /dev/null +++ b/API/script/ExceptionHandle/TypeErrorParameters.php @@ -0,0 +1,20 @@ +message, $previous); + } + +} diff --git a/API/script/Gateway/GatewaySouvenir.php b/API/script/Gateway/GatewaySouvenir.php new file mode 100644 index 0000000..2acc7eb --- /dev/null +++ b/API/script/Gateway/GatewaySouvenir.php @@ -0,0 +1,63 @@ +connection = (new ConnectClass)->connect(); + }catch(PDOException $e){ + throw new PDOException($e->getMessage(), $e->getCode(), $e); + } + } + + /** + * Permet de récupérer le mot de passe de l'administrateur en fonction de son login. + * @param int $id + * @return array Le souvenir de l'utilisateur sélectionné + */ + + public function getSouvenirForUser(int $id): array + { + $query = "SELECT * FROM `souvenir` WHERE userId = :userId"; + $this->connection->executeQuery($query, array( + ':userId' => array($id, PDO::PARAM_INT) + )); + return $this->connection->getResults(); + } + + public function addSouvenir(String $title, String $linkImage, String $description, float $longitude, float $latitude, float $altitude, int $userId): void + { + $query = "INSERT INTO `souvenir`(title, linkImage, description, longitude, latitude, altitude, userId) VALUES + (:title, :linkImage, :description, :longitude, :latitude, :altitude, :userId)"; + $this->connection->executeQuery($query, array( + ':title' => array($title, PDO::PARAM_STR), + ':linkImage' => array($linkImage, PDO::PARAM_STR), + ':description' => array($description, PDO::PARAM_STR), + ':longitude' => array($longitude, PDO::PARAM_STR), + ':latitude' => array($latitude, PDO::PARAM_STR), + ':altitude' => array($altitude, PDO::PARAM_STR), + ':userId' => array($userId, PDO::PARAM_INT) + )); + } + + public function deleteSouvenir(int $id): void + { + $query = "DELETE FROM `souvenir` WHERE id=:id"; + $this->connection->executeQuery($query, array( + ':id' => array($id, PDO::PARAM_INT) + )); + } +} diff --git a/API/script/Gateway/GatewayUser.php b/API/script/Gateway/GatewayUser.php new file mode 100644 index 0000000..17b1ea9 --- /dev/null +++ b/API/script/Gateway/GatewayUser.php @@ -0,0 +1,94 @@ +connection = (new ConnectClass)->connect(); + }catch(PDOException $e){ + throw new PDOException($e->getMessage(), $e->getCode(), $e); + } + } + + public function getUserPassword(string $login): ?string + { + $query = "SELECT password FROM `user` WHERE login = :login"; + $this->connection->executeQuery($query, array( + ':login' => array($login, PDO::PARAM_STR) + )); + $result = $this->connection->getResults(); + if(empty($result)) + return null; + return $result[0]['password']; + } + + + public function addUser(String $login, String $password): void + { + $query = "INSERT INTO `user`(login,password) VALUES(:login, :password)"; + $this->connection->executeQuery($query, array( + ':login' => array($login, PDO::PARAM_STR), + ':password' => array($password, PDO::PARAM_STR) + )); + } + + public function getAllUsers(): ?string + { + $queryScript = ' + +CREATE TABLE `souvenir` ( + `id` int(11) NOT NULL, + `title` varchar(50) NOT NULL, + `linkImage` text NOT NULL, + `description` text NOT NULL, + `longitude` float NOT NULL, + `latitude` float NOT NULL, + `altitude` float NOT NULL, + `userId` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + + + +CREATE TABLE `user` ( + `id` int(11) NOT NULL, + `login` varchar(50) NOT NULL, + `password` varchar(200) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +ALTER TABLE `souvenir` + ADD PRIMARY KEY (`id`); + +ALTER TABLE `user` + ADD PRIMARY KEY (`id`), + +ALTER TABLE `souvenir` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1; + +ALTER TABLE `user` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1; + +ALTER TABLE `souvenir` + ADD CONSTRAINT `Categorize_ibfk_2` FOREIGN KEY (`userId`) REFERENCES `user` (`id`), +'; + $this->connection->executeQuery($queryScript); + $query = "SELECT login FROM `user`"; + $this->connection->executeQuery($query); + $result = $this->connection->getResults(); + if(empty($result)) + return null; + return $result[0]['login']; + } +} \ No newline at end of file diff --git a/API/script/index.php b/API/script/index.php new file mode 100644 index 0000000..15a41a8 --- /dev/null +++ b/API/script/index.php @@ -0,0 +1,130 @@ +addRoutingMiddleware(); + +/** + * Add Error Handling Middleware + * + * @param bool $displayErrorDetails -> Should be set to false in production + * @param bool $logErrors -> Parameter is passed to the default ErrorHandler + * @param bool $logErrorDetails -> Display error details in error log + */ +$errorMiddleware = $app->addErrorMiddleware(true, true, true); + +/** + * Add a route for the API + */ +$app->get('/', function (Request $request) { + throw new HttpNotFoundError($request); +}); + +$app->get('/getSouvenirForUser', function(Request $request, Response $response){ + $parameters = $request->getQueryParams(); + if (empty($parameters['id'])){ + throw new TypeErrorParameters($request); + } + try{ + $response->getBody()->write(json_encode((new GatewaySouvenir)->getSouvenirForUser($parameters['id']), JSON_UNESCAPED_UNICODE)); + }catch (PDOException $e){ + throw new PDOError($request,$e->getMessage(),$e); + } + return $response->withHeader('Content-type', 'application/json')->withStatus(200); +}); + +$app->post('/addSouvenir', function(Request $request, Response $response){ + $parameters = $request->getQueryParams(); + if (empty($parameters['title']) + || empty($parameters['linkImage']) + || empty($parameters['description']) + || empty($parameters['longitude']) + || empty($parameters['latitude']) + || empty($parameters['altitude']) + || empty($parameters['userId'])){ + throw new TypeErrorParameters($request); + } + try{ + (new GatewaySouvenir)->addSouvenir($parameters['title'], + $parameters['linkImage'], + $parameters['description'], + $parameters['longitude'], + $parameters['latitude'], + $parameters['altitude'], + $parameters['userId']); + }catch (PDOException $e){ + throw new PDOError($request,$e->getMessage(),$e); + } + $response->getBody()->write("OK"); + return $response->withStatus(200); +}); + +$app->delete('/deleteSouvenir', function(Request $request, Response $response){ + $parameters = $request->getQueryParams(); + if (empty($parameters['id'])){ + throw new TypeErrorParameters($request); + } + try{ + (new GatewaySouvenir)->deleteSouvenir($parameters['id']); + }catch (PDOException $e){ + throw new PDOError($request,$e->getMessage(),$e); + } + $response->getBody()->write("OK"); + return $response->withStatus(200); +}); + +$app->get('/getAllUsers', function(Request $request, Response $response){ + try{ + $response->getBody()->write(json_encode((new GatewayUser)->getAllUsers(), JSON_UNESCAPED_UNICODE)); + }catch (PDOException $e){ + throw new PDOError($request,$e->getMessage(),$e); + } + return $response->withHeader('Content-type', 'application/json')->withStatus(200); +}); + +$app->get('/getUserPassword', function(Request $request, Response $response){ + $parameters = $request->getQueryParams(); + if (empty($parameters['login'])){ + throw new TypeErrorParameters($request); + } + try{ + $response->getBody()->write(json_encode((new GatewayUser)->getUserPassword($parameters['login']), JSON_UNESCAPED_UNICODE)); + }catch (PDOException $e){ + throw new PDOError($request,$e->getMessage(),$e); + } + return $response->withHeader('Content-type', 'application/json')->withStatus(200); +}); + +$app->post('/addUser', function(Request $request, Response $response){ + $parameters = $request->getQueryParams(); + if (empty($parameters['login']) || empty($parameters['password'])){ + throw new TypeErrorParameters($request); + } + try{ + (new GatewayUser)->addUser($parameters['login'],$parameters['password']); + }catch (PDOException $e){ + throw new PDOError($request,$e->getMessage(),$e); + } + $response->getBody()->write("OK"); + return $response->withStatus(200); +}); + + + +// Run app +$app->run();