Finish Advanced Search
This commit is contained in:
@@ -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 ] );
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user