/** * @ApiDoc( * description="Edit response", * requirements={ * { * "name"="app_key", * "dataType"="String", * "requirement"="true", * "description"="Unique APP_KEY. For example: NACOFXYLPJGQERVBISKTWUHDZM." * } * }, * parameters={ * {"name"="name", "dataType"="string", "required"=true, "description"="Name of application"}, * {"name"="url", "dataType"="string", "required"=true, "description"="Path to application response"}, * {"name"="value", "dataType"="string", "required"=true, "description"="Value that endpoint should return"}, * {"name"="method", "dataType"="string", "required"=true, "description"="HTTP Methods. Allowed: GET, POST, PUT, DELETE"}, * {"name"="statusCode", "dataType"="string", "required"=true, "description"="HTTP Status Code."} * }) * ) * @param Request $request * @param \JSONMockBundle\Entity\Response $response * @param Application $application * @return mixed|Response * @ParamConverter("response", class="JSONMockBundle\Entity\Response", options={"id" = "id"}) * @ParamConverter("application", class="JSONMockBundle\Entity\Application", options={"mapping":{"app_key" = "appKey"}}) */ public function editResponseAction(Request $request, \JSONMockBundle\Entity\Response $response = null, Application $application = null) { if ($application == null) { return JsonResponse::create(array('status' => 'Error', 'message' => 'APP_KEY not match'), 404); } if ($response == null || !$application->getResponses()->contains($response)) { return JsonResponse::create(array('status' => 'Error', 'message' => 'Response not found'), 404); } $form = $this->get('form.factory')->create(new ResponseType(), $response); $formData = json_decode($request->getContent(), true); $formData['application'] = $application->getId(); $form->submit($formData); if (!$form->isValid()) { return JsonResponse::create(array('status' => 'Error', 'message' => array_values($this->getErrorMessages($form))[0]), 400); } $em = $this->getDoctrine()->getManager(); $em->persist($response); $em->flush(); return $this->success($response, 'application', Response::HTTP_OK, array('Default', 'Details')); }