From 788357a6a7f60306caa47667a9924f2fcc5a7412 Mon Sep 17 00:00:00 2001 From: Lee Peuker Date: Mon, 11 Jul 2022 21:50:17 +0200 Subject: [PATCH] Fix issue with unique constraint on movie watch date --- ...SetCorrectConstraintForMovieWatchDates.php | 24 +++++++++++++++++++ src/Application/Movie/Api.php | 2 +- src/Application/Movie/Repository.php | 12 +++++----- src/Application/Movie/Service/Update.php | 10 ++++---- 4 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 db/migrations/20220711194814_SetCorrectConstraintForMovieWatchDates.php diff --git a/db/migrations/20220711194814_SetCorrectConstraintForMovieWatchDates.php b/db/migrations/20220711194814_SetCorrectConstraintForMovieWatchDates.php new file mode 100644 index 00000000..bcc8621f --- /dev/null +++ b/db/migrations/20220711194814_SetCorrectConstraintForMovieWatchDates.php @@ -0,0 +1,24 @@ +execute( + <<execute( + <<movieUpdateService->setPersonalRating($movieId, $userId, $rating); + $this->movieUpdateService->setUserRating($movieId, $userId, $rating); } } diff --git a/src/Application/Movie/Repository.php b/src/Application/Movie/Repository.php index 6216d459..30a7c750 100644 --- a/src/Application/Movie/Repository.php +++ b/src/Application/Movie/Repository.php @@ -534,7 +534,12 @@ public function updateLetterboxdId(int $id, string $letterboxdId) : void $this->dbConnection->update('movie', ['letterboxd_id' => $letterboxdId], ['id' => $id]); } - public function updatePersonalRating(int $id, int $userId, PersonalRating $personalRating) : void + public function updateTraktId(int $id, TraktId $traktId) : void + { + $this->dbConnection->update('movie', ['trakt_id' => $traktId->asInt()], ['id' => $id]); + } + + public function updateUserRating(int $id, int $userId, PersonalRating $personalRating) : void { $this->dbConnection->executeQuery( 'INSERT INTO movie_user_rating (movie_id, user_id, rating) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE rating=?', @@ -542,11 +547,6 @@ public function updatePersonalRating(int $id, int $userId, PersonalRating $perso ); } - public function updateTraktId(int $id, TraktId $traktId) : void - { - $this->dbConnection->update('movie', ['trakt_id' => $traktId->asInt()], ['id' => $id]); - } - private function fetchById(int $id) : Entity { $data = $this->dbConnection->fetchAssociative('SELECT * FROM `movie` WHERE id = ?', [$id]); diff --git a/src/Application/Movie/Service/Update.php b/src/Application/Movie/Service/Update.php index 302c869f..b5e16685 100644 --- a/src/Application/Movie/Service/Update.php +++ b/src/Application/Movie/Service/Update.php @@ -31,6 +31,11 @@ public function __construct( ) { } + public function setUserRating(int $id, int $userId, PersonalRating $rating) : void + { + $this->repository->updateUserRating($id, $userId, $rating); + } + public function updateCast(int $movieId, Cast $tmdbCast) : void { $this->movieCasteDeleteService->deleteByMovieId($movieId); @@ -103,11 +108,6 @@ public function updateProductionCompanies(int $movieId, Company\EntityList $genr } } - public function setPersonalRating(int $id, int $userId, PersonalRating $rating) : void - { - $this->repository->updatePersonalRating($id, $userId, $rating); - } - public function updateTraktId(int $movieId, TraktId $traktId) : void { $this->repository->updateTraktId($movieId, $traktId);