diff --git a/Documentation/team.puml b/Documentation/team.puml new file mode 100644 index 0000000..f775665 --- /dev/null +++ b/Documentation/team.puml @@ -0,0 +1,3 @@ +@startuml +/*todo*/ +@enduml \ No newline at end of file diff --git a/public/index.php b/public/index.php index 4c5290b..88d90fa 100644 --- a/public/index.php +++ b/public/index.php @@ -40,6 +40,9 @@ $router->map("POST", "/submit", fn() => $sampleFormController->submitForm($_POST $router->map("GET", "/twig", fn() => $sampleFormController->displayFormTwig()); $router->map("POST", "/submit-twig", fn() => $sampleFormController->submitFormTwig($_POST)); +$teamController = new \App\Controller\TeamController(new \App\Model\TeamModel(),$twig); +$router->map("GET","/team/new", fn()=>$teamController->submitTeam($_POST)); + $match = $router->match(); if ($match == null) { diff --git a/sql/setup-tables.sql b/sql/setup-tables.sql index 0c6fbe7..70723dc 100644 --- a/sql/setup-tables.sql +++ b/sql/setup-tables.sql @@ -1,8 +1,14 @@ - -- drop tables here DROP TABLE IF EXISTS FormEntries; CREATE TABLE FormEntries(name varchar, description varchar); +CREATE TABLE Team( + id numeric PRIMARY KEY AUTOINCREMENT, + name varchar, + picture varchar, + mainColor varchar, + secondColor varchar +); diff --git a/src/Controller/FrontController.php b/src/Controller/FrontController.php new file mode 100644 index 0000000..c1a39bc --- /dev/null +++ b/src/Controller/FrontController.php @@ -0,0 +1,8 @@ +model = $model; + $this->twig = $twig; + } + + public function submitTeam(array $request){ + if(isset($request['name']) && isset($request["picture"]) && isset($request["mainColor"]) && isset($request["secondColor"])){ + $result= $this->$model->; + } + else{ + http_response_code(400); + echo "Champ(s) manquant(s)"; + } + } + +} + + diff --git a/src/Data/Color.php b/src/Data/Color.php index f841731..bc9043b 100755 --- a/src/Data/Color.php +++ b/src/Data/Color.php @@ -14,10 +14,7 @@ class Color { * @param int $value 6 bytes unsigned int that represents an RGB color * @throws \InvalidArgumentException if the value is negative or greater than 0xFFFFFF */ - public function __constructor(int $value) { - if ($value < 0 || $value > 0xFFFFFF) { - throw new InvalidArgumentException("int color value is invalid, must be positive and lower than 0xFFFFFF"); - } + private function __constructor(int $value) { $this->value = $value; } @@ -27,4 +24,20 @@ class Color { public function getValue(): int { return $this->value; } + + public static function from(int $value): Color { + $color = self::tryFrom($value); + if ($color == null) { + throw new InvalidArgumentException("int color value is invalid, must be positive and lower than 0xFFFFFF"); + } + return $color; + } + + public static function tryFrom(int $value): ?Color { + if ($value < 0 || $value > 0xFFFFFF) { + return null; + } + return new Color($value); + } + } \ No newline at end of file diff --git a/src/Gateway/TeamGateway.php b/src/Gateway/TeamGateway.php new file mode 100644 index 0000000..2bd5faa --- /dev/null +++ b/src/Gateway/TeamGateway.php @@ -0,0 +1,23 @@ +con = $con; + } + + function insert(string $name, string $picture, string $mainColor, string $secondColor) { + $this->con->exec( /* todo */ + "INSERT INTO Team VALUES (:name, :picture)", + [ + ":name" => [$username, PDO::PARAM_STR], + "description" => [$description, PDO::PARAM_STR] + ] + ); + } +} \ No newline at end of file diff --git a/src/Model/TeamModel.php b/src/Model/TeamModel.php new file mode 100644 index 0000000..b1d4e67 --- /dev/null +++ b/src/Model/TeamModel.php @@ -0,0 +1,24 @@ +gateway = $gateway; + } + + + public function createTeam(string $name, Color $mainColor, Color $secondColor ){ + + } +} \ No newline at end of file