src/Controller/Recipe/RecipeController.php line 57

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Recipe;
  3. use App\Services\RecipeService;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. // use Nelmio\ApiDocBundle\Annotation\Security;
  9. // use OpenApi\Annotations as OA;
  10. class RecipeController extends AbstractController
  11. {
  12.     private $recipeService;
  13.     public function __construct(RecipeService $recipeService)
  14.     {
  15.         $this->recipeService $recipeService;
  16.     }
  17.     #[Route('/api/add-recipe'name'app_recipe'methods: ["POST"])]
  18.     public function addRecipe(Request $request): Response
  19.     {
  20.         $data $request->request->all();
  21.         $files $request->files;
  22.         return $this->recipeService->add($data$files);
  23.     }
  24.     #[Route('/api/delete-recipe/{id}'name'delete_recipe'methods: ["DELETE"])]
  25.     public function deleteRecipe($id): Response
  26.     {
  27.         return $this->recipeService->delete($id);
  28.     }
  29.   
  30.     #[Route('/delete-recipe/{id}'name'delete_recipe_admin'methods: ["DELETE"])]
  31.     public function deleteRecipeAdmin($id): Response
  32.     {
  33.         return $this->recipeService->delete($id);
  34.     }
  35.     #[Route('/show-recipe/{slug}'name'show_recipe'methods: ["GET"])]
  36.     public function showRecipe($slug): Response
  37.     {
  38.         return $this->recipeService->show($slug);
  39.     }
  40.     #[Route('/api/update-recipe/{id}'name'update_recipe'methods: ["POST"])]
  41.     public function updateRecipe(Request $request$id): Response
  42.     {
  43.         $data $request->request->all();
  44.         $files $request->files;
  45.         return $this->recipeService->update($id,$data ,$files);
  46.     }
  47.     #[Route('/get-recipes'name'get_recipes'methods: ["POST"])]
  48.     public function getRecipes(Request $request): Response
  49.     {
  50.         $data json_decode($request->getContent(), true);
  51.         return $this->recipeService->getAll($data);
  52.     }
  53.     #[Route('/get-recipes-by-type/{slug}'name'get_by_cat_recipes'methods: ["POST"])]
  54.     public function getRecipesByType($slugRequest $request): Response
  55.     {
  56.         $data json_decode($request->getContent(), true);
  57.         return $this->recipeService->getByType($slug$data);
  58.     }
  59.     #[Route('api/like-recipe/{id}'name'app_like_recipes'methods: ["GET"])]
  60.     public function likeRecipe($id): Response
  61.     {
  62.         $user $this->getUser();
  63.         return $this->recipeService->likeOrDislike($id$user);
  64.     }
  65.     #[Route('api/comment-recipe/{slug}'name'app_comment_recipes'methods: ["POST"])]
  66.     public function commentRecipe($slugRequest $request): Response
  67.     {
  68.         $data json_decode($request->getContent(), true);
  69.         // $data = $request->request->all();
  70.         return $this->recipeService->commentRecipe($slug$data);
  71.     }
  72.     #[Route('/api/update-comment/{recipe_id}/{comment_id}'name'app_update_comment_recipes'methods: ["POST"])]
  73.     public function updateCommentRecipe($recipe_id$comment_idRequest $request): Response
  74.     {
  75.         $data $request->request->all();
  76.         return $this->recipeService->updateCommentRecipe($recipe_id$comment_id$data);
  77.     }
  78.     #[Route('/api/delete-comment/{recipe_id}/{comment_id}'name'app_delete_comment_recipes'methods: ["PATCH"])]
  79.     public function deleteCommentRecipe($recipe_id$comment_id): Response
  80.     {
  81.         return $this->recipeService->deleteCommentRecipe($recipe_id$comment_id);
  82.     }
  83.     #[Route('/get-recipe_types/spot_light'name'get_recipes_spot_light'methods: ["GET"])]
  84.     public function getRecipeSpotLight(): Response
  85.     {
  86.         return $this->recipeService->getRecipeSpotLight();
  87.     }
  88.     // FILTERS
  89.     #[Route('api/get-recipe-by-level/{id}'name'app_get_recipes_by_level'methods: ["GET"])]
  90.     public function getRecipeByLevel($id): Response
  91.     {
  92.         return $this->recipeService->getByLevel($id);
  93.     }
  94.     #[Route('get-recipe-by-name/{keyword}'name'app_get_recipes_by_name'methods: ["GET"])]
  95.     public function getRecipeByName($keyword): Response
  96.     {
  97.         return $this->recipeService->getRecipeByName($keyword);
  98.     }
  99.     #[Route('api/add-to-recipe-to-bookmaker/{id}'name'app_add_recipe_to_book_maker'methods: ["GET"])]
  100.     public function addRecipeToBookMaker($id): Response
  101.     {
  102.         return $this->recipeService->addRecipeToBookMark($id);
  103.     }
  104.     #[Route('api/get-recipe-bookmaker'name'app_get_recipe_book_maker'methods: ["GET"])]
  105.     public function getRecipeBookMark(): Response
  106.     {
  107.         return $this->recipeService->getRecipeBookMark();
  108.         
  109.     }
  110.     #[Route('get-recipes-count'name'app_get_all_recipe_count'methods: ["GET"])]
  111.     public function getRecipeAllCount(): Response
  112.     {
  113.         return $this->recipeService->getRecipeAll();
  114.     }
  115.     #[Route('get-recipe-is-spotlight'name'app_get_is_spot_ligth_recipes_by_name'methods: ["GET"])]
  116.     public function getIsSpotLight()
  117.     {
  118.         return $this->recipeService->getIsSpotifiyRecipe();
  119.     }
  120.     #[Route('set-is-spotLigth-abj/{slug}'name'app_set_is_spot_ligth_recipes'methods: ["GET"])]
  121.     public function setIsSpotLigth($slug)
  122.     {
  123.         return $this->recipeService->setIsSpotifiyRecipe($slug);
  124.     }
  125.     #[Route('get-all-recipes'name'app_get_all_recipe'methods: ["GET"])]
  126.     public function getAllRecipeForDash(Request $request)
  127.     {
  128.         $data['page'] = $request->query->getInt('page'1);
  129.         $data['per_page'] = $request->query->getInt('per_page'15);
  130.         return $this->recipeService->getAllRecipeForDash($data);
  131.     }
  132.     #[Route('active-recipe/{slug}'name'active_recipe'methods: ["GET"])]
  133.     public function activeRecipe($slug)
  134.     {
  135.         return $this->recipeService->activeRecipe($slug);
  136.     }
  137.     #[Route('recettes'name'recipe_for_abj')]
  138.     public function recipeForAbj(Request $request){
  139.         
  140.         $data = [
  141.             "ordre"=>$request->query->get('ordre') ?? "DESC",
  142.             "nombre_elt"=>$request->query->get('nombre_elt') ?? 5,
  143.             "isActive"=>$request->query->get('isActive') ?? 1,
  144.             "valeur"=>$request->query->get('valeur') ?? null,
  145.             "critere"=>$request->query->get('critere') ?? null,
  146.             "allProperty"=>$request->query->get('allProperty') ?? 0,
  147.         ];
  148.         return $this->recipeService->recipeForAbj($data);        
  149.     }
  150.     // #[Route('generate_js_for_af', name: 'generate_js_for_af')]
  151.     // public function generate(Request $request){
  152.     //     $data = [
  153.     //         "ordre"=>$request->query->get('ordre') ?? "DESC",
  154.     //         "nombre_elt"=>$request->query->get('nombre_elt') ?? 5,
  155.     //         "isActive"=>$request->query->get('isActive') ?? 1,
  156.     //         "valeur"=>$request->query->get('valeur') ?? null,
  157.     //         "critere"=>$request->query->get('critere') ?? null,
  158.     //         "allProperty"=>$request->query->get('allProperty') ?? 0,
  159.     //     ];
  160.     //     return $this->recipeService->generateJS($data);    
  161.     // }
  162.     
  163. }