-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cd14b3
commit c8790cb
Showing
8 changed files
with
88 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Collection; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Support\Facades\Request; | ||
|
||
class CollectionItemController extends Controller | ||
{ | ||
public function index(Collection $collection) | ||
{ | ||
$filter = $collection->item_filter; | ||
if (!$filter) { | ||
abort(404); | ||
} | ||
|
||
$parameters = ['filter' => $filter]; | ||
|
||
if (request()->has('size')) { | ||
$parameters['size'] = request()->integer('size'); | ||
} | ||
|
||
if (request()->has('page')) { | ||
$parameters['page'] = request()->integer('page'); | ||
} | ||
|
||
$request = Request::create(route('api.v1.items.index', $parameters)); | ||
return app()->handle($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Api; | ||
|
||
use App\Collection; | ||
use App\Elasticsearch\Repositories\ItemRepository; | ||
use App\Item; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Tests\RecreateSearchIndex; | ||
use Tests\TestCase; | ||
|
||
class CollectionItemsTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
use RecreateSearchIndex; | ||
|
||
public function testIndex() | ||
{ | ||
Item::factory()->create(['author' => 'author-1']); | ||
Item::factory()->create(['author' => 'author-2']); | ||
app(ItemRepository::class)->refreshIndex(); | ||
|
||
$collection = Collection::factory()->create([ | ||
'url' => 'https://www.webumenia.sk/katalog-new?filter[author][]=author-1', | ||
]); | ||
|
||
$url = route('api.collections.items.index', [ | ||
'collection' => $collection, | ||
'size' => 2, | ||
]); | ||
$response = $this->get($url); | ||
$response->assertJsonCount(1, 'data'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters