addRoutingMiddleware(); /** * Add Error Handling Middleware * * @param bool $displayErrorDetails -> Should be set to false in production * @param bool $logErrors -> Parameter is passed to the default ErrorHandler * @param bool $logErrorDetails -> Display error details in error log */ $errorMiddleware = $app->addErrorMiddleware(true, true, true); /** * Add a route for the API */ $app->get('/', function (Request $request) { throw new HttpNotFoundError($request); }); $app->get('/getForm', function(Request $request, Response $response){ try{ $response->getBody()->write(json_encode((new GatewayForm)->getForm(), JSON_UNESCAPED_UNICODE)); }catch (PDOException $e){ throw new PDOError($request,$e->getMessage(),$e); } return $response->withHeader('Content-type', 'application/json')->withStatus(200); }); $app->put('/insertForm', function(Request $request){ $parameters = $request->getQueryParams(); if (empty($parameters['title']) || empty($parameters['description'])){ throw new TypeErrorParameters($request); } try{ (new GatewayForm)->insertForm($parameters['title'],$parameters['description']); }catch (PDOException $e){ throw new PDOError($request,$e->getMessage(),$e); } }); $app->put('/deleteForm', function(Request $request){ $parameters = $request->getQueryParams(); if (empty($parameters['id'])){ throw new TypeErrorParameters($request); } try{ (new GatewayForm)->deleteForm($parameters['id']); }catch (PDOException $e){ throw new PDOError($request,$e->getMessage(),$e); } }); $app->get('/selectForDeleteAndInsert', 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)); }catch (PDOException $e){ throw new PDOError($request,$e->getMessage(),$e); } return $response->withHeader('Content-type', 'application/json')->withStatus(200); }); $app->put('/assignKeywordToQuestion', function(Request $request){ $parameters = $request->getQueryParams(); if (empty($parameters['keyword']) || empty($parameters['id']) || empty($parameters['response'])){ throw new TypeErrorParameters($request); } try{ (new GatewayForm)->assignKeywordToQuestion($parameters['keyword'],$parameters['id'],$parameters['response']); }catch (PDOException $e){ throw new PDOError($request,$e->getMessage(),$e); } }); $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();