<?php
namespace App\Controller\Api;
use App\CommonDataStructures\InputDetailsData;
use App\CommonDataStructures\InputGroupsData;
use App\Exception\AppException;
use App\UseCase\GetDetails;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
/**
* Diabelek: te 3 wpisy są potrzebne by się generowała dokumentacja
*/
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Annotations as OA;
use Symfony\Component\Routing\Annotation\Route;
class BoxController extends AbstractFOSRestController
{
/**
* @var Request|null
*/
private ?Request $request;
/**
* @param RequestStack|null $requestStack
* @param GetDetails $getDetails
*/
public function __construct(
?RequestStack $requestStack,
private readonly GetDetails $getDetails
)
{
$this->request = $requestStack->getCurrentRequest();
}
/**
* Details
*
* @Route("/box", methods={"POST"})
*
* @OA\Tag(name="Box")
*
* @OA\Post(
* description="Box",
* @OA\RequestBody(
* required=false,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* description="Place for json body",
* type="string"
* )
* )
* )
* )
*
* @OA\Response(
* response=200,
* description="Box",
* @OA\MediaType(
* mediaType="application/json"
* )
* )
*
* @return Response
* @throws AppException
*/
public function postAction(): Response
{
$data = json_decode($this->request->getContent(), true);
foreach ($data as $ofr_id) {
$dataId = ['conditions' => ['ofr_id' => $ofr_id]];
$inputData = new InputDetailsData($dataId);
if ($this->getDetails->getResponse($inputData)) {
$outputData[] = $this->getDetails->getResponse($inputData);
}
}
if (empty($outputData)) {
$data = ['conditions' => ['trp_depDate' => "20240418:20260418"]];
$inputData = new InputGroupsData($data);
throw new AppException('No data found');
}
return $this->handleView($this->view($outputData));
}
}