diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index 4398421..b091060 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -12,8 +12,8 @@ doctrine: mappings: App: is_bundle: false - dir: '%kernel.project_dir%/src/Composant' - prefix: 'App\Composant' + dir: '%kernel.project_dir%/src/Component' + prefix: 'App\Component' alias: App when@test: diff --git a/migrations/Version20220407211354.php b/migrations/Version20220407211354.php new file mode 100644 index 0000000..6b33597 --- /dev/null +++ b/migrations/Version20220407211354.php @@ -0,0 +1,33 @@ +addSql('CREATE TABLE roles (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, created DATETIME NOT NULL, updated DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE users (id INT AUTO_INCREMENT NOT NULL, lastname VARCHAR(255) NOT NULL, firstname VARCHAR(255) NOT NULL, kwh_price NUMERIC(2, 0) NOT NULL, hourly_cost NUMERIC(2, 0) NOT NULL, created DATETIME NOT NULL, updated DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE roles'); + $this->addSql('DROP TABLE users'); + } +} diff --git a/src/Component/Role/Domain/Role.php b/src/Component/Role/Domain/Role.php new file mode 100644 index 0000000..e298868 --- /dev/null +++ b/src/Component/Role/Domain/Role.php @@ -0,0 +1,62 @@ +id; + } + + /** + * @param int $id + */ + public function setId(int $id): void + { + $this->id = $id; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName(string $name): void + { + $this->name = $name; + } + +} \ No newline at end of file diff --git a/src/Component/Role/Domain/RoleDataMapper.php b/src/Component/Role/Domain/RoleDataMapper.php new file mode 100644 index 0000000..2a3b53f --- /dev/null +++ b/src/Component/Role/Domain/RoleDataMapper.php @@ -0,0 +1,8 @@ +find($id); + + if (!$user) + { + throw new Exception( + 'L\'utilisateur n\'existe pas' + ); + } + + return $user; + } + + public function findAll(): array + { + // TODO: Implement findAll() method. + } +} \ No newline at end of file diff --git a/src/Composant/User/Domain/User.php b/src/Component/User/Domain/User.php similarity index 56% rename from src/Composant/User/Domain/User.php rename to src/Component/User/Domain/User.php index b8e0fee..769243d 100644 --- a/src/Composant/User/Domain/User.php +++ b/src/Component/User/Domain/User.php @@ -1,7 +1,8 @@ created = new \DateTime(); + $this->updated = new \DateTime(); } /** - * @return float + * @return int */ - public function getKwhPrice(): float + public function getId(): int { - return $this->kwhPrice; + return $this->id; } /** - * @param float $kwhPrice + * @param int $id */ - public function setKwhPrice(float $kwhPrice): void + public function setId(int $id): void { - $this->kwhPrice = $kwhPrice; + $this->id = $id; } /** - * @return float + * @return string */ - public function getHourlyCost(): float + public function getLastname(): string { - return $this->hourlyCost; + return $this->lastname; } /** - * @param float $hourlyCost + * @param string $lastname */ - public function setHourlyCost(float $hourlyCost): void + public function setLastname(string $lastname): void { - $this->hourlyCost = $hourlyCost; + $this->lastname = $lastname; } /** - * @return int + * @return string */ - public function getRoleId(): int + public function getFirstname(): string { - return $this->roleId; + return $this->firstname; } /** - * @param int $roleId + * @param string $firstname */ - public function setRoleId(int $roleId): void + public function setFirstname(string $firstname): void { - $this->roleId = $roleId; + $this->firstname = $firstname; } /** - * @return string + * @return Role */ - public function getLastname(): string + public function getRole(): Role { - return $this->lastname; + return $this->role; } /** - * @param string $lastname + * @param Role $role */ - public function setLastname(string $lastname): void + public function setRole(Role $role): void { - $this->lastname = $lastname; + $this->role = $role; } /** - * @return string + * @return float */ - public function getFirstname(): string + public function getKwhPrice(): float { - return $this->firstname; + return $this->kwhPrice; } /** - * @param string $firstname + * @param float $kwhPrice */ - public function setFirstname(string $firstname): void + public function setKwhPrice(float $kwhPrice): void { - $this->firstname = $firstname; + $this->kwhPrice = $kwhPrice; } /** - * @return int + * @return float */ - public function getId(): int + public function getHourlyCost(): float { - return $this->id; + return $this->hourlyCost; } /** - * @param int $id + * @param float $hourlyCost */ - public function setId(int $id): void + public function setHourlyCost(float $hourlyCost): void { - $this->id = $id; + $this->hourlyCost = $hourlyCost; } + /** + * @return \DateTime + */ + public function getCreated(): \DateTime + { + return $this->created; + } + + /** + * @param \DateTime $created + */ + public function setCreated(\DateTime $created): void + { + $this->created = $created; + } + + /** + * @return \DateTime + */ + public function getUpdated(): \DateTime + { + return $this->updated; + } + + /** + * @param \DateTime $updated + */ + public function setUpdated(\DateTime $updated): void + { + $this->updated = $updated; + } + + } \ No newline at end of file diff --git a/src/Component/User/Domain/UserDataMapper.php b/src/Component/User/Domain/UserDataMapper.php new file mode 100644 index 0000000..6baf11d --- /dev/null +++ b/src/Component/User/Domain/UserDataMapper.php @@ -0,0 +1,8 @@ +findById(1); return new Response( $user->getId(). " " .$user->getLastname(),