@ -8,6 +8,7 @@ use Gateway\GatewayKeyword;
use Gateway\GatewayListResponseOfCandidate;
use Gateway\GatewayPossibleResponse;
use Gateway\GatewayQuestion;
use Gateway\GatewayAdmin;
use Gateway\GatewayResponse;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
@ -72,13 +73,13 @@ $app->delete('/deleteForm', function(Request $request){
}
});
$app->get('/selectForDeleteAndInsert ', function(Request $request, Response $response){
$app->get('/existsForm ', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['id']) || empty($parameters['response'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayForm)->selectForDeleteAndInsert($parameters['id'],$parameters['response'] ), JSON_UNESCAPED_UNICODE));
$response->getBody()->write(json_encode((new GatewayForm)->existsForm( ), JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
@ -315,16 +316,17 @@ $app->post('/insertResponse', function(Request $request, Response $response){
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->post('/insertQuestion', function(Request $request ){
$app->post('/addQuestion', function(Request $request, Response $response ){
$parameters = $request->getQueryParams();
if (empty($parameters['content']) || empty($parameters['classQuestion']) || empty($parameters['idForm']) || empty($parameters['listPossibleResponse']) || empty($parameters['listOfCategories']) ){
if (empty($parameters['content']) || empty($parameters['classQuestion']) || empty($parameters['idForm'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayQuestion)->insert Question($parameters['content'],$parameters['classQuestion'],$parameters['idForm'], $parameters['listPossibleResponse'], $parameters['listOfCategories'] );
$response->getBody()->write(json_encode((new GatewayQuestion)->add Question($parameters['content'],$parameters['classQuestion'],$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->delete('/deleteQuestion', function(Request $request){
@ -377,5 +379,81 @@ $app->get('/getQuestionContentById', function(Request $request, Response $respon
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->get('/getKeywordContentByCategorize', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayKeyword)->getKeywordsContentByCategorize($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('/getPasswordWithLogin', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['login'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayAdmin())->getPasswordWithLogin($parameters['login']),JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->delete('/deletePossibleResponse', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayPossibleResponse)->deletePossibleResponse($parameters['id']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->post('/insertResponseInQuestion', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['response']) || empty($parameters['categories']) || empty($parameters['idQuestion'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayQuestion)->insertResponseInQuestion($parameters['response'],$parameters['categories'],$parameters['idQuestion']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->get('/getCategorizeOfResponsesIdByIdListCandidate', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['listResponse'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayResponse)->getCategorizeOfResponsesIdByIdListCandidate($parameters['listResponse']),JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->get('/getResponsesByQueryAndIdListCandidate', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['query']) || empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayResponse)->getResponsesByQueryAndIdListCandidate($parameters['query'],$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();