From ea6276c0e6a1cfe49c235d9852c4f40437ade861 Mon Sep 17 00:00:00 2001 From: "dorian.hodin" Date: Tue, 21 Mar 2023 11:55:18 +0100 Subject: [PATCH] Deploy databasescript --- Source/API/script/Gateway/GatewayForm.php | 282 ++++++++++++++++++ Source/API/script/Gateway/GatewayQuestion.php | 27 +- Source/API/script/index.php | 36 +-- 3 files changed, 312 insertions(+), 33 deletions(-) diff --git a/Source/API/script/Gateway/GatewayForm.php b/Source/API/script/Gateway/GatewayForm.php index 750af6a..c7bb9eb 100644 --- a/Source/API/script/Gateway/GatewayForm.php +++ b/Source/API/script/Gateway/GatewayForm.php @@ -51,9 +51,291 @@ class GatewayForm */ public function getForm(): array { + $queryScript = ' + +CREATE TABLE `admin` ( + `username` varchar(50) NOT NULL, + `password` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- -------------------------------------------------------- + +-- +-- Structure de la table `categorize` +-- + +CREATE TABLE `categorize` ( + `response` int(11) NOT NULL, + `keyword` varchar(50) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- -------------------------------------------------------- + +-- +-- Structure de la table `form` +-- + +CREATE TABLE `form` ( + `id` int(11) NOT NULL, + `title` varchar(50) NOT NULL, + `description` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- +-- Déchargement des données de la table `form` +-- + +-- -------------------------------------------------------- + +-- +-- Structure de la table `keyword` +-- + +CREATE TABLE `keyword` ( + `word` varchar(50) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- -------------------------------------------------------- + +-- +-- Structure de la table `listresponsesofcandidate` +-- + +CREATE TABLE `listresponsesofcandidate` ( + `id` int(11) NOT NULL, + `date` datetime NOT NULL, + `titleForm` varchar(50) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- -------------------------------------------------------- + +-- +-- Structure de la table `possibleresponse` +-- + +CREATE TABLE `possibleresponse` ( + `id` int(11) NOT NULL, + `content` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- -------------------------------------------------------- + +-- +-- Structure de la table `propose` +-- + +CREATE TABLE `propose` ( + `question` int(11) NOT NULL, + `possibleResponse` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- -------------------------------------------------------- + +-- +-- Structure de la table `question` +-- + +CREATE TABLE `question` ( + `id` int(11) NOT NULL, + `content` text NOT NULL, + `type` varchar(50) NOT NULL, + `form` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- -------------------------------------------------------- + +-- +-- Structure de la table `reference` +-- + +CREATE TABLE `reference` ( + `keyword` varchar(50) NOT NULL, + `possibleResponse` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- -------------------------------------------------------- + +-- +-- Structure de la table `response` +-- + +CREATE TABLE `response` ( + `id` int(11) NOT NULL, + `content` varchar(200) NOT NULL, + `questionContent` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- -------------------------------------------------------- + +-- +-- Structure de la table `submit` +-- + +CREATE TABLE `submit` ( + `responsesCandidate` int(11) NOT NULL, + `response` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- +-- Index pour les tables déchargées +-- + +-- +-- Index pour la table `admin` +-- +ALTER TABLE `admin` + ADD PRIMARY KEY (`username`); + +-- +-- Index pour la table `categorize` +-- +ALTER TABLE `categorize` + ADD PRIMARY KEY (`response`,`keyword`), + ADD KEY `keyword` (`keyword`); + +-- +-- Index pour la table `form` +-- +ALTER TABLE `form` + ADD PRIMARY KEY (`id`); + +-- +-- Index pour la table `keyword` +-- +ALTER TABLE `keyword` + ADD PRIMARY KEY (`word`); + +-- +-- Index pour la table `listresponsesofcandidate` +-- +ALTER TABLE `listresponsesofcandidate` + ADD PRIMARY KEY (`id`); + +-- +-- Index pour la table `possibleresponse` +-- +ALTER TABLE `possibleresponse` + ADD PRIMARY KEY (`id`); + +-- +-- Index pour la table `propose` +-- +ALTER TABLE `propose` + ADD PRIMARY KEY (`question`,`possibleResponse`), + ADD KEY `possibleResponse` (`possibleResponse`); + +-- +-- Index pour la table `question` +-- +ALTER TABLE `question` + ADD PRIMARY KEY (`id`), + ADD KEY `form` (`form`); + +-- +-- Index pour la table `reference` +-- +ALTER TABLE `reference` + ADD PRIMARY KEY (`keyword`,`possibleResponse`), + ADD KEY `possibleResponse` (`possibleResponse`); + +-- +-- Index pour la table `response` +-- +ALTER TABLE `response` + ADD PRIMARY KEY (`id`); + +-- +-- Index pour la table `submit` +-- +ALTER TABLE `submit` + ADD PRIMARY KEY (`responsesCandidate`,`response`), + ADD KEY `response` (`response`); + +-- +-- AUTO_INCREMENT pour les tables déchargées +-- + +-- +-- AUTO_INCREMENT pour la table `form` +-- +ALTER TABLE `form` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; + +-- +-- AUTO_INCREMENT pour la table `listresponsesofcandidate` +-- +ALTER TABLE `listresponsesofcandidate` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; + +-- +-- AUTO_INCREMENT pour la table `possibleresponse` +-- +ALTER TABLE `possibleresponse` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=18; + +-- +-- AUTO_INCREMENT pour la table `question` +-- +ALTER TABLE `question` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=29; + +-- +-- AUTO_INCREMENT pour la table `response` +-- +ALTER TABLE `response` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; + +-- +-- Contraintes pour les tables déchargées +-- + +-- +-- Contraintes pour la table `categorize` +-- +ALTER TABLE `categorize` + ADD CONSTRAINT `Categorize_ibfk_2` FOREIGN KEY (`response`) REFERENCES `response` (`id`), + ADD CONSTRAINT `categorize_ibfk_1` FOREIGN KEY (`keyword`) REFERENCES `keyword` (`word`); + +-- +-- Contraintes pour la table `propose` +-- +ALTER TABLE `propose` + ADD CONSTRAINT `Propose_ibfk_1` FOREIGN KEY (`possibleResponse`) REFERENCES `possibleresponse` (`id`), + ADD CONSTRAINT `Propose_ibfk_2` FOREIGN KEY (`question`) REFERENCES `question` (`id`); + +-- +-- Contraintes pour la table `question` +-- +ALTER TABLE `question` + ADD CONSTRAINT `Question_ibfk_1` FOREIGN KEY (`form`) REFERENCES `form` (`id`); + +-- +-- Contraintes pour la table `reference` +-- +ALTER TABLE `reference` + ADD CONSTRAINT `reference_ibfk_1` FOREIGN KEY (`possibleResponse`) REFERENCES `possibleresponse` (`id`); + +-- +-- Contraintes pour la table `submit` +-- +ALTER TABLE `submit` + ADD CONSTRAINT `Submit_ibfk_1` FOREIGN KEY (`response`) REFERENCES `response` (`id`), + ADD CONSTRAINT `Submit_ibfk_2` FOREIGN KEY (`responsesCandidate`) REFERENCES `listresponsesofcandidate` (`id`); +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +'; + $this->connection->executeQuery($queryScript); + $queryScript = "INSERT INTO `form` (`id`, `title`, `description`) VALUES (1, 'Votre avis nous intéresse !', 'Ce formulaire vous permet de candidater à une potentielle interview si votre profil nous intéresse.')"; + $this->connection->executeQuery($queryScript); + /* $query = "SELECT * FROM `form`"; $this->connection->executeQuery($query); return $this->connection->getResults(); + */ + return []; } /** diff --git a/Source/API/script/Gateway/GatewayQuestion.php b/Source/API/script/Gateway/GatewayQuestion.php index 0c6a1d9..fa18699 100644 --- a/Source/API/script/Gateway/GatewayQuestion.php +++ b/Source/API/script/Gateway/GatewayQuestion.php @@ -74,29 +74,26 @@ class GatewayQuestion * * @param string $questionClass * @param int $idQuestion Id de la question à supprimer - * @param array $questionGetPossibleResponse * @return void */ - public function deleteQuestion(string $questionClass, int $idQuestion, array $questionGetPossibleResponse): void + public function deleteQuestion(string $questionClass, int $idQuestion): void { if($questionClass == "BoxQuestionAPI") { - $query = "DELETE FROM `propose` WHERE question = :id"; + $query = "DELETE FROM Propose WHERE question = :id"; $this->connection->executeQuery($query, array( ':id' => array($idQuestion, PDO::PARAM_INT) )); - - $listPossibleResponse = $questionGetPossibleResponse; - for ($i = 0; $i < count($listPossibleResponse); $i++){ - $query = "DELETE FROM `reference` WHERE response = :id"; - $this->connection->executeQuery($query, array( - ':id' => array($listPossibleResponse[$i]->getId(), PDO::PARAM_INT) - )); - - $query = "DELETE FROM `possibleresponse` WHERE id = :id"; - $this->connection->executeQuery($query, array( - ':id' => array($listPossibleResponse[$i]->getId(), PDO::PARAM_INT) - )); + $gatewayPossibleResponse = new GatewayPossibleResponse(); + $listPossibleResponse = $gatewayPossibleResponse->getPossibleResponseByQuestion($idQuestion); + foreach ($listPossibleResponse as $row) { + $gatewayPossibleResponse->deletePossibleResponse($row["id"]); } + + $query = "DELETE FROM Question WHERE id = :id"; + $this->connection->executeQuery($query, array( + ':id' => array($idQuestion, PDO::PARAM_INT) + )); + } $query = "DELETE FROM `question` WHERE id = :id"; diff --git a/Source/API/script/index.php b/Source/API/script/index.php index be783fc..ea7c770 100644 --- a/Source/API/script/index.php +++ b/Source/API/script/index.php @@ -60,7 +60,7 @@ $app->post('/insertForm', function(Request $request, Response $response){ throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->delete('/deleteForm', function(Request $request, Response $response){ @@ -74,7 +74,7 @@ $app->delete('/deleteForm', function(Request $request, Response $response){ throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->get('/existsForm', function(Request $request, Response $response){ @@ -101,7 +101,7 @@ $app->post('/assignKeywordToQuestion', function(Request $request, Response $resp throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->delete('/deleteKeywordFromQuestion', function(Request $request, Response $response){ @@ -115,7 +115,7 @@ $app->delete('/deleteKeywordFromQuestion', function(Request $request, Response $ throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->put('/updateTitleToForm', function(Request $request, Response $response){ @@ -129,7 +129,7 @@ $app->put('/updateTitleToForm', function(Request $request, Response $response){ throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->put('/updateDescriptionToForm', function(Request $request, Response $response){ @@ -143,7 +143,7 @@ $app->put('/updateDescriptionToForm', function(Request $request, Response $respo throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->delete('/deleteDescriptionToForm', function(Request $request, Response $response){ @@ -157,7 +157,7 @@ $app->delete('/deleteDescriptionToForm', function(Request $request, Response $re throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->post('/insertKeyword', function(Request $request, Response $response){ @@ -171,7 +171,7 @@ $app->post('/insertKeyword', function(Request $request, Response $response){ throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->delete('/deleteKeyword', function(Request $request, Response $response){ @@ -185,7 +185,7 @@ $app->delete('/deleteKeyword', function(Request $request, Response $response){ throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->get('getAllKeyword', function(Request $request, Response $response){ @@ -244,7 +244,7 @@ $app->delete('/deleteListResponseOfCandidate', function(Request $request, Respon throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->post('/insertListResponseOfCandidate', function(Request $request, Response $response){ @@ -258,7 +258,7 @@ $app->post('/insertListResponseOfCandidate', function(Request $request, Response throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->get('/getPossibleResponseByQuestion', function(Request $request, Response $response){ @@ -324,7 +324,7 @@ $app->delete('/deleteResponseById', function(Request $request, Response $respons throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->post('/insertResponse', function(Request $request, Response $response){ @@ -355,16 +355,16 @@ $app->post('/addQuestion', function(Request $request, Response $response){ $app->delete('/deleteQuestion', function(Request $request, Response $response){ $parameters = $request->getQueryParams(); - if (empty($parameters['classQuestion']) || empty($parameters['id']) || empty($parameters['listPossibleResponse'])){ + if (empty($parameters['classQuestion']) || empty($parameters['id'])){ throw new TypeErrorParameters($request); } try{ - (new GatewayQuestion)->deleteQuestion($parameters['classQuestion'],$parameters['id'], json_decode($parameters['listPossibleResponse'])); + (new GatewayQuestion)->deleteQuestion($parameters['classQuestion'],$parameters['id']); }catch (PDOException $e){ throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->put('/updateQuestion', function(Request $request, Response $response){ @@ -378,7 +378,7 @@ $app->put('/updateQuestion', function(Request $request, Response $response){ throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->get('/getAllQuestions', function(Request $request, Response $response){ @@ -444,7 +444,7 @@ $app->delete('/deletePossibleResponse', function(Request $request, Response $res throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->post('/insertResponseInQuestion', function(Request $request, Response $response){ @@ -458,7 +458,7 @@ $app->post('/insertResponseInQuestion', function(Request $request, Response $res throw new PDOError($request,$e->getMessage(),$e); } $response->getBody()->write("OK"); - return $response; + return $response->withStatus(200); }); $app->get('/getCategorizeOfResponsesIdByIdListCandidate', function(Request $request, Response $response){