Skip to content

Commit

Permalink
feat: allow for filtering featured wikis
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Aug 22, 2023
1 parent 12443aa commit ff49ecf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/Http/Controllers/PublicWikiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ public function index(Request $request)
if ($perPage !== null) {
$perPage = intval($perPage);
}

$query = Wiki::query();

$isFeatured = $request->query('is_featured', null);
if ($isFeatured !== null) {
$query = $query->where(['is_featured' => boolval($isFeatured)]);
}

return new PublicWikiCollection(Wiki::query()->paginate($perPage));
}

Expand Down
19 changes: 19 additions & 0 deletions tests/Routes/Wiki/PublicWikiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,23 @@ public function testPagination()
->assertJsonCount(1, 'data')
->assertJsonPath('meta.total', 3);
}

public function testFilter()
{
$wiki = Wiki::factory()->create(['domain' => 'one.wikibase.cloud', 'is_featured' => false]);
WikiSiteStats::factory()->create(['wiki_id' => $wiki->id, 'pages' => 77]);

$wiki = Wiki::factory()->create(['domain' => 'two.wikibase.cloud', 'is_featured' => true]);
WikiSiteStats::factory()->create(['wiki_id' => $wiki->id, 'pages' => 66]);

$wiki = Wiki::factory()->create(['domain' => 'three.wikibase.cloud', 'is_featured' => false]);
WikiSiteStats::factory()->create(['wiki_id' => $wiki->id, 'pages' => 55]);

$this->json('GET', $this->route.'?is_featured=1')
->assertStatus(200)
->assertJsonPath('data.0.domain', 'two.wikibase.cloud')
->assertJsonPath('data.0.wiki_site_stats.pages', 66)
->assertJsonCount(1, 'data')
->assertJsonPath('meta.total', 1);
}
}

0 comments on commit ff49ecf

Please sign in to comment.