diff --git a/lib/Controller/EpisodeActionController.php b/lib/Controller/EpisodeActionController.php index 761979c..19ff329 100644 --- a/lib/Controller/EpisodeActionController.php +++ b/lib/Controller/EpisodeActionController.php @@ -41,6 +41,7 @@ public function __construct( public function create(): JSONResponse { $episodeActionsArray = $this->filterEpisodesFromRequestParams($this->request->getParams()); + $episodeActionsArray = $this->filterOnlyPlays($episodeActionsArray); $this->episodeActionSaver->saveEpisodeActions($episodeActionsArray, $this->userId); return new JSONResponse(["timestamp" => time()]); @@ -67,11 +68,11 @@ public function list(int $since = 0): JSONResponse { ]); } - /** - * @param array $data - * @return array $episodeActionsArray - */ - public function filterEpisodesFromRequestParams(array $data): array { - return array_filter($data, "is_numeric", ARRAY_FILTER_USE_KEY); + public function filterEpisodesFromRequestParams(array $episodesFromRequestParams): array { + return array_filter($episodesFromRequestParams, "is_numeric", ARRAY_FILTER_USE_KEY); + } + + public function filterOnlyPlays(array $episodesFromRequestParams): array { + return array_filter($episodesFromRequestParams, fn($ep) => isset($ep['action']) && strtolower($ep['action']) === 'play'); } } diff --git a/tests/Integration/Controller/EpisodeActionControllerTest.php b/tests/Integration/Controller/EpisodeActionControllerTest.php index 53c51c9..2c30455 100644 --- a/tests/Integration/Controller/EpisodeActionControllerTest.php +++ b/tests/Integration/Controller/EpisodeActionControllerTest.php @@ -151,6 +151,16 @@ public function testEpisodeActionCreateAction(): void "started": 15, "position": 120, "total": 500 + }, + { + "podcast": "https://example.com/feed.rss", + "episode": "https://example.com/files/s01e21.mp3", + "guid": "s01e21-example-org", + "action": "DELETE", + "timestamp": "2009-12-12T09:00:00", + "started": -1, + "position": -1, + "total": -1 } ]', true, @@ -181,6 +191,7 @@ public function testEpisodeActionCreateAction(): void $episodeActionEntities = $mapper->findAll(0, $userId); /** @var EpisodeActionEntity $firstEntity */ $firstEntity = $episodeActionEntities[0]; + $this->assertCount(1, $episodeActionEntities); $this->assertSame( "https://example.com/feed.rss", $firstEntity->getPodcast()