mirror of
https://github.com/kevin-DL/scraps.git
synced 2026-01-11 18:04:31 +00:00
Do the search
This commit is contained in:
13
app/Http/Controllers/DashboardController.php
Normal file
13
app/Http/Controllers/DashboardController.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return Inertia::render('Dashboard');
|
||||
}
|
||||
}
|
||||
28
app/Http/Controllers/SearchController.php
Normal file
28
app/Http/Controllers/SearchController.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Integrations\Spoonacular\Requests\FindRecipesByIngredients;
|
||||
use App\Http\Integrations\Spoonacular\SpoonacularConnector;
|
||||
use App\Http\Requests\RecipeSearchRequest;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class SearchController extends Controller
|
||||
{
|
||||
public function recipes(RecipeSearchRequest $request)
|
||||
{
|
||||
$data = $request->validated();
|
||||
$connector = new SpoonacularConnector();
|
||||
$request = new FindRecipesByIngredients(
|
||||
ingredients: array_map("trim", explode(",", $data['ingredients'])),
|
||||
ranking: 2
|
||||
);
|
||||
|
||||
$response = $connector->send($request);
|
||||
|
||||
return Inertia::render('Search/Recipes', [
|
||||
'recipes' => $response->json(),
|
||||
'previousSearch' => $data['ingredients']
|
||||
]);
|
||||
}
|
||||
}
|
||||
20
app/Http/Requests/RecipeSearchRequest.php
Normal file
20
app/Http/Requests/RecipeSearchRequest.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RecipeSearchRequest extends FormRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'ingredients' => ['required', 'string', 'min:3']
|
||||
];
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user