every bugs has been fixed
continuous-integration/drone/push Build is passing Details

pull/16/head
Maël DAIM 1 year ago
parent 46862bb7cd
commit d824f17ea7

2
.gitignore vendored

@ -4,7 +4,7 @@
.vite .vite
vendor vendor
.nfs*
composer.lock composer.lock
*.phar *.phar
/dist /dist

@ -2,8 +2,8 @@
DROP TABLE IF EXISTS FormEntries; DROP TABLE IF EXISTS FormEntries;
DROP TABLE IF EXISTS TacticInfo; DROP TABLE IF EXISTS TacticInfo;
DROP TABLE IF EXISTS Team; DROP TABLE IF EXISTS Team;
DROP TABLE IF EXISTS User;
DROP TABLE IF EXISTS Member; DROP TABLE IF EXISTS Member;
DROP TABLE IF EXISTS Participate;
CREATE TABLE FormEntries(name varchar, description varchar); CREATE TABLE FormEntries(name varchar, description varchar);
@ -11,20 +11,20 @@ CREATE TABLE Team(
id integer PRIMARY KEY AUTOINCREMENT, id integer PRIMARY KEY AUTOINCREMENT,
name varchar, name varchar,
picture varchar, picture varchar,
mainColor numeric, mainColor varchar,
secondColor numeric secondColor varchar
); );
CREATE TABLE Member( CREATE TABLE User(
id integer PRIMARY KEY AUTOINCREMENT id integer PRIMARY KEY AUTOINCREMENT
); );
CREATE TABLE Participate( CREATE TABLE Member(
idTeam integer, idTeam integer,
idMember integer, idMember integer,
role char(1) CHECK (role IN ('C','P')), role char(1) CHECK (role IN ('C','P')),
FOREIGN KEY (idTeam) REFERENCES Team(id), FOREIGN KEY (idTeam) REFERENCES Team(id),
FOREIGN KEY (idMember) REFERENCES Member(id) FOREIGN KEY (idMember) REFERENCES User(id)
); );
CREATE TABLE TacticInfo( CREATE TABLE TacticInfo(

@ -31,13 +31,11 @@ class TeamController /* verif si les camp sont assignés, sinon erreur 400*/
public function submitTeam(array $request): HttpResponse { public function submitTeam(array $request): HttpResponse {
$errors = []; $errors = [];
$request['mainColor'] = hexdec($request['mainColor']);
$request['secondColor'] = hexdec($request['secondColor']);
$request = HttpRequest::from($request, $errors, [ $request = HttpRequest::from($request, $errors, [
"name" => [Validators::lenBetween(1, 32), Validators::nameWithSpaces()], "name" => [Validators::lenBetween(1, 32), Validators::nameWithSpaces()],
"mainColor" => [Validators::isInteger(), Validators::isIntInRange(0, 0xffffff)], "mainColor" => [Validators::regex('/#(?:[0-9a-fA-F]{6})/')],
"secondColor" => [Validators::isInteger(), Validators::isIntInRange(0, 0xffffff)], "secondColor" => [Validators::regex('/#(?:[0-9a-fA-F]{6})/')],
"picture" => [Validators::isURL()] "picture" => [Validators::isURL()]
]); ]);
if (!empty($errors)) { if (!empty($errors)) {

@ -2,39 +2,39 @@
namespace App\Data; namespace App\Data;
use http\Exception\InvalidArgumentException; use \InvalidArgumentException;
class Color { class Color {
/** /**
* @var int 6 bytes unsigned int that represents an RGB color * @var string 6 bytes unsigned int that represents an RGB color
*/ */
private int $value; private string $hex;
/** /**
* @param int $value 6 bytes unsigned int that represents an RGB color * @param string $value 6 bytes unsigned int that represents an RGB color
* @throws \InvalidArgumentException if the value is negative or greater than 0xFFFFFF * @throws \InvalidArgumentException if the value is negative or greater than 0xFFFFFF
*/ */
private function __constructor(int $value) { private function __construct(string $value) {
$this->value = $value; $this->value = $value;
} }
/** /**
* @return int * @return string
*/ */
public function getValue(): int { public function getValue(): string {
return $this->value; return $this->value;
} }
public static function from(int $value): Color { public static function from(string $value): Color {
$color = self::tryFrom($value); $color = self::tryFrom($value);
if ($color == null) { if ($color == null) {
throw new InvalidArgumentException("int color value is invalid, must be positive and lower than 0xFFFFFF"); throw new InvalidArgumentException("The string is not an hexadecimal code");
} }
return $color; return $color;
} }
public static function tryFrom(int $value): ?Color { public static function tryFrom(string $value): ?Color {
if ($value < 0 || $value > 0xFFFFFF) { if (!preg_match('/#(?:[0-9a-fA-F]{6})/',$value)) {
return null; return null;
} }
return new Color($value); return new Color($value);

@ -2,12 +2,10 @@
namespace App\Data; namespace App\Data;
use http\Url;
class Team { class Team {
private int $id; private int $id;
private string $name; private string $name;
private Url $picture; private string $picture;
private Color $mainColor; private Color $mainColor;
private Color $secondColor; private Color $secondColor;
@ -18,12 +16,12 @@ class Team {
/** /**
* @param string $name * @param string $name
* @param Url $picture * @param string $picture
* @param Color $mainColor * @param Color $mainColor
* @param Color $secondColor * @param Color $secondColor
* @param array $members * @param array $members
*/ */
public function __construct(int $id,string $name, Url $picture, Color $mainColor, Color $secondColor, array $members =[]) { public function __construct(int $id,string $name, string $picture, Color $mainColor, Color $secondColor, array $members =[]) {
$this->id = $id; $this->id = $id;
$this->name = $name; $this->name = $name;
$this->picture = $picture; $this->picture = $picture;
@ -47,9 +45,9 @@ class Team {
} }
/** /**
* @return Url * @return string
*/ */
public function getPicture(): Url { public function getPicture(): string {
return $this->picture; return $this->picture;
} }

@ -12,14 +12,14 @@ class TeamGateway {
$this->con = $con; $this->con = $con;
} }
public function insert(string $name, string $picture, int $mainColor, int $secondColor) { public function insert(string $name, string $picture, string $mainColor, string $secondColor) {
$this->con->exec( $this->con->exec(
"INSERT INTO Team(name, picture, mainColor, secondColor) VALUES (:teamName , :picture, :mainColor, :secondColor)", "INSERT INTO Team(name, picture, mainColor, secondColor) VALUES (:teamName , :picture, :mainColor, :secondColor)",
[ [
":teamName" => [$name, PDO::PARAM_STR], ":teamName" => [$name, PDO::PARAM_STR],
":picture" => [$picture, PDO::PARAM_STR], ":picture" => [$picture, PDO::PARAM_STR],
":mainColor" => [$mainColor, PDO::PARAM_INT], ":mainColor" => [$mainColor, PDO::PARAM_STR],
":secondColor" => [$secondColor, PDO::PARAM_INT] ":secondColor" => [$secondColor, PDO::PARAM_STR]
] ]
); );
} }
@ -35,7 +35,7 @@ class TeamGateway {
public function getTeamById(int $id): array{ public function getTeamById(int $id): array{
return $this->con->fetch( return $this->con->fetch(
"SELECT name,picture,mainColor,secondColor FROM Team WHERE id = :id", "SELECT id,name,picture,mainColor,secondColor FROM Team WHERE id = :id",
[ [
":id" => [$id, PDO::PARAM_INT] ":id" => [$id, PDO::PARAM_INT]
] ]
@ -53,7 +53,7 @@ class TeamGateway {
public function getMembersById($id):array{ public function getMembersById($id):array{
return $this->con->fetch( return $this->con->fetch(
"SELECT p.role,m.email,m.id FROM Member m,Team t,Participate p WHERE t.id = :id AND p.idTeam = t.id AND p.idMember = m.id", "SELECT m.role,u.id FROM User u,Team t,Member m WHERE t.id = :id AND m.idTeam = t.id AND m.idMember = u.id",
[ [
":id" => [$id, PDO::PARAM_INT] ":id" => [$id, PDO::PARAM_INT]
] ]

@ -6,12 +6,9 @@ use App\Gateway\TeamGateway;
use App\Data\Team; use App\Data\Team;
use App\Data\Member; use App\Data\Member;
use App\Data\MemberRole; use App\Data\MemberRole;
use http\Url; use App\Data\Color;
/** class TeamModel
*
*/
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; private TeamGateway $gateway;
@ -22,7 +19,7 @@ class TeamModel /* throw des exceptions(ex validation des champs, filtre etc) po
$this->gateway = $gateway; $this->gateway = $gateway;
} }
public function createTeam(string $name, string $picture, int $mainColor, int $secondColor): int{ public function createTeam(string $name, string $picture, string $mainColor, string $secondColor): int {
$this->gateway->insert($name, $picture, $mainColor, $secondColor); $this->gateway->insert($name, $picture, $mainColor, $secondColor);
$result = $this->gateway->getIdTeamByName($name); $result = $this->gateway->getIdTeamByName($name);
return intval($result[0]['id']); return intval($result[0]['id']);
@ -32,15 +29,14 @@ class TeamModel /* throw des exceptions(ex validation des champs, filtre etc) po
$teams = []; $teams = [];
$results = $this->gateway->listByName($name); $results = $this->gateway->listByName($name);
foreach ($results as $row) { foreach ($results as $row) {
$url = new Url($row['picture']); $teams[] = new Team($row['id'], $row['name'], $row['picture'], Color::from($row['mainColor']), Color::from($row['secondColor']));
$teams[] = new Team($row['id'], $row['name'], $url, $row['mainColor'], $row['secondColor']);
} }
return $teams; return $teams;
} }
public function displayTeam(int $id): Team { public function displayTeam(int $id): Team {
$members = []; $members = [];
$result = $this->gateway->getTeamById($id); $result = $this->gateway->getTeamById($id)[0];
$resultMembers = $this->gateway->getMembersById($id); $resultMembers = $this->gateway->getMembersById($id);
foreach ($resultMembers as $row) { foreach ($resultMembers as $row) {
if ($row['role'] == 'C') { if ($row['role'] == 'C') {
@ -50,7 +46,6 @@ class TeamModel /* throw des exceptions(ex validation des champs, filtre etc) po
} }
$members[] = new Member($row['id'], $role); $members[] = new Member($row['id'], $role);
} }
return new Team($result['id'], $result['name'], $result['picture'], $result['mainColor'], $result['secondColor'], $members); return new Team(intval($result['id']), $result['name'], $result['picture'], Color::from($result['mainColor']), Color::from($result['secondColor']), $members);
} }
} }

@ -69,5 +69,4 @@ class Validators {
fn(string $name) => [new FieldValidationFail($name, "The value is not an URL")] fn(string $name) => [new FieldValidationFail($name, "The value is not an URL")]
); );
} }
} }

@ -3,14 +3,29 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Twig view</title> <title>Twig view</title>
<style>
.square{
width:50px;
height:50px;
}
#mainColor{
background-color: {{ team.mainColor.getValue() }};
}
#secondColor{
background-color: {{ team.secondColor.getValue() }};
}
</style>
</head> </head>
<body> <body>
<h1>{{ team.name }}</h1> <h1>{{ team.name }}</h1>
<img src="{{ team.picture }}" alt="Logo d'équipe">
<div class="square" id="mainColor"></div>
<div class="square" id="secondColor"></div>
{% for m in team.members %} {% for m in team.members %}
<p> m.email </p> <p> m.id </p>
{% endfor %} {% endfor %}
</body> </body>

@ -24,7 +24,7 @@
{% for t in teams %} {% for t in teams %}
<div class="team" onclick="window.location.href = '/team/{{ t.id }}'"> <div class="team" onclick="window.location.href = '/team/{{ t.id }}'">
<p>Nom de l'équipe : {{ t.name }}</p> <p>Nom de l'équipe : {{ t.name }}</p>
<p>picture : {{ t.picture }}</p> <img src="{{ t.picture }}" alt="logo de l'équipe">
</div> </div>
{% endfor %} {% endfor %}
{% endif %} {% endif %}

Loading…
Cancel
Save