diff --git a/build/api/module/formationController.php b/build/api/module/formationController.php index bf08f1f..928f593 100644 --- a/build/api/module/formationController.php +++ b/build/api/module/formationController.php @@ -14,7 +14,7 @@ use database\core\Repo; class formationController { - public static function get($args){ + public function get($args){ $form_id = null; extract($args); @@ -24,4 +24,37 @@ class formationController return ['formations' => $repo->get($form_id)]; } + public function post($args){ + $label = null; + $isInternal = null; + extract($args); + + /** @var \database\repo\formation $repo */ + $repo = Repo::getRepo("formation"); + + return ['idFormation' => $repo->create($label,$isInternal)]; + } + + public function put($args){ + $idFormation = null; + $label = null; + $isInternal = null; + extract($args); + + /** @var \database\repo\formation $repo */ + $repo = Repo::getRepo("formation"); + + return ['success' => $repo->update($idFormation,$label,$isInternal)]; + } + + public function delete($args){ + $idFormation = null; + extract($args); + + /** @var \database\repo\formation $repo */ + $repo = Repo::getRepo("formation"); + + return ['success' => $repo->delete($idFormation)]; + } + } \ No newline at end of file diff --git a/build/database/repo/formation.php b/build/database/repo/formation.php index 875fda1..65e26ed 100644 --- a/build/database/repo/formation.php +++ b/build/database/repo/formation.php @@ -42,6 +42,26 @@ class formation extends Repo_i { } + public function update(int $idFormation, ?String $label, ?bool $isInternal) : bool{ + $req = ""; + $execute = []; + + if($label != null){ + $req .= "labelFormation=:label,"; + $execute["label"] = $label; + } + if($isInternal != null){ + $req .= "isInternal=:isInternal,"; + $execute["isInternal"] = $isInternal?1:0; + } + $req = rtrim($req,","); + $execute["idFormation"] = $idFormation; + + $st = $this->pdo->prepare("UPDATE `Formation` SET $req WHERE idFormation=:idFormation"); + + return $st->execute($execute); + } + /* (2) Check if a formation exists (by its label) diff --git a/config/modules.json b/config/modules.json index 2538077..108e9b3 100644 --- a/config/modules.json +++ b/config/modules.json @@ -495,6 +495,33 @@ "par": { "URL0":{"des" : "Id of the formation", "typ": "id", "ren": "form_id", "opt" : true } } + }, + + "POST":{ + "des": "Create a new formation", + "per": [["cas_admin"]], + "par": { + "label":{"des" : "name of the formation", "typ": "text" }, + "isInternal":{"des" : "is this formation internal to the department", "typ": "bool" } + } + }, + + "PUT":{ + "des": "Update a formation", + "per": [["cas_admin"]], + "par": { + "URL0": { "des": "Id of the formation", "typ": "id", "ren": "idFormation" }, + "label":{"des" : "name of the formation", "typ": "text", "opt":true }, + "isInternal":{"des" : "is this formation internal to the department", "typ": "bool", "opt":true } + } + }, + + "DELETE":{ + "des": "Delete a formation", + "per": [["cas_admin"]], + "par": { + "URL0": { "des": "Id of the formation", "typ": "id", "ren": "idFormation" } + } } },