Modification de l'API pour ajout d'un user et récupération d'informations sur un user
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
437d16b25d
commit
f1b7bb2df5
@ -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
|
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/symfony/translation" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/nesbot/carbon" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/pimple/pimple" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/psr/simple-cache" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/psr/http-message" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/illuminate/support" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/psr/container" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/doctrine/inflector" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/illuminate/contracts" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/slim/slim" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/illuminate/database" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/illuminate/container" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/nikic/fast-route" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/composer" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/symfony/polyfill-php80" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/kylekatarnls/update-helper" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/symfony/translation-contracts" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/sources/vendor/symfony/polyfill-mbstring" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/api_database.iml" filepath="$PROJECT_DIR$/.idea/api_database.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="PhpIncludePathManager">
|
||||||
|
<include_path>
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/symfony/translation" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/nesbot/carbon" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/pimple/pimple" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/psr/simple-cache" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/psr/http-message" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/illuminate/support" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/psr/container" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/doctrine/inflector" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/illuminate/contracts" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/slim/slim" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/illuminate/database" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/illuminate/container" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/nikic/fast-route" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/composer" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/symfony/polyfill-php80" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/kylekatarnls/update-helper" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/symfony/translation-contracts" />
|
||||||
|
<path value="$PROJECT_DIR$/sources/vendor/symfony/polyfill-mbstring" />
|
||||||
|
</include_path>
|
||||||
|
</component>
|
||||||
|
<component name="PhpProjectSharedConfiguration" php_language_level="7.4">
|
||||||
|
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="SqlDialectMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$/database/dafl_music.sql" dialect="MariaDB" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Connection extends PDO
|
||||||
|
{
|
||||||
|
|
||||||
|
private $stmt;
|
||||||
|
|
||||||
|
public function __construct(string $dsn, string $username, string $password)
|
||||||
|
{
|
||||||
|
|
||||||
|
parent::__construct($dsn, $username, $password);
|
||||||
|
$this->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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require "gateways/UserGateway.php";
|
||||||
|
require "business/User.php";
|
||||||
|
|
||||||
|
class Model
|
||||||
|
{
|
||||||
|
public function getInformationsUser($id): array
|
||||||
|
{
|
||||||
|
global $app;
|
||||||
|
$db = $app->getContainer()['settings']['db'];
|
||||||
|
$gw = new UserGateway(new Connection($db['dsn'], $db['user'], $db['pass']));
|
||||||
|
$id = filter_var($id, FILTER_SANITIZE_STRING);
|
||||||
|
$userDb = $gw->getInformations($id);
|
||||||
|
$user = new User($userDb[0][0], $userDb[0][1]);
|
||||||
|
return $user->getInformations();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addUser($idDafl, $idSpotify, $passw): void
|
||||||
|
{
|
||||||
|
global $app;
|
||||||
|
$db = $app->getContainer()['settings']['db'];
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
$data['idDafl'] = filter_var($idDafl, FILTER_SANITIZE_STRING);
|
||||||
|
$data['idSpotify'] = filter_var($idSpotify, FILTER_SANITIZE_STRING);
|
||||||
|
$data['passw'] = filter_var($passw, FILTER_SANITIZE_STRING);
|
||||||
|
|
||||||
|
$gw = new UserGateway(new Connection($db['dsn'], $db['user'], $db['pass']));
|
||||||
|
$gw->addUser($data['idDafl'], $data['idSpotify'], $data['passw']);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
use Illuminate\Database\Eloquent\Model as Model;
|
|
||||||
class User extends Model {
|
|
||||||
|
|
||||||
protected $table = 'users';
|
|
||||||
}
|
|
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class User
|
||||||
|
{
|
||||||
|
private string $idDafl;
|
||||||
|
private string $idSpotify;
|
||||||
|
|
||||||
|
public function __construct(string $idDafl, string $idSpotify)
|
||||||
|
{
|
||||||
|
$this->idDafl = $idDafl;
|
||||||
|
$this->idSpotify = $idSpotify;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getIdDafl(): string
|
||||||
|
{
|
||||||
|
return $this->idDafl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getIdSpotify(): string
|
||||||
|
{
|
||||||
|
return $this->idSpotify;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInformations(): array
|
||||||
|
{
|
||||||
|
return array($this->idDafl, $this->idSpotify);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,16 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$config=[
|
$config['displayErrorDetails'] = true;
|
||||||
'determineRouteBeforeAppMiddleware' => false,
|
$config['addContentLengthHeader'] = false;
|
||||||
'displayErrorDetails' => true,
|
|
||||||
'db' => [
|
$config['db']['dsn'] = 'mysql:host=localhost;dbname=dafl_music';
|
||||||
'driver' => 'mysql',
|
$config['db']['user'] = 'root';
|
||||||
'host' => 'localhost',
|
$config['db']['pass'] = 'root';
|
||||||
'database' => 'dafl_music',
|
|
||||||
'username' => 'root',
|
|
||||||
'password' => 'root',
|
|
||||||
'charset' => 'utf8',
|
|
||||||
'collation' => 'utf8_unicode_ci',
|
|
||||||
'prefix' => ''
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
$container = $app->getContainer();
|
|
||||||
|
|
||||||
$container['db'] = function ($container) {
|
|
||||||
$capsule = new \Illuminate\Database\Capsule\Manager;
|
|
||||||
$capsule->addConnection($container['settings']['db']);
|
|
||||||
|
|
||||||
$capsule->setAsGlobal();
|
|
||||||
$capsule->bootEloquent();
|
|
||||||
|
|
||||||
return $capsule;
|
|
||||||
};
|
|
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class UserGateway
|
||||||
|
{
|
||||||
|
private Connection $con;
|
||||||
|
|
||||||
|
public function __construct(Connection $con)
|
||||||
|
{
|
||||||
|
$this->con = $con;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInformations($id): array
|
||||||
|
{
|
||||||
|
$query = 'SELECT idDafl,idSpotify FROM users WHERE idDafl=:id';
|
||||||
|
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR)));
|
||||||
|
return $this->con->getResults();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addUser($idDafl, $idSpotify, $passw)
|
||||||
|
{
|
||||||
|
$query = 'INSERT INTO users VALUES (:idDafl,:idSpotify,:passw)';
|
||||||
|
$this->con->executeQuery($query, array(':idDafl' => array($idDafl, PDO::PARAM_STR), ':idSpotify' => array($idSpotify, PDO::PARAM_STR), ':passw' => array($passw, PDO::PARAM_STR)));
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"slim/slim": "3.*",
|
"slim/slim": "3.*",
|
||||||
"illuminate/database": "~5.1"
|
"illuminate/database": "~5.1",
|
||||||
},
|
"ext-json": "*"
|
||||||
"config": {
|
},
|
||||||
"allow-plugins": {
|
"config": {
|
||||||
"kylekatarnls/update-helper": true
|
"allow-plugins": {
|
||||||
}
|
"kylekatarnls/update-helper": true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue