|
|
|
@ -11,30 +11,27 @@ use FOS\RestBundle\Controller\Annotations as Rest;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
|
|
|
|
|
|
|
#[Rest\Route(path: '/api/charts', name: 'api_charts')]
|
|
|
|
#[Rest\Route(path: '/api/charts', name: 'api_charts_')]
|
|
|
|
class ChartRestController extends AbstractRestController
|
|
|
|
class ChartRestController extends AbstractRestController
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
#[Rest\Get('/', name: '_list')]
|
|
|
|
#[Rest\Get('/', name: 'list')]
|
|
|
|
public function list(DocumentManager $dm, Request $request) : Response
|
|
|
|
public function list(DocumentManager $dm, Request $request) : Response
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$charts = \array_map(fn(Chart $entity) => ChartOutput::fromEntity($entity)->id, $dm->getRepository(Chart::class)->findAll());
|
|
|
|
$charts = \array_map(fn(Chart $entity) => ChartOutput::fromEntity($entity)->id, iterator_to_array($this->getUser()->getCharts()));
|
|
|
|
return $this->respond($charts, Response::HTTP_OK);
|
|
|
|
return $this->respond($charts, Response::HTTP_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[Rest\Get('/{id}', name: '_detail')]//, requirements: ['id' => '\d+'])]
|
|
|
|
#[Rest\Get('/{id}', name: 'detail')]
|
|
|
|
public function detail(DocumentManager $dm, Chart $chart): Response
|
|
|
|
public function detail(DocumentManager $dm, Chart $chart): Response
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//$chart = $this->findOrFail($dm, $id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$chartDto = ChartOutput::fromEntity($chart);
|
|
|
|
$chartDto = ChartOutput::fromEntity($chart);
|
|
|
|
return $this->respond( $chartDto, Response::HTTP_OK);
|
|
|
|
return $this->respond( $chartDto, Response::HTTP_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[Rest\Put('/insert', name: '_insert')]
|
|
|
|
#[Rest\Post('/insert', name: 'insert')]
|
|
|
|
public function insert(DocumentManager $dm, Request $request): Response
|
|
|
|
public function insert(DocumentManager $dm, Request $request): Response
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//$chart = $newChart->toEntity();
|
|
|
|
|
|
|
|
$data = json_decode($request->getContent());
|
|
|
|
$data = json_decode($request->getContent());
|
|
|
|
$chart = new Chart();
|
|
|
|
$chart = new Chart();
|
|
|
|
$chart->setName($data->name);
|
|
|
|
$chart->setName($data->name);
|
|
|
|
@ -46,15 +43,25 @@ class ChartRestController extends AbstractRestController
|
|
|
|
return $this->respond( $chart->getName(), Response::HTTP_OK);
|
|
|
|
return $this->respond( $chart->getName(), Response::HTTP_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*private function findOrFail(DocumentManager $dm, int $id): Chart
|
|
|
|
#[Rest\Post('/{id}/update', name: 'update')]
|
|
|
|
|
|
|
|
public function update(DocumentManager $dm, Request $request, Chart $chart): Response
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//$chart = $dm->getRepository(Chart::class)->findOneBy(['code' => $id]);
|
|
|
|
$data = json_decode($request->getContent());
|
|
|
|
$chart = $dm->getRepository(Chart::class)->findOneBy(['_id' => $id]);
|
|
|
|
$chart->setName($data->name);
|
|
|
|
|
|
|
|
$chart->setMetadata($data->metadata);
|
|
|
|
|
|
|
|
$chart->setTable($data->table);
|
|
|
|
|
|
|
|
|
|
|
|
if ($chart === null) {
|
|
|
|
$dm->persist($chart);
|
|
|
|
throw $this->createNotFoundException("Chart was not found");
|
|
|
|
$dm->flush();
|
|
|
|
|
|
|
|
return $this->respond( $chart->getName(), Response::HTTP_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $chart ;
|
|
|
|
#[Rest\Delete('/{id}/remove', name:'remove')]
|
|
|
|
}*/
|
|
|
|
public function remove(DocumentManager $dm, Request $request, Chart $chart): Response
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$dm->remove($chart);
|
|
|
|
|
|
|
|
$dm->flush();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->respond( $chart->getName(), Response::HTTP_OK);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|