Skip to content

Commit

Permalink
Update the last seen attributes from the API
Browse files Browse the repository at this point in the history
When using the Plex API, any episodes that are watched are correctly
marked as seen but that is not reflected in the last seen ordering in
the TV view.

This commit ensures that when an episode is watched, sorting by "Last
seen" on the TV page still works.
  • Loading branch information
Ilias committed May 17, 2020
1 parent 49bb978 commit 76b70e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/app/Services/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public function handle(array $data)
->findBySeasonNumber($this->getSeasonNumber())
->first();

// Mark the episode as seen and update the last_seen_at attribute of the item
if ($episode) {
$found->updateLastSeenAt($found->tmdb_id);
$episode->update([
'seen' => true,
]);
Expand Down
18 changes: 18 additions & 0 deletions backend/tests/Services/Api/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,22 @@ public function it_should_mark_an_episode_as_seen($fixture)
$this->assertCount(0, $seenEpisodesBefore);
$this->assertCount(1, $seenEpisodesAfter);
}

public function it_should_update_last_seen_at($fixture)
{
$this->createTv();

$api = app($this->apiClass);

$lastSeenBefore = Item::first()->last_seen_at;

// sleep for 1 second so that Carbon::now() returns a different date
sleep(1);

$api->handle($this->apiFixtures($fixture));

$lastSeenAfter = Item::first()->last_seen_at;

$this->assertNotEquals($lastSeenBefore, $lastSeenAfter);
}
}
6 changes: 6 additions & 0 deletions backend/tests/Services/Api/PlexApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,10 @@ public function it_should_mark_an_episode_as_seen()
{
$this->apiTest->it_should_mark_an_episode_as_seen('plex/episode_seen.json');
}

/** @test */
public function it_should_update_last_seen_at_of_a_show()
{
$this->apiTest->it_should_update_last_seen_at('plex/episode_seen.json');
}
}

0 comments on commit 76b70e3

Please sign in to comment.