new branch starting the team part in the MVC, plus a little change about the type Color

pull/16/head
Maël DAIM 1 year ago committed by mael.daim
parent 947cda494a
commit f9eb6fbb6d

@ -0,0 +1,3 @@
@startuml
/*todo*/
@enduml

@ -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) {

@ -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
);

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

@ -0,0 +1,33 @@
<?php
namespace App\Controller;
use App\Model\TeamModel;
class TeamController /* verif si les camp sont assignés, sinon erreur 400*/
{
private TeamModel $model;
private Environment $twig;
/**
* @param TeamModel $model
* @param Environment $twig
*/
public function __construct(TeamModel $model, Environment $twig)
{
$this->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)";
}
}
}

@ -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);
}
}

@ -0,0 +1,23 @@
<?php
namespace App\Gateway;
use App\Connexion;
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 */
{
private Connexion $con;
public function __construct(Connexion $con) {
$this->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]
]
);
}
}

@ -0,0 +1,24 @@
<?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, */
{
private TeamGateway $gateway;
/**
* @param TeamGateway $gateway
*/
public function __construct(TeamGateway $gateway)
{
$this->gateway = $gateway;
}
public function createTeam(string $name, Color $mainColor, Color $secondColor ){
}
}
Loading…
Cancel
Save