Skip to content

Commit

Permalink
Feat: All recipes list page (#12)
Browse files Browse the repository at this point in the history
* Feat: All recipes list page

* chore: fix bad reference

* Apply pint changes

---------

Co-authored-by: IronSinew <[email protected]>
  • Loading branch information
IronSinew and IronSinew authored Apr 24, 2024
1 parent 69c8dfe commit a594da0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/Http/Controllers/AllRecipeListController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Controllers;

use App\Models\Recipe;
use Illuminate\Http\Request;
use Inertia\Inertia;

class AllRecipeListController extends Controller
{
public function __invoke(Request $request)
{
$perPageAmount = 9;

//@codeCoverageIgnoreStart
if ($request->wantsJson()) {
return Recipe::orderBy('id')->cursorPaginate($perPageAmount);
}
//@codeCoverageIgnoreEnd

return Inertia::render('Recipe/RecipeList')->with([
'label' => fn () => collect(['name' => 'All Recipes']),
'recipes' => fn () => Recipe::orderBy('id')->cursorPaginate($perPageAmount),
]);
}
}
5 changes: 5 additions & 0 deletions resources/js/Layouts/AppLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const menuItems = ref([
icon: "pi pi-envelope",
route: "label.index",
},
{
label: "All Recipes",
icon: "pi pi-list",
route: "recipe.all",
}
]);
onMounted(() => {
Expand Down
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Controllers\Admin\LabelController as AdminLabelController;
use App\Http\Controllers\Admin\RecipeController as AdminRecipeController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\AllRecipeListController;
use App\Http\Controllers\CategoryController;
use App\Http\Controllers\CategoryListController;
use App\Http\Controllers\HomeController;
Expand All @@ -26,6 +27,7 @@
Route::get('/labels', [LabelController::class, 'index'])->name('label.index');
Route::get('/labels/{label}', [LabelController::class, 'show'])->name('label.show');

Route::get('/recipes', AllRecipeListController::class)->name('recipe.all');
Route::get('/recipe/{recipe}', RecipeController::class)->name('recipe.show');
Route::post('/search-simple', SearchSimpleController::class)->name('search.simple');

Expand Down
31 changes: 31 additions & 0 deletions tests/Feature/Http/Controllers/AllRecipeListControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Http\Controllers;

use App\Models\Recipe;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Inertia\Testing\AssertableInertia as Assert;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

/**
* @see \App\Http\Controllers\AllRecipeListController
*/
final class AllRecipeListControllerTest extends TestCase
{
use RefreshDatabase;

#[Test]
public function index_displays_view(): void
{
Recipe::factory()->count(5)->create();

$response = $this->get(route('recipe.all'));

$response->assertOk();
$response->assertInertia(fn (Assert $page) => $page
->component('Recipe/RecipeList')
->has('recipes.data', 5)
);
}
}

0 comments on commit a594da0

Please sign in to comment.