2026-03-20 15:54:29 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Domain\Recettes;
|
|
|
|
|
|
|
|
|
|
use App\Domain\Controller;
|
2026-04-03 10:43:55 +02:00
|
|
|
use App\Http\JSONResponse;
|
|
|
|
|
use App\Http\Request;
|
2026-03-20 15:54:29 +01:00
|
|
|
|
|
|
|
|
class RecettesAPIController extends Controller {
|
|
|
|
|
|
|
|
|
|
public static function defineRoutes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
self::Route( routeUrl: '/api/recettes/list', routeName: 'api->recettes->list', routeAction: 'list', routeMethods: ['POST'] ),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
}
|
2026-04-03 10:43:55 +02:00
|
|
|
|
|
|
|
|
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 ] );
|
|
|
|
|
|
|
|
|
|
}
|
2026-03-20 15:54:29 +01:00
|
|
|
}
|