This commit is contained in:
xoxel 2018-12-13 06:42:08 +01:00
parent 0393733bcd
commit 46be9eb7f4
4 changed files with 195 additions and 16 deletions

View File

@ -20,6 +20,11 @@ RewriteCond %{HTTP_HOST} ^fitness.sanchez-mathieu.test$
RewriteCond %{DOCUMENT_ROOT}/static%{REQUEST_URI} -f
RewriteRule ^(.*)$ static/$1 [L,E=END:1]
# Redirection des fichiers static pour cauweb.fr
RewriteCond %{HTTP_HOST} ^cauweb.fr$
RewriteCond %{DOCUMENT_ROOT}/static%{REQUEST_URI} -f
RewriteRule ^(.*)$ static/$1 [L,E=END:1]
# RewriteRule ^haute-garonne/toulouse/installation-entretien-climatisation /haute-garonne/toulouse/climatisation.php [L]
# Redirection de toutes les requêtes vers Index.php

View File

@ -35,7 +35,9 @@ if ( count( $pages ) > 1 && $pages[ count( $pages ) - 1 ] == '' ) {
if ( $pages[ 0 ] == 'api' && isset( $pages[ 1 ] ) && preg_match( '#^([a-z]+)$#', $pages[ 1 ], $api1 ) && isset( $pages[ 2 ] ) && preg_match( '#^([a-z-]+)$#', $pages[ 2 ], $api2 ) ) {
new APIRouter( $api1[ 0 ], $api2[ 0 ] );
} else if ( preg_match( '#^fitness.sanchez-mathieu\.test$#', $_SERVER[ 'SERVER_NAME' ] ) || preg_match( '#^fitness.sanchez-mathieu\.fr$#', $_SERVER[ 'SERVER_NAME' ] ) ) {
} else if ( preg_match( '#^fitness.sanchez-mathieu\.test$#', $_SERVER[ 'SERVER_NAME' ] )
|| preg_match( '#^fitness.sanchez-mathieu\.fr$#', $_SERVER[ 'SERVER_NAME' ] )
|| preg_match( '#^cauweb\.fr$#', $_SERVER[ 'SERVER_NAME' ] )) {
new SiteRouter( $pages );
} else {
new Error( 404 );

View File

@ -5,30 +5,168 @@ namespace WebProjectFitness\API;
use WebProjectFitness\Model\BDTables;
use WebProjectFitness\Model\Model;
class APIUser extends API {
class APIUser extends API
{
private $declaredFunctions = [
'create' => [
'method' => 'GET',
'method' => 'POST',
'params' => [
// 'id' => [
// 'required' => true,
// 'type' => 'string'
// ]
]
],
'modify' => [
'method' => 'POST',
'params' => [
'user_id' => [
'required' => true,
'type' => 'string'
],
'name' => [
'required' => true,
'type' => 'string'
]
]
],
'favorite-delete' => [
'method' => 'POST',
'params' => [
'id_user' => [
'required' => true,
'type' => 'string'
],
'id_exercise' => [
'required' => true,
'type' => 'int'
]
]
],
'favorite-add' => [
'method' => 'POST',
'params' => [
'id_user' => [
'required' => true,
'type' => 'string'
],
'id_exercise' => [
'required' => true,
'type' => 'int'
]
]
],
'training-add' => [
'method' => 'POST',
'params' => [
'id_user' => [
'required' => true,
'type' => 'string'
],
'id_exercise' => [
'required' => true,
'type' => 'int'
], 'id_order' => [
'required' => true,
'type' => 'int'
]
]
],
'training-delete' => [
'method' => 'POST',
'params' => [
'id_user' => [
'required' => true,
'type' => 'string'
],
'id_exercise' => [
'required' => true,
'type' => 'int'
], 'id_order' => [
'required' => true,
'type' => 'int'
]
]
],
'training-change-order' => [
'method' => 'POST',
'params' => [
'id_user' => [
'required' => true,
'type' => 'string'
],
'id_exercise' => [
'required' => true,
'type' => 'int'
], 'id_order' => [
'required' => true,
'type' => 'int'
],
'new_order' => [
'required' => true,
'type' => 'int'
]
]
]
];
public function __construct() {
public function __construct()
{
parent::__construct($this->declaredFunctions);
}
public function create( $data ) {
//functions for user table.
public function create($data)
{
$id = uniqid();
$id = substr($id, 0, 6);
Model::insert(BDTables::USER, [
"name" => "Mathi",
"user_id" => "bite"
"name" => "",
"user_id" => $id
]);
$this->returnJson( [ 'body' => 'truc' ] );
$this->returnJson(['id' => $id]);
}
public function modify($data)
{
Model::update(BDTables::USER, ['name' => $data['name']], "user_id", $data['user_id']);
$this->returnJson(['name' => $data['name'], 'id' => $data['user_id']]);
}
//Functions for favorite table.
public function favoriteAdd($data)
{
Model::insert(BDTables::FAVORITE, ['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise']]);
$this->returnJson(['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise']]);
}
public function favoriteDelete($data)
{
Model::delete(BDTables::FAVORITE, ['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise']]);
$this->returnJson(['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise']]);
}
//functions for training table
public function trainingAdd($data)
{
Model::insert(BDTables::TRAINING, ['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise'], 'id_order' => $data['id_order']]);
$this->returnJson(['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise'], 'id_order' => $data['id_order']]);
}
public function trainingDelete($data)
{
Model::delete(BDTables::TRAINING, ['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise'], 'id_order' => $data['id_order']]);
$this->returnJson(['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise'], 'id_order' => $data['id_order']]);
}
public function trainingChangeOrder($data)
{
Model::update_order(BDTables::TRAINING, ['id_user' => $data['id_user'], 'id_order' => $data['id_order'], 'id_exercise' => $data['id_exercise'] ], $data['new_order']);
$this->returnJson(['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise'], 'id_order' => $data['id_order'], 'new_order' => $data['new_order']]);
}
}

View File

@ -28,7 +28,7 @@ class Model {
* @param string $idColumn
* @param int $idValue
*/
public static function update( string $tableName, array $data, string $idColumn, int $idValue ) {
public static function update( string $tableName, array $data, string $idColumn, string $idValue ) {
$reqStr = 'UPDATE ' . $tableName . ' SET ';
$lastKey = endKey( $data );
foreach ( $data as $key => $value ) {
@ -45,6 +45,40 @@ class Model {
$req = BDD::instance()->prepare( $reqStr );
$req->execute( $data );
}
public static function delete (string $tableName, array $data){
$reqStr = 'DELETE FROM ' . $tableName . ' WHERE ';
$lastKey = endKey( $data );
foreach ( $data as $key => $value ) {
$reqStr .= $key . ' = :' . $key;
if ( $key != $lastKey ) {
$reqStr .= ' AND ';
}
}
//echo $reqStr; exit();
$req = BDD::instance()->prepare( $reqStr );
$req->execute( $data );
}
public static function update_order( string $tableName, array $data, string $newOrder) {
$reqStr = 'UPDATE ' . $tableName . ' SET id_order = :newOrder WHERE ';
$lastKey = endKey( $data );
foreach ( $data as $key => $value ) {
$reqStr .= $key . ' = :' . $key;
if ( $key != $lastKey ) {
$reqStr .= ' AND ';
}
}
$data[ 'newOrder' ] = $newOrder;
//echo $reqStr; exit();
$req = BDD::instance()->prepare( $reqStr );
$req->execute( $data );
}
}
?>