src/Controller/Api/BoxController.php line 90

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\CommonDataStructures\InputDetailsData;
  4. use App\CommonDataStructures\InputGroupsData;
  5. use App\Exception\AppException;
  6. use App\UseCase\GetDetails;
  7. use FOS\RestBundle\Controller\AbstractFOSRestController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\RequestStack;
  10. use Symfony\Component\HttpFoundation\Response;
  11. /**
  12.  * Diabelek: te 3 wpisy są potrzebne by się generowała dokumentacja
  13.  */
  14. use Nelmio\ApiDocBundle\Annotation\Model;
  15. use OpenApi\Annotations as OA;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. class BoxController extends AbstractFOSRestController
  18. {
  19.     /**
  20.      * @var Request|null
  21.      */
  22.     private ?Request $request;
  23.     /**
  24.      * @param RequestStack|null $requestStack
  25.      * @param GetDetails $getDetails
  26.      */
  27.     public function __construct(
  28.         ?RequestStack               $requestStack,
  29.         private readonly GetDetails $getDetails
  30.     )
  31.     {
  32.         $this->request $requestStack->getCurrentRequest();
  33.     }
  34.     /**
  35.      * Details
  36.      *
  37.      * @Route("/box", methods={"POST"})
  38.      *
  39.      * @OA\Tag(name="Box")
  40.      *
  41.      * @OA\Post(
  42.      *     description="Box",
  43.      *      @OA\RequestBody(
  44.      *          required=false,
  45.      *          @OA\MediaType(
  46.      *              mediaType="application/json",
  47.      *              @OA\Schema(
  48.      *                  description="Place for json body",
  49.      *                  type="string"
  50.      *              )
  51.      *          )
  52.      *      )
  53.      * )
  54.      *
  55.      * @OA\Response(
  56.      *     response=200,
  57.      *     description="Box",
  58.      *     @OA\MediaType(
  59.      *          mediaType="application/json"
  60.      *     )
  61.      * )
  62.      *
  63.      * @return Response
  64.      * @throws AppException
  65.      */
  66.     public function postAction(): Response
  67.     {
  68.         $data json_decode($this->request->getContent(), true);
  69.         foreach ($data as $ofr_id) {
  70.             $dataId = ['conditions' => ['ofr_id' => $ofr_id]];
  71.             $inputData = new InputDetailsData($dataId);
  72.             if ($this->getDetails->getResponse($inputData)) {
  73.                 $outputData[] = $this->getDetails->getResponse($inputData);
  74.             }
  75.         }
  76.         if (empty($outputData)) {
  77.             $data = ['conditions' => ['trp_depDate' => "20240418:20260418"]];
  78.             $inputData = new InputGroupsData($data);
  79.             throw new AppException('No data found');
  80.         }
  81.         return $this->handleView($this->view($outputData));
  82.     }
  83. }