first impl for api

This commit is contained in:
2021-05-05 20:33:34 +02:00
parent 19fdf2a503
commit f02e33fda7
16 changed files with 849 additions and 87 deletions

View File

@@ -0,0 +1,48 @@
<?php
namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
class AccompanyingCourseApiController extends ApiController
{
public function participationApi($accompanyingPeriodId, Request $request)
{
/** @var AccompanyingPeriod $accompanyingPeriod */
$accompanyingPeriod = $this->getEntity($accompanyingPeriodId);
$person = $this->serializer->deserialize($request->getContent(), Person::class, $_format, []);
if (NULL === $person) {
throw new BadRequestException('person id not found');
}
// TODO add acl
switch ($request->getMethod()) {
case Request::METHOD_POST:
$participation = $accompanyingCours->addPerson($person);
break;
case Request::METHOD_DELETE:
$participation = $accompanyingCours->removePerson($person);
break;
default:
throw new BadRequestException("This method is not supported");
}
$errors = $this->validator->validate($accompanyingCourse);
if ($errors->count() > 0) {
// only format accepted
return $this->json($errors);
}
$this->getDoctrine()->getManager()->flush();
return $this->json($participation);
}
}