Finish Advanced Search

This commit is contained in:
2026-04-03 10:43:55 +02:00
parent f918134469
commit f2397b6d31
8 changed files with 187 additions and 18 deletions

View File

@@ -3,6 +3,8 @@
namespace App\Domain\Recettes;
use App\Domain\Controller;
use App\Http\JSONResponse;
use App\Http\Request;
class RecettesAPIController extends Controller {
@@ -13,4 +15,29 @@ class RecettesAPIController extends Controller {
];
}
public function list(){
$title = Request::post( 'title' ) ?? "";
$tagsId = explode( ",", Request::post( 'tagsId' ) ) ?? [];
$ingredientsId = explode( ",", Request::post( 'ingredientsId' ) ) ?? [];
if( $tagsId == [ "" ] )
$tagsId = [];
if( $ingredientsId == [ "" ] )
$ingredientsId = [];
$tagsId = array_map( 'intval', $tagsId );
$ingredientsId = array_map( 'intval', $ingredientsId );
$recetteRepo = new RecetteRepository();
$resp = $recetteRepo->advancedRecetteSearch( $title, $tagsId, $ingredientsId );
$resp = array_map( function($recette) use ($recetteRepo){
return $recetteRepo->getByID( $recette['num_recette'] );
}, $resp ?? [] );
JSONResponse::sendSuccess( [ 'data' => $resp ] );
}
}