diff --git a/app/src/Domain/Entity.php b/app/src/Domain/Entity.php
new file mode 100644
index 0000000..d88b7f4
--- /dev/null
+++ b/app/src/Domain/Entity.php
@@ -0,0 +1,43 @@
+id = $id;
+ }
+
+ public function getId(): int
+ {
+ return $this->id;
+ }
+
+ public function setCreatedAt(DateTimeImmutable $createdAt): void
+ {
+ $this->createdAt = $createdAt;
+ }
+
+ public function getCreatedAt(): DateTimeImmutable
+ {
+ return $this->createdAt;
+ }
+
+ public function setUpdatedAt(DateTime $updatedAt): void
+ {
+ $this->updatedAt = $updatedAt;
+ }
+
+ public function getUpdatedAt(): DateTime
+ {
+ return $this->updatedAt;
+ }
+}
diff --git a/app/src/Domain/Model/Channel.php b/app/src/Domain/Entity/Channel.php
similarity index 97%
rename from app/src/Domain/Model/Channel.php
rename to app/src/Domain/Entity/Channel.php
index 66cf65f..f8f6369 100644
--- a/app/src/Domain/Model/Channel.php
+++ b/app/src/Domain/Entity/Channel.php
@@ -1,6 +1,6 @@
email = $email;
- $this->password = $password;
- $this->name;
- }
+ ) { }
public function getEmail(): string
{
@@ -37,7 +36,7 @@ class User
*/
public function isNew(): bool
{
- return (bool) $this->id;
+ return (bool) $this->getId();
}
/**
@@ -46,11 +45,19 @@ class User
*/
public static function fromArray(array $props): User
{
- return new self(
- $props['id'] ?? null,
+ $user = new self(
$props['email'],
$props['password'],
$props['name']
);
+
+ if ($props['id']) {
+ $user->setId($props['id']);
+ }
+
+ $user->setCreatedAt($props['createdAt']);
+ $user->setUpdatedAt($props['updatedAt']);
+
+ return $user;
}
}
diff --git a/app/src/Domain/Repository/UserRepository.php b/app/src/Domain/Repository/UserRepository.php
new file mode 100644
index 0000000..a2cd438
--- /dev/null
+++ b/app/src/Domain/Repository/UserRepository.php
@@ -0,0 +1,79 @@
+ $results['id'],
+ 'email' => $results['email'],
+ 'password' => $results['password'],
+ 'name' => $results['name'],
+ 'createdAt' => $results['created_at'],
+ 'updatedAt' => $results['updated_at']
+ ]);
+ }
+
+ /**
+ * @param string $query The Query for getting a User
+ * @param arary $params The parameters in the query
+ * @param PDO $connection The PDO connection
+ * @return array The column data from the Database
+ * @throws EntityNotFoundException The User does no exist
+ */
+ protected function queryForUser(
+ string $query,
+ array $params,
+ PDO $connection
+ ): array {
+ $statement = $connection->prepare($query);
+ $statement->execute($params);
+ $results = $statement->fetchAll();
+
+ if (!$results) {
+ throw new EntityNotFoundException("Unable to find User");
+ }
+
+ return array_shift($results);
+ }
+
+ public function get(int $id): User
+ {
+ $query = "SELECT * FROM users WHERE id = :id LIMIT 1";
+ $connection = $this->database->getConnection();
+ $userData = $this->queryForUser(
+ $query,
+ [ 'id' => $id ],
+ $connection
+ );
+ return $this->userFromQueryResults($userData);
+ }
+
+ public function getFromEmail(string $email): User
+ {
+ $query = "SELECT * FROM users WHERE email = :email LIMIT 1";
+ $connection = $this->database->getConnection();
+ $userData = $this->queryForUser(
+ $query,
+ [ 'email' => $email ],
+ $connection
+ );
+ return $this->userFromQueryResults($userData);
+ }
+}
diff --git a/app/src/Domain/Repository/UserRepositoryInterface.php b/app/src/Domain/Repository/UserRepositoryInterface.php
new file mode 100644
index 0000000..e01503e
--- /dev/null
+++ b/app/src/Domain/Repository/UserRepositoryInterface.php
@@ -0,0 +1,13 @@
+https://kevyscountrybreakfast.podbean.com/e/episode-5-sarasota-sizzle/#comments