diff --git a/src/server/app/App/Repository.php b/src/server/app/App/Repository.php index cb47c6141a833d6d800d4331b3841bff681a9f92..061c84ae84885cb8cfb81e676a28f2e0200ce526 100644 --- a/src/server/app/App/Repository.php +++ b/src/server/app/App/Repository.php @@ -173,6 +173,42 @@ abstract class Repository } } + public function update(Domain $domain) + { + $domainKeyLength = count($domain->toArray()); + $query = "UPDATE {$this->table} SET "; + + $countKey = 0; + foreach ($domain->toArray() as $key => $value) { + if ($key != 'id') { + $query .= "$key = :$key"; + } + + if ($countKey < $domainKeyLength - 1) { + $query .= ", "; + } + + $countKey += 1; + } + + $query .= " WHERE id = :id"; + + $statement = $this->connection->prepare($query); + foreach ($domain->toArray() as $key => $value) { + if ($key != 'id') { + $statement->bindValue(":$key", $value); + } + } + + $statement->execute(); + + try { + return $domain; + } finally { + $statement->closeCursor(); + } + } + public function deleteAll(): void { $this->connection->exec("DELETE FROM {$this->table}"); diff --git a/src/server/app/Controller/CatalogController.php b/src/server/app/Controller/CatalogController.php index 50fa48385de65edba46fd2b46d8d7f8570b1dc1c..2bd2af949b496f95eef41f464cec10657f17cbfd 100644 --- a/src/server/app/Controller/CatalogController.php +++ b/src/server/app/Controller/CatalogController.php @@ -67,18 +67,25 @@ class CatalogController public function detail(): void { + $uuid = '6517b94da6b8c'; + $catalog = $this->catalogService->findByUUID($uuid); + + if (!$catalog) { + View::render('catalog/not-found', [ + 'title' => 'Catalog Not Found', + 'styles' => [ + '/css/catalog-not-found.css', + ], + ]); + return; + } + View::render('catalog/detail', [ 'title' => 'Catalog Detail', 'styles' => [ '/css/catalog-detail.css', ], - 'data' => [ - 'title' => 'Snowdrop', - 'category' => 'ANIME', - 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', - 'poster' => 'jihu-13.jpg', - 'trailer' => 'the-journey-of-elaina.mp4' - ] + 'data' => $catalog->toArray() ]); } diff --git a/src/server/app/Repository/CatalogRepository.php b/src/server/app/Repository/CatalogRepository.php index e781a5052552020bc690e9efcc568705503505f4..a76ebe94dada8c22868b9cdfd5e3c7d5ce2dec97 100644 --- a/src/server/app/Repository/CatalogRepository.php +++ b/src/server/app/Repository/CatalogRepository.php @@ -67,17 +67,4 @@ class CatalogRepository extends Repository return null; } } - - public function deleteAll(): void - { - $this->connection->exec("DELETE FROM catalogs"); - } - - public function deleteById(int $id): void - { - $statement = $this->connection->prepare("DELETE FROM catalogs WHERE id = ?"); - $statement->execute([$id]); - - $statement->closeCursor(); - } } \ No newline at end of file diff --git a/src/server/app/Service/CatalogService.php b/src/server/app/Service/CatalogService.php index c8266139af4c523d8df95ea5eb8165b4213a5733..9e79fa51f79c318895bc980704df524e14a8c2eb 100644 --- a/src/server/app/Service/CatalogService.php +++ b/src/server/app/Service/CatalogService.php @@ -35,6 +35,17 @@ class CatalogService return $catalogs; } + public function findByUUID(string $uuid): ?Catalog + { + $catalog = $this->catalogRepository->findOne('uuid', $uuid); + return $catalog; + } + + public function deleteByUUID(string $uuid): void + { + $this->catalogRepository->deleteBy('uuid', $uuid); + } + public function create(CatalogCreateRequest $request): CatalogCreateResponse { $this->validateCatalogCreateRequest($request);