diff --git a/src/Controller/FrontController.php b/src/Controller/FrontController.php deleted file mode 100644 index c1a39bc..0000000 --- a/src/Controller/FrontController.php +++ /dev/null @@ -1,8 +0,0 @@ -$model->; + $errors = $this->model->createTeam($request['name'],$request['picture'],$request['mainColor'],$request["secondColor"]); + /*todo gestion des erreurs grace au tableau*/ } else{ http_response_code(400); - echo "Champ(s) manquant(s)"; + /*todo rappeler vue avec parametre pour signaler les pb */ } } diff --git a/src/Gateway/TeamGateway.php b/src/Gateway/TeamGateway.php index 2bd5faa..56992d8 100644 --- a/src/Gateway/TeamGateway.php +++ b/src/Gateway/TeamGateway.php @@ -1,7 +1,10 @@ con = $con; } - function insert(string $name, string $picture, string $mainColor, string $secondColor) { - $this->con->exec( /* todo */ - "INSERT INTO Team VALUES (:name, :picture)", + public function insert(string $name, string $picture, Color $mainColor, Color $secondColor) { + $this->con->exec( + "INSERT INTO Team VALUES (:name, :picture, :mainColor, :secondColor)", [ - ":name" => [$username, PDO::PARAM_STR], - "description" => [$description, PDO::PARAM_STR] + ":name" => [$name, PDO::PARAM_STR], + ":picture" => [$picture, PDO::PARAM_STR], + ":mainColor" => [$mainColor, PDO::PARAM_STR], + ":secondColor" => [$secondColor, PDO::PARAM_STR] ] ); } + + public function listByName($name): array { + /*todo*/ + } + } \ No newline at end of file diff --git a/src/Model/TeamModel.php b/src/Model/TeamModel.php index b1d4e67..3158423 100644 --- a/src/Model/TeamModel.php +++ b/src/Model/TeamModel.php @@ -1,12 +1,22 @@ gateway = $gateway; } + public function createTeam(string $name,string $picture,int $mainColorValue, int $secondColorValue, array $errors) { - public function createTeam(string $name, Color $mainColor, Color $secondColor ){ + $mainColor = Color::tryFrom($mainColorValue); + $secondColor = Color::tryFrom($secondColorValue); + if( $mainColor == null || $secondColor == null ){ + $errors[] = self::ERROR_INVALID_COLOR; + } + + if(Validation::hasHTMLInjection($name)){ + $errors[] = self::ERROR_INVALID_NAME; + } + + if(filter_var($picture,FILTER_VALIDATE_URL)){ + $errors[] = self::ERROR_INVALID_PICTURE; + } + + if(empty($errors)){ + $this->gateway->insert($name,$picture,$mainColor,$secondColor); + } + + } + public function list(string $search,array $errors):array { + if(Validation::hasHTMLInjection($search)){ + $errors = self::ERROR_INVALID_SEARCH; + } } } \ No newline at end of file diff --git a/src/Model/Validation.php b/src/Model/Validation.php new file mode 100644 index 0000000..ac732d0 --- /dev/null +++ b/src/Model/Validation.php @@ -0,0 +1,10 @@ +]"); + } +} \ No newline at end of file