for each selected, loop for post participation, then get response and commit state

This commit is contained in:
2021-05-04 22:30:22 +02:00
parent 120e7cade5
commit 30f490959b
6 changed files with 78 additions and 49 deletions

View File

@@ -121,7 +121,7 @@ class AccompanyingCourseController extends Controller
* @Route(
* "/{_locale}/person/api/1.0/accompanying-course/{accompanying_period_id}/participation.{_format}",
* name="chill_person_accompanying_course_api_add_participation",
* methods={"POST"},
* methods={"POST","DELETE"},
* format="json",
* requirements={
* "_format": "json",
@@ -129,7 +129,7 @@ class AccompanyingCourseController extends Controller
* )
* @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"})
*/
public function addParticipationAPI(Request $request, AccompanyingPeriod $accompanyingCourse, $_format): Response
public function participationAPI(Request $request, AccompanyingPeriod $accompanyingCourse, $_format): Response
{
switch ($_format) {
case 'json':
@@ -146,7 +146,9 @@ class AccompanyingCourseController extends Controller
}
// TODO add acl
$accompanyingCourse->addPerson($person);
$participation = ($request->getMethod() === 'POST') ?
$accompanyingCourse->addPerson($person) : $accompanyingCourse->removePerson($person);
$errors = $this->validator->validate($accompanyingCourse);
if ($errors->count() > 0) {
@@ -156,6 +158,6 @@ class AccompanyingCourseController extends Controller
$this->getDoctrine()->getManager()->flush();
return new JsonResponse();
return $this->json($participation);
}
}