From 685c3ffc9166fcce383c22b86be11e4c0fd2413a Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 1 Mar 2018 18:01:45 +0100 Subject: [PATCH] [module.professor] fixed POST > optional 'casLogin' | check if already exists | type --- build/api/core/Checker.php | 2 +- build/api/module/ProfessorController.php | 15 +++++++++++---- build/error/core/Error.php | 11 ++++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/build/api/core/Checker.php b/build/api/core/Checker.php index 02d631b..108cb3e 100755 --- a/build/api/core/Checker.php +++ b/build/api/core/Checker.php @@ -124,7 +124,7 @@ // Boolean case 'boolean': - return $checker && is_bool($value); + return $checker && ( is_bool($value) || $value === 'false' || $value === 'true' ); break; // Objet non vide diff --git a/build/api/module/ProfessorController.php b/build/api/module/ProfessorController.php index b8b78e6..0be6192 100644 --- a/build/api/module/ProfessorController.php +++ b/build/api/module/ProfessorController.php @@ -84,8 +84,14 @@ class ProfessorController{ /** @var professor $prof_repo */ $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( $lastName, $firstName, @@ -93,15 +99,16 @@ class ProfessorController{ $hoursToDo, $initials, $isAdmin, - $casLogin + is_null($casLogin) ? "" : $casLogin ); - /* (2) If repo error -> return it */ + /* (4) If repo error -> return it */ if( is_null($repo_rtn) ) return ['error' => new Error(Err::RepoError)]; - /* (3) Else return UID */ + + /* (5) Else return UID */ return ['created_uid' => $repo_rtn]; } diff --git a/build/error/core/Error.php b/build/error/core/Error.php index 3aeb804..2ff7d0b 100755 --- a/build/error/core/Error.php +++ b/build/error/core/Error.php @@ -76,9 +76,10 @@ case Err::UncallableModule: return $this->UncallableModule(); break; case Err::UncallableMethod: return $this->UncallableMethod(); 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::WrongParam: return $this->WrongParam(); break; + case Err::WrongDefaultParam: return $this->WrongDefaultParam(); break; case Err::ModuleError: return $this->ModuleError(); break; case Err::PDOConnection: return $this->PDOConnection(); break; case Err::WrongPathRepo: return $this->WrongPathRepo(); break; @@ -160,6 +161,14 @@ return 'wrong param \''.$this->arguments[0].'\''; else 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(){ return 'module error'; }private function PDOConnection(){