made progression on the create team almost done
continuous-integration/drone/push Build is passing Details

pull/16/head
Maël DAIM 1 year ago
parent f9eb6fbb6d
commit c8df556699

@ -1,8 +0,0 @@
<?php
namespace App\Controller;
class FrontController
{
/* todo */
}

@ -19,12 +19,14 @@ class TeamController /* verif si les camp sont assignés, sinon erreur 400*/
}
public function submitTeam(array $request){
$errors = [];
if(isset($request['name']) && isset($request["picture"]) && isset($request["mainColor"]) && isset($request["secondColor"])){
$result= $this->$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 */
}
}

@ -1,7 +1,10 @@
<?php
namespace App\Gateway;
use App\Connexion;
use App\Data\Color;
use PDO;
class TeamGateway /* retourne exception par rapport à la validité du paramètre par ex. un int qui ne peut pas etre <0 doit etre verif etsoulever une exception */
{
@ -11,13 +14,20 @@ class TeamGateway /* retourne exception par rapport à la validité du paramètr
$this->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*/
}
}

@ -1,12 +1,22 @@
<?php
namespace App\Model;
use App\Data\Color;
use App\Gateway\TeamGateway;
/**
*
*/
class TeamModel /* throw des exceptions(ex validation des champs, filtre etc) pour le controller qui l'utilise, catch celle de la gw, */
{
/**
* Attributes used to
*/
public const ERROR_INVALID_COLOR = 0;
public const ERROR_INVALID_NAME = 1;
public const ERROR_INVALID_PICTURE = 2;
public const ERROR_INVALID_SEARCH = 3;
private TeamGateway $gateway;
/**
@ -17,8 +27,31 @@ class TeamModel /* throw des exceptions(ex validation des champs, filtre etc) po
$this->gateway = $gateway;
}
public function createTeam(string $name,string $picture,int $mainColorValue, int $secondColorValue, array $errors) {
$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;
}
public function createTeam(string $name, Color $mainColor, Color $secondColor ){
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;
}
}
}

@ -0,0 +1,10 @@
<?php
namespace App\Model;
class Validation
{
public static function hasHTMLInjection(string $s): bool{
return filter_var($s,FILTER_VALIDATE_REGEXP,"[<>]");
}
}
Loading…
Cancel
Save