Ajout de la Planification API
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
34ca7ca60f
commit
014fa79013
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Slim\Factory\AppFactory;
|
||||
use OpenApi\Annotations as OA;
|
||||
|
||||
/**
|
||||
* @OA\Info(title="My First API", version="0.1")
|
||||
*/
|
||||
|
||||
$app->addBodyParsingMiddleware();
|
||||
$app->addRoutingMiddleware();
|
||||
$app->addErrorMiddleware(true, true, true);
|
||||
|
||||
/**
|
||||
* @OA\Get(path="/api/Planification",
|
||||
* @OA\Response(response="200", description="Succes")
|
||||
* @OA\Response(response="500", description="Bdd Error")
|
||||
* )
|
||||
*/
|
||||
|
||||
$app->post('/Planification/FromIdCompte/', function(Request $request, Response $response,array $args){
|
||||
$idCompte = $request->getParsedBody()["id"];
|
||||
$query = 'SELECT * FROM Planification WHERE compte=:id';
|
||||
|
||||
try{
|
||||
$db = new Database();
|
||||
$conn = $db->connect();
|
||||
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->bindValue(':id', $idCompte, PDO::PARAM_STR);
|
||||
|
||||
$stmt->execute();
|
||||
$ope = $stmt->fetchAll(PDO::FETCH_OBJ);
|
||||
|
||||
$db = null;
|
||||
$response->getBody()->write(json_encode($ope));
|
||||
return $response
|
||||
->withHeader('content-type', 'application/json')
|
||||
->withStatus(200);
|
||||
} catch(PDOException $e){
|
||||
$error = array("message" => $e->getMessage());
|
||||
|
||||
$response->getBody()->write(json_encode($error));
|
||||
return $response
|
||||
->withHeader('content-type', 'application/json')
|
||||
->withStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
$app->post('/Planification/add/', function(Request $request, Response $response, array $args){
|
||||
$compte = $request->getParsedBody()["compte"];
|
||||
$nom = $request->getParsedBody()["nom"];
|
||||
$montant = $request->getParsedBody()["montant"];
|
||||
$dateO = $request->getParsedBody()["dateO"];
|
||||
$methodePayement = $request->getParsedBody()["methodePayement"];
|
||||
$isDebit = $request->getParsedBody()["isDebit"];
|
||||
$freq = $request->getParsedBody()["freq"];
|
||||
|
||||
$query = "INSERT INTO Planification (compte, nom, montant, dateO, methodePayement, isDebit, frequance) SELECT :compte,:nom,:montant, STR_TO_DATE(:dateO, '%d/%m/%Y %H:%i:%s' ), :methodePayement, :isD ,:freq;";
|
||||
try{
|
||||
$db = new Database();
|
||||
$conn = $db->connect();
|
||||
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->bindValue(':compte', $compte, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':nom', $nom, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':montant', $montant, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':dateO', $dateO, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':methodePayement', $methodePayement, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':isD', $isDebit, PDO::PARAM_BOOL);
|
||||
$stmt->bindValue(':freq', $freq, PDO::PARAM_STR);
|
||||
|
||||
$result = $stmt->execute();
|
||||
|
||||
$db = null;
|
||||
$response->getBody()->write(json_encode($result));
|
||||
return $response
|
||||
->withHeader('content-type', 'application/json')
|
||||
->withStatus(200);
|
||||
} catch(PDOException $e){
|
||||
$error = array("message" => $e->getMessage());
|
||||
|
||||
$response->getBody()->write(json_encode($error));
|
||||
return $response
|
||||
->withHeader('content-type', 'application/json')
|
||||
->withStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
$app->delete('/Planification/delete/', function (Request $request, Response $response, array $args) {
|
||||
$compte = $request->getParsedBody()["compte"];
|
||||
$nom = $request->getParsedBody()["nom"];
|
||||
|
||||
$query = "DELETE FROM Planification WHERE compte=:compte AND nom=:nom";
|
||||
|
||||
try{
|
||||
$db = new Database();
|
||||
$conn = $db->connect();
|
||||
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->bindValue(':compte', $compte, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':nom', $nom, PDO::PARAM_STR);
|
||||
|
||||
$result = $stmt->execute();
|
||||
|
||||
$db = null;
|
||||
$response->getBody()->write(json_encode($result));
|
||||
return $response
|
||||
->withHeader('content-type', 'application/json')
|
||||
->withStatus(200);
|
||||
|
||||
} catch(PDOException $e){
|
||||
$error = array("message" => $e->getMessage());
|
||||
|
||||
$response->getBody()->write(json_encode($error));
|
||||
return $response
|
||||
->withHeader('content-type', 'application/json')
|
||||
->withStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
?>
|
Loading…
Reference in new issue