D
D
d999992021-03-15 12:14:37
symfony
d99999, 2021-03-15 12:14:37

Do I need to transfer the action that I work with manipulate with JSON and return it on an AJAX request to be transferred to the API?

For example, the code that is responsible for changing the status and returns the result in JSON. Should such an action be moved to the API folder?

/**
     * @Route ("/update-status/{url}", name="update_status", methods={"POST"})
     * @param Proposition $proposition
     * @param Request $request
     * @return Response
     */
    public function updateStatus(Proposition $proposition, Request $request): Response
    {
        $status = $request->get('status', null);

        if (!$proposition || !$status) {
            return new JsonResponse([
                'success' => false,
                'message' => 'id or status cannot be empty',
            ]);
        }
        $this->propositionService->updateStatus($proposition, Proposition::STATUSES[$status], $this->getUser());

        return new JsonResponse(['success' => true]);
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question