@ -4,6 +4,10 @@ use ExceptionHandle\HttpNotFoundError;
use ExceptionHandle\PDOError;
use ExceptionHandle\TypeErrorParameters;
use Gateway\GatewayForm;
use Gateway\GatewayKeyword;
use Gateway\GatewayListResponseOfCandidate;
use Gateway\GatewayPossibleResponse;
use Gateway\GatewayResponse;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
@ -30,7 +34,7 @@ $errorMiddleware = $app->addErrorMiddleware(true, true, true);
/**
* Add a route for the API
*/
$app->get('/', function (Request $request, Response $response ) {
$app->get('/', function (Request $request) {
throw new HttpNotFoundError($request);
});
@ -43,7 +47,7 @@ $app->get('/getForm', function(Request $request, Response $response){
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->put('/insertForm', function(Request $request, Response $response ){
$app->put('/insertForm', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['title']) || empty($parameters['description'])){
throw new TypeErrorParameters($request);
@ -55,7 +59,7 @@ $app->put('/insertForm', function(Request $request, Response $response){
}
});
$app->put('/deleteForm', function(Request $request, Response $response ){
$app->put('/deleteForm', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
@ -80,7 +84,7 @@ $app->get('/selectForDeleteAndInsert', function(Request $request, Response $resp
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->put('/assignKeywordToQuestion', function(Request $request, Response $response ){
$app->put('/assignKeywordToQuestion', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['keyword']) || empty($parameters['id']) || empty($parameters['response'])){
throw new TypeErrorParameters($request);
@ -92,6 +96,225 @@ $app->put('/assignKeywordToQuestion', function(Request $request, Response $respo
}
});
$app->put('/deleteKeywordFromQuestion', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['keyword']) || empty($parameters['id']) || empty($parameters['response'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayForm)->deleteKeywordFromQuestion($parameters['keyword'],$parameters['id'],$parameters['response']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->put('/updateTitleToForm', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['id']) || empty($parameters['title'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayForm)->updateTitleToForm($parameters['id'],$parameters['title']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->put('/updateDescriptionToForm', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['id']) || empty($parameters['description'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayForm)->updateDescriptionToForm($parameters['id'],$parameters['description']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->put('/deleteDescriptionToForm', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayForm)->deleteDescriptionToForm($parameters['id']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->put('/insertKeyword', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['keyword'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayKeyword)->insertKeyword($parameters['keyword']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->put('/deleteKeyword', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['keyword'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayKeyword)->deleteKeyword(($parameters['keyword']));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->get('getAllKeyword', function(Request $request, Response $response){
try{
$response->getBody()->write(json_encode((new GatewayKeyword)->getAllKeyword(),JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->get('/getKeywordsContentByReference', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayKeyword)->getKeywordsContentByReference($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('/getDetailsListResponseOfCandidate', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayListResponseOfCandidate)->getDetailsListResponsesOfCandidate($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('/getAllListResponseOfCandidate', function(Request $request, Response $response){
try{
$response->getBody()->write(json_encode((new GatewayListResponseOfCandidate)->getAllListResponsesOfCandidate(),JSON_UNESCAPED_UNICODE));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->put('/deleteListResponseOfCandidate', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayListResponseOfCandidate)->deleteListResponseOfCandidate($parameters['id']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->put('/insertListResponseOfCandidate', function(Request $request){
$parameters = $request->getQueryParams();
if (empty($parameters['answer']) || empty($parameters['titleForm']) || empty($parameters['idQuestion'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayListResponseOfCandidate)->insertListResponsesOfCandidate($parameters['answer'],$parameters['titleForm'],$parameters['idQuestion']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->get('/getPossibleResponseByQuestion', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayPossibleResponse)->getPossibleResponseByQuestion($parameters['id'])));
}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){
$parameters = $request->getQueryParams();
if (empty($parameters['content'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayPossibleResponse)->insertPossibleResponse($parameters['content'])));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->get('/getResponsesByIdListCandidate', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayResponse)->getResponsesByIdListCandidate($parameters['id'])));
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
return $response->withHeader('Content-type', 'application/json')->withStatus(200);
});
$app->get('/getResponsesIdByIdListCandidate', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayResponse)->getResponsesIdByIdListCandidate($parameters['id'])));
}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){
$parameters = $request->getQueryParams();
if (empty($parameters['id'])){
throw new TypeErrorParameters($request);
}
try{
(new GatewayResponse)->deleteResponseById($parameters['id']);
}catch (PDOException $e){
throw new PDOError($request,$e->getMessage(),$e);
}
});
$app->get('/insertResponse', function(Request $request, Response $response){
$parameters = $request->getQueryParams();
if (empty($parameters['content']) || empty($parameters['questionContent']) || empty($parameters['category'])){
throw new TypeErrorParameters($request);
}
try{
$response->getBody()->write(json_encode((new GatewayResponse)->insertResponse($parameters['content'],$parameters['questionContent'],$parameters['category']),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();