[module.professor] fixed POST > optional 'casLogin' | check if already exists | type

This commit is contained in:
xdrm-brackets 2018-03-01 18:01:45 +01:00
parent d0fbaa6f04
commit 685c3ffc91
3 changed files with 22 additions and 6 deletions

View File

@ -124,7 +124,7 @@
// Boolean // Boolean
case 'boolean': case 'boolean':
return $checker && is_bool($value); return $checker && ( is_bool($value) || $value === 'false' || $value === 'true' );
break; break;
// Objet non vide // Objet non vide

View File

@ -84,8 +84,14 @@ class ProfessorController{
/** @var professor $prof_repo */ /** @var professor $prof_repo */
$prof_repo = Repo::getRepo('professor'); $prof_repo = Repo::getRepo('professor');
/* (1) Check if professor already exists */
$exists = $prof_repo->exists($lastName, $firstName);
/* (1) Dispatch to the repo */ /* (2) If found -> already exists */
if( !is_null($exists) )
return ['error' => new Error(Err::AlreadyExists)];
/* (3) Else try to create */
$repo_rtn = $prof_repo->create( $repo_rtn = $prof_repo->create(
$lastName, $lastName,
$firstName, $firstName,
@ -93,15 +99,16 @@ class ProfessorController{
$hoursToDo, $hoursToDo,
$initials, $initials,
$isAdmin, $isAdmin,
$casLogin is_null($casLogin) ? "" : $casLogin
); );
/* (2) If repo error -> return it */ /* (4) If repo error -> return it */
if( is_null($repo_rtn) ) if( is_null($repo_rtn) )
return ['error' => new Error(Err::RepoError)]; return ['error' => new Error(Err::RepoError)];
/* (3) Else return UID */
/* (5) Else return UID */
return ['created_uid' => $repo_rtn]; return ['created_uid' => $repo_rtn];
} }

View File

@ -76,9 +76,10 @@
case Err::UncallableModule: return $this->UncallableModule(); break; case Err::UncallableModule: return $this->UncallableModule(); break;
case Err::UncallableMethod: return $this->UncallableMethod(); break; case Err::UncallableMethod: return $this->UncallableMethod(); break;
case Err::UnknownHttpMethod: return $this->UnknownHttpMethod(); break; case Err::UnknownHttpMethod: return $this->UnknownHttpMethod(); break;
case Err::ConfigError: return $this->ConfigError(); break; case Err::ConfigError: return $this->ConfigError(); break;
case Err::MissingParam: return $this->MissingParam(); break; case Err::MissingParam: return $this->MissingParam(); break;
case Err::WrongParam: return $this->WrongParam(); break; case Err::WrongParam: return $this->WrongParam(); break;
case Err::WrongDefaultParam: return $this->WrongDefaultParam(); break;
case Err::ModuleError: return $this->ModuleError(); break; case Err::ModuleError: return $this->ModuleError(); break;
case Err::PDOConnection: return $this->PDOConnection(); break; case Err::PDOConnection: return $this->PDOConnection(); break;
case Err::WrongPathRepo: return $this->WrongPathRepo(); break; case Err::WrongPathRepo: return $this->WrongPathRepo(); break;
@ -160,6 +161,14 @@
return 'wrong param \''.$this->arguments[0].'\''; return 'wrong param \''.$this->arguments[0].'\'';
else else
return 'wrong param'; return 'wrong param';
}private function WrongDefaultParam(){
if( count($this->arguments) > 0 )
if( count($this->arguments) > 1 )
return 'wrong default param \''.$this->arguments[0].'\' expected to be of type \''.$this->arguments[1].'\'';
else
return 'wrong default param \''.$this->arguments[0].'\'';
else
return 'wrong param';
}private function ModuleError(){ }private function ModuleError(){
return 'module error'; return 'module error';
}private function PDOConnection(){ }private function PDOConnection(){