diff --git a/build/api/module/ProfessorController.php b/build/api/module/ProfessorController.php index 1218352..b8b78e6 100644 --- a/build/api/module/ProfessorController.php +++ b/build/api/module/ProfessorController.php @@ -11,6 +11,8 @@ namespace api\module; use database\core\Repo; use database\repo\professor; +use error\core\Error; +use error\core\Err; class ProfessorController{ @@ -27,6 +29,7 @@ class ProfessorController{ extract($args); /* Get the professor repo */ + /** @var professor $prof_repo */ $prof_repo = Repo::getRepo('professor'); @@ -49,7 +52,58 @@ class ProfessorController{ /* (2) Else -> getAll() ---------------------------------------------------------*/ - return ['professors' => $prof_repo->getAll($prof_id)]; + return ['professors' => $prof_repo->getAll()]; + + } + + + /* (2) Creates a new professor + * + * @lastName The professor's lastName + * @firstName The professor's firstName + * @category The professor's category ID + * @hoursToDo The professor's number of hours to do + * @initials The professor's initials + * @isAdmin Whether the professor is an admin + * @casLogin The professor's CAS username + * + * @return prof_id The created professor UID (if no error) + * + ---------------------------------------------------------*/ + public static function post($args){ + $lastName = ""; + $firstName = ""; + $category = 0; + $hoursToDo = 0; + $initials = ""; + $isAdmin = false; + $casLogin = ""; + extract($args); + + /* Get the professor repo */ + /** @var professor $prof_repo */ + $prof_repo = Repo::getRepo('professor'); + + + /* (1) Dispatch to the repo */ + $repo_rtn = $prof_repo->create( + $lastName, + $firstName, + $category, + $hoursToDo, + $initials, + $isAdmin, + $casLogin + ); + + + /* (2) If repo error -> return it */ + if( is_null($repo_rtn) ) + return ['error' => new Error(Err::RepoError)]; + + /* (3) Else return UID */ + return ['created_uid' => $repo_rtn]; + } } \ No newline at end of file diff --git a/build/database/repo/professor.php b/build/database/repo/professor.php index c4c4d9d..7270d93 100644 --- a/build/database/repo/professor.php +++ b/build/database/repo/professor.php @@ -170,7 +170,7 @@ class professor extends Repo_i { * @return teacher The professor's data (NULL on error / not found) * ---------------------------------------------------------*/ - public function get(int $id) : ?array{ + public function getById(int $id) : ?array{ /* (1) Prepare Statement */ $st = $this->pdo->prepare("SELECT * FROM `Professeur` WHERE `idProfesseur` = :id"); diff --git a/config/modules.json b/config/modules.json index cdd4fc0..71a4750 100644 --- a/config/modules.json +++ b/config/modules.json @@ -31,6 +31,36 @@ }, "Professor":{ + + "POST": { + "des": "Creates a new professor", + "per": [], + "par": { + "firstName": { "des": "Professor last name.", "typ": "varchar(2,30,alphanumeric)" }, + "lastName": { "des": "Professor first name.", "typ": "varchar(2,30,alphanumeric)" }, + "category": { "des": "Professor category UID.", "typ": "id" }, + "hoursToDo": { "des": "Number of hours professor have to do", "typ": "id" }, + "initials": { "des": "Professor initials", "typ": "varchar(2,2,letters)" }, + "isAdmin": { "des": "Whether professor is an admin", "typ": "boolean" }, + "casLogin": { "des": "Optional CAS username", "typ": "varchar(6,10,letters)", "opt": true } + }, + "out": { + "created_uid": { "des": "Created professor UID", "typ": "id" } + } + }, + + "GET": { + "des": "Get one or all professors", + "per": [], + "par": { + "URL0": { "des": "Optional professor UID.", "typ": "id", "ren": "prof_id", "opt": true } + }, + "out": { + "professors": { "des": "Teacher list", "typ": "array" } + } + }, + + "Stats": { "GET":{ "des": "Get statistics of the professor", @@ -40,6 +70,8 @@ } } } + + }, "Formation": {