[module.professor] fixed GET + implemented POST
This commit is contained in:
parent
3d56d90b47
commit
720be931c0
|
@ -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<String> The professor's lastName
|
||||
* @firstName<String> The professor's firstName
|
||||
* @category<int> The professor's category ID
|
||||
* @hoursToDo<int> The professor's number of hours to do
|
||||
* @initials<int> The professor's initials
|
||||
* @isAdmin<bool> Whether the professor is an admin
|
||||
* @casLogin<String> The professor's CAS username
|
||||
*
|
||||
* @return prof_id<int> 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];
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -170,7 +170,7 @@ class professor extends Repo_i {
|
|||
* @return teacher<array> 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");
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Reference in New Issue