Reorganize
This commit is contained in:
parent
c65d95621d
commit
ba0e7ede16
@ -5,14 +5,12 @@ namespace WebProjectFitness\API;
|
|||||||
use WebProjectFitness\Model\BDTables;
|
use WebProjectFitness\Model\BDTables;
|
||||||
use WebProjectFitness\Model\Model;
|
use WebProjectFitness\Model\Model;
|
||||||
|
|
||||||
class APIUser extends API
|
class APIUser extends API {
|
||||||
{
|
|
||||||
|
|
||||||
private $declaredFunctions = [
|
private $declaredFunctions = [
|
||||||
'create' => [
|
'create' => [
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'params' => [
|
'params' => []
|
||||||
]
|
|
||||||
],
|
],
|
||||||
'modify' => [
|
'modify' => [
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
@ -109,69 +107,61 @@ class APIUser extends API
|
|||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct()
|
public function __construct() {
|
||||||
{
|
parent::__construct( $this->declaredFunctions );
|
||||||
parent::__construct($this->declaredFunctions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//functions for user table.
|
//functions for user table.
|
||||||
public function create($data)
|
public function create( $data ) {
|
||||||
{
|
|
||||||
$bytes = null;
|
$bytes = null;
|
||||||
if (function_exists("random_bytes")) {
|
if ( function_exists( "random_bytes" ) ) {
|
||||||
$bytes = random_bytes(ceil(6 / 2));
|
$bytes = random_bytes( ceil( 6 / 2 ) );
|
||||||
} elseif (function_exists("openssl_random_pseudo_bytes")) {
|
} elseif ( function_exists( "openssl_random_pseudo_bytes" ) ) {
|
||||||
$bytes = openssl_random_pseudo_bytes(ceil(6 / 2));
|
$bytes = openssl_random_pseudo_bytes( ceil( 6 / 2 ) );
|
||||||
}
|
}
|
||||||
$id = substr(bin2hex($bytes), 0, 6);
|
$id = substr( bin2hex( $bytes ), 0, 6 );
|
||||||
Model::insert(BDTables::USER, [
|
Model::insert( BDTables::USER, [
|
||||||
"name" => "",
|
"name" => "",
|
||||||
"user_id" => $id
|
"user_id" => $id
|
||||||
]);
|
] );
|
||||||
$this->returnJson(['id' => $id]);
|
$this->returnJson( [ 'id' => $id ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function modify($data)
|
public function modify( $data ) {
|
||||||
{
|
Model::update( BDTables::USER, [ 'name' => $data[ 'name' ] ], "user_id", $data[ 'user_id' ] );
|
||||||
Model::update(BDTables::USER, ['name' => $data['name']], "user_id", $data['user_id']);
|
$this->returnJson( [ 'name' => $data[ 'name' ], 'id' => $data[ 'user_id' ] ] );
|
||||||
$this->returnJson(['name' => $data['name'], 'id' => $data['user_id']]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Functions for favorite table.
|
//Functions for favorite table.
|
||||||
public function favoriteAdd($data)
|
public function favoriteAdd( $data ) {
|
||||||
{
|
Model::insert( BDTables::FAVORITE, [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ] ] );
|
||||||
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' ] ] );
|
||||||
$this->returnJson(['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise']]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function favoriteDelete($data)
|
public function favoriteDelete( $data ) {
|
||||||
{
|
Model::delete( BDTables::FAVORITE, [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ] ] );
|
||||||
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' ] ] );
|
||||||
$this->returnJson(['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise']]);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//functions for training table
|
//functions for training table
|
||||||
public function trainingAdd($data)
|
public function trainingAdd( $data ) {
|
||||||
{
|
Model::insert( BDTables::TRAINING, [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ], 'id_order' => $data[ 'id_order' ] ] );
|
||||||
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' ] ] );
|
||||||
$this->returnJson(['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise'], 'id_order' => $data['id_order']]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function trainingDelete($data)
|
public function trainingDelete( $data ) {
|
||||||
{
|
Model::delete( BDTables::TRAINING, [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ], 'id_order' => $data[ 'id_order' ] ] );
|
||||||
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']]);
|
$this->returnJson( [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ], 'id_order' => $data[ 'id_order' ] ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function trainingChangeOrder($data)
|
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' ] );
|
||||||
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']]);
|
$this->returnJson( [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ], 'id_order' => $data[ 'id_order' ], 'new_order' => $data[ 'new_order' ] ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user