Modification of GatewayQuestion.php, finalize all routes in index.php, try to reduce CI time in Dockerfile
continuous-integration/drone/push Build is failing Details

master
dorian.hodin 2 years ago
parent 87a638374d
commit cade423108

@ -1,5 +1,5 @@
FROM php:8.1-apache
RUN apt-get update && apt-get upgrade -y && apt-get install -y git
RUN apt-get install -y git
RUN docker-php-ext-install pdo pdo_mysql
COPY ./script /var/www/html
WORKDIR /var/www/html/Config

@ -16,8 +16,9 @@ class GatewayQuestion
try{
$this->connection = (new ConnectClass)->connect();
}catch(PDOException $e){
throw new PDOException();
} }
throw new PDOException($e->getMessage(), $e->getCode(), $e);
}
}
public function insertQuestion(string $contentQuestion, string $classQuestion, int $idForm, array $listPossibleResponse, array $listOfCategories): void
{
@ -52,15 +53,15 @@ class GatewayQuestion
}
}
public function deleteQuestion(QuestionAPI $question): void
public function deleteQuestion(string $questionClass, int $idQuestion, array $questionGetPossibleResponse): void
{
if(get_class($question) == BoxQuestionAPI::class) {
if($questionClass == "BoxQuestionAPI") {
$query = "DELETE FROM Propose WHERE question = :id";
$this->connection->executeQuery($query, array(
':id' => array($question->getId(), PDO::PARAM_INT)
':id' => array($idQuestion, PDO::PARAM_INT)
));
$listPossibleResponse = $question->getPossibleResponses();
$listPossibleResponse = $questionGetPossibleResponse;
for ($i = 0; $i < count($listPossibleResponse); $i++){
$query = "DELETE FROM Reference WHERE response = :id";
$this->connection->executeQuery($query, array(
@ -76,22 +77,22 @@ class GatewayQuestion
$query = "DELETE FROM Question WHERE id = :id";
$this->connection->executeQuery($query, array(
':id' => array($question->getId(), PDO::PARAM_INT)
':id' => array($idQuestion, PDO::PARAM_INT)
));
}
public function updateQuestion(QuestionAPI $question): void
public function updateQuestion(string $questionContent, string $questionClass, string $questionGetForm, string $idQuestion): void
{
$query = "UPDATE Question SET content = :content, type = :type, form = :form WHERE id = :id";
$this->connection->executeQuery($query, array(
':content' => array($question->getContent(), PDO::PARAM_STR),
':type' => array(get_class($question), PDO::PARAM_STR),
':form' => array($question->getForm(), PDO::PARAM_STR),
':id' => array($question->getId(), PDO::PARAM_STR)
':content' => array($questionContent, PDO::PARAM_STR),
':type' => array($questionClass, PDO::PARAM_STR),
':form' => array($questionGetForm, PDO::PARAM_STR),
':id' => array($idQuestion, PDO::PARAM_STR)
));
}
public function getAllQuestions(array $idForm): array //Print en json un array contenant trois qui pour chaque indice commun de ces 3 array une question, sa liste de reponse possible et sa liste de keyword associer au réponse. les deux autres sont null si c'est une textBox
public function getAllQuestions(array $idForm): array
{
$query = "SELECT * FROM Question WHERE form = :form";
$this->connection->executeQuery($query, array(

@ -7,6 +7,7 @@ use Gateway\GatewayForm;
use Gateway\GatewayKeyword;
use Gateway\GatewayListResponseOfCandidate;
use Gateway\GatewayPossibleResponse;
use Gateway\GatewayQuestion;
use Gateway\GatewayResponse;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
@ -108,7 +109,6 @@ $app->delete('/deleteKeywordFromQuestion', function(Request $request){
}
});
$app->put('/updateTitleToForm', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['id']) || empty($parameters['title'])){
@ -145,7 +145,7 @@ $app->delete('/deleteDescriptionToForm', function(Request $request){
}
});
$app->put('/insertKeyword', function(Request $request){
$app->post('/insertKeyword', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['keyword'])){
throw new TypeErrorParameters($request);
@ -157,7 +157,7 @@ $app->put('/insertKeyword', function(Request $request){
}
});
$app->put('/deleteKeyword', function(Request $request){
$app->delete('/deleteKeyword', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['keyword'])){
throw new TypeErrorParameters($request);
@ -214,7 +214,7 @@ $app->get('/getAllListResponseOfCandidate', function(Request $request, Response
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->put('/deleteListResponseOfCandidate', function(Request $request){
$app->delete('/deleteListResponseOfCandidate', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
@ -226,7 +226,7 @@ $app->put('/deleteListResponseOfCandidate', function(Request $request){
}
});
$app->put('/insertListResponseOfCandidate', function(Request $request){
$app->post('/insertListResponseOfCandidate', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['answer']) || empty($parameters['titleForm']) || empty($parameters['idQuestion'])){
throw new TypeErrorParameters($request);
@ -244,20 +244,20 @@ $app->get('/getPossibleResponseByQuestion', function(Request $request, Response
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayPossibleResponse)->getPossibleResponseByQuestion($parameters['id'])));
$response->getBody()->write(json_encode((new GatewayPossibleResponse)->getPossibleResponseByQuestion($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->get('/insertPossibleResponse', function(Request $request, Response $response){
$app->post('/insertPossibleResponse', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['content'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayPossibleResponse)->insertPossibleResponse($parameters['content'])));
$response->getBody()->write(json_encode((new GatewayPossibleResponse)->insertPossibleResponse($parameters['content']),JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
@ -270,7 +270,7 @@ $app->get('/getResponsesByIdListCandidate', function(Request $request, Response
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayResponse)->getResponsesByIdListCandidate($parameters['id'])));
$response->getBody()->write(json_encode((new GatewayResponse)->getResponsesByIdListCandidate($parameters['id']),JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
@ -283,14 +283,14 @@ $app->get('/getResponsesIdByIdListCandidate', function(Request $request, Respons
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayResponse)->getResponsesIdByIdListCandidate($parameters['id'])));
$response->getBody()->write(json_encode((new GatewayResponse)->getResponsesIdByIdListCandidate($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->put('/deleteResponseById', function(Request $request){
$app->delete('/deleteResponseById', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
@ -302,7 +302,7 @@ $app->put('/deleteResponseById', function(Request $request){
}
});
$app->get('/insertResponse', function(Request $request, Response $response){
$app->post('/insertResponse', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['content']) || empty($parameters['questionContent']) || empty($parameters['category'])){
throw new TypeErrorParameters($request);
@ -315,6 +315,67 @@ $app->get('/insertResponse', function(Request $request, Response $response){
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->post('/insertQuestion', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['content']) || empty($parameters['classQuestion']) || empty($parameters['idForm']) || empty($parameters['listPossibleResponse']) || empty($parameters['listOfCategories'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayQuestion)->insertQuestion($parameters['content'],$parameters['classQuestion'],$parameters['idForm'], $parameters['listPossibleResponse'], $parameters['listOfCategories']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->delete('/deleteQuestion', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['classQuestion']) || empty($parameters['id']) || empty($parameters['listPossibleResponse'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayQuestion)->deleteQuestion($parameters['classQuestion'],$parameters['id'], $parameters['listPossibleResponse']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->put('/updateQuestion', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['content']) || empty($parameters['classQuestion']) || empty($parameters['questionGetForm']) || empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayQuestion)->updateQuestion($parameters['content'],$parameters['classQuestion'],$parameters['questionGetForm'], $parameters['id']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->get('/getAllQuestions', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['idForm'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayQuestion)->getAllQuestions($parameters['idForm']),JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->get('/getQuestionContentById', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayQuestion)->getQuestionContentById($parameters['id']),JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
// Run app
$app->run();

Loading…
Cancel
Save