diff --git a/Documentation/database_mcd.puml b/Documentation/database_mcd.puml index e698a69..710dfee 100644 --- a/Documentation/database_mcd.puml +++ b/Documentation/database_mcd.puml @@ -2,12 +2,10 @@ object Account { id - name - age email - phoneNumber - passwordHash - profilePicture + username + token + hash } object Team { @@ -26,7 +24,7 @@ object TacticFolder { object Tactic { id_json name - creationDate + creation_date } usecase have_team [ @@ -63,6 +61,10 @@ usecase contains_other_folder [ to contain ] +usecase owns [ + owns +] + Account "0,n" -- have_team have_team -- "1,n" Team @@ -73,6 +75,9 @@ shared_tactic_account -- "0,n" Tactic Tactic "0,n" -- shared_tactic_team shared_tactic_team -- "0,n" Team +Tactic "1,1" -- owns +owns -- Account + Team "0,n" -- shared_folder_team shared_folder_team -- "0,n"TacticFolder diff --git a/public/api/index.php b/public/api/index.php index 580f794..c5f8f2e 100644 --- a/public/api/index.php +++ b/public/api/index.php @@ -17,7 +17,6 @@ use App\Http\ViewHttpResponse; use App\Model\AuthModel; use App\Model\TacticModel; use App\Session\PhpSessionHandle; -use App\Session\SessionHandle; use App\Validation\ValidationFail; function getTacticController(): APITacticController { @@ -28,6 +27,9 @@ function getAuthController(): APIAuthController { return new APIAuthController(new AuthModel(new AccountGateway(new Connexion(get_database())))); } +/** + * A Front controller action + */ class Action { /** * @var callable(mixed[]): HttpResponse $action action to call diff --git a/sql/setup-tables.sql b/sql/setup-tables.sql index 457803c..26e58da 100644 --- a/sql/setup-tables.sql +++ b/sql/setup-tables.sql @@ -1,13 +1,7 @@ -- drop tables here -DROP TABLE IF EXISTS FormEntries; DROP TABLE IF EXISTS Account; -DROP TABLE IF EXISTS TacticInfo; +DROP TABLE IF EXISTS Tactic; -CREATE TABLE FormEntries -( - name varchar NOT NULL, - description varchar NOT NULL -); CREATE TABLE Account ( id integer PRIMARY KEY AUTOINCREMENT, @@ -17,7 +11,7 @@ CREATE TABLE Account hash varchar NOT NULL ); -CREATE TABLE TacticInfo +CREATE TABLE Tactic ( id integer PRIMARY KEY AUTOINCREMENT, name varchar NOT NULL, diff --git a/src/Gateway/TacticInfoGateway.php b/src/Gateway/TacticInfoGateway.php index efa0a7c..3075f69 100644 --- a/src/Gateway/TacticInfoGateway.php +++ b/src/Gateway/TacticInfoGateway.php @@ -18,7 +18,7 @@ class TacticInfoGateway { public function get(int $id): ?TacticInfo { $res = $this->con->fetch( - "SELECT * FROM TacticInfo WHERE id = :id", + "SELECT * FROM Tactic WHERE id = :id", [":id" => [$id, PDO::PARAM_INT]] ); @@ -33,14 +33,14 @@ class TacticInfoGateway { public function insert(string $name, int $owner): TacticInfo { $this->con->exec( - "INSERT INTO TacticInfo(name, owner) VALUES(:name, :owner)", + "INSERT INTO Tactic(name, owner) VALUES(:name, :owner)", [ ":name" => [$name, PDO::PARAM_STR], ":owner" => [$owner, PDO::PARAM_INT], ] ); $row = $this->con->fetch( - "SELECT id, creation_date, owner FROM TacticInfo WHERE :id = id", + "SELECT id, creation_date, owner FROM Tactic WHERE :id = id", [':id' => [$this->con->lastInsertId(), PDO::PARAM_INT]] )[0]; return new TacticInfo(intval($row["id"]), $name, strtotime($row["creation_date"]), $row["owner"]); @@ -48,7 +48,7 @@ class TacticInfoGateway { public function updateName(int $id, string $name): void { $this->con->exec( - "UPDATE TacticInfo SET name = :name WHERE id = :id", + "UPDATE Tactic SET name = :name WHERE id = :id", [ ":name" => [$name, PDO::PARAM_STR], ":id" => [$id, PDO::PARAM_INT], diff --git a/src/Session/MutableSessionHandle.php b/src/Session/MutableSessionHandle.php index 64ee52f..1459819 100644 --- a/src/Session/MutableSessionHandle.php +++ b/src/Session/MutableSessionHandle.php @@ -4,9 +4,17 @@ namespace App\Session; use App\Data\Account; +/** + * The mutable side of a session handle + */ interface MutableSessionHandle extends SessionHandle { - + /** + * @param string|null $url the url to redirect the user to after authentication. + */ public function setInitialTarget(?string $url): void; + /** + * @param Account $account update the session's account + */ public function setAccount(Account $account): void; } diff --git a/src/Session/PhpSessionHandle.php b/src/Session/PhpSessionHandle.php index 5568eb5..7d6b10b 100644 --- a/src/Session/PhpSessionHandle.php +++ b/src/Session/PhpSessionHandle.php @@ -4,8 +4,11 @@ namespace App\Session; use App\Data\Account; +/** + * A PHP session handle + */ class PhpSessionHandle implements MutableSessionHandle { - public static function init(): SessionHandle { + public static function init(): self { if (session_status() !== PHP_SESSION_NONE) { throw new \Exception("A php session is already started !"); } diff --git a/src/Session/SessionHandle.php b/src/Session/SessionHandle.php index 2114877..663c78c 100644 --- a/src/Session/SessionHandle.php +++ b/src/Session/SessionHandle.php @@ -4,8 +4,20 @@ namespace App\Session; use App\Data\Account; +/** + * An immutable session handle + */ interface SessionHandle { + /** + * The initial target url if the user wanted to perform an action that requires authentication + * but has been required to login first in the application. + * @return string|null Get the initial targeted URL + */ public function getInitialTarget(): ?string; + /** + * The session account if the user is logged in. + * @return Account|null + */ public function getAccount(): ?Account; }