<commit_before><?php
namespace Coruja\TodoBundle\Controller;

use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\Annotations\Prefix;
use FOS\RestBundle\Controller\Annotations\NamePrefix;
use FOS\RestBundle\View\RouteRedirectView;
use FOS\RestBundle\View\View;
use FOS\Rest\Util\Codes as HttpCodes;

/**
 * @Prefix("todo/api")
 * @NamePrefix("todo_api_")
 */
class TodoRestController extends FOSRestController
{
    /**
     * @Rest\View()
     * @ApiDoc
     */
    public function getTodosAction()
    {
        $em = $this->get('doctrine')->getEntityManager();
        /* @var $em \Doctrine\ORM\EntityManager */
        $todos = $em->getRepository('CorujaTodoBundle:Todo')->findAll();
        return $todos;
    }

    /**
     * @Rest\View()
     * @ApiDoc
     * @param $id
     */
    public function getTodoAction($id)
    {
        $em = $this->get('doctrine')->getEntityManager();
        /* @var $em \Doctrine\ORM\EntityManager */
        $todo = $em->find('CorujaTodoBundle:Todo', $id);
        return $todo;
    }

    /**
     * put: man kennt die Ressource also bearbeiten
     * @Rest\View()
     * @ApiDoc
     */
    public function putTodoAction($id)
    {
        $data = $this->getRequest()->request;
        $em = $this->get('doctrine')->getEntityManager();
        /* @var $em \Doctrine\ORM\EntityManager */
        $todo = $em->find('CorujaTodoBundle:Todo', $id);
        $todo->setTitle($data->get('title'));
        $todo->setCompleted($data->get('completed'));
        $em->flush();

        return View::create(null, HttpCodes::HTTP_NO_CONTENT);
    }

    /**
     * neue ressourcen
     * @Rest\View()
     * @ApiDoc
     */
    public function postTodosAction()
    {
        $data = $this->getRequest()->request;
        $todo = new \Coruja\TodoBundle\Entity\Todo();
        $todo->setTitle($data->get('title'));
        $todo->setCompleted($data->get('completed'));

        $em = $this->get('doctrine')->getEntityManager();
        /* @var $em \Doctrine\ORM\EntityManager */
        $em->persist($todo);
        $em->flush();

        return RouteRedirectView::create('todo_api_get_todo', array('id' => $todo->getId()), HttpCodes::HTTP_CREATED);
    }


    /**
     * lösche ressourcen
     * @Rest\View(statusCode=204)
     * @ApiDoc
     */
    public function deleteTodoAction($id)
    {
        $em = $this->get('doctrine')->getEntityManager();
        /* @var $em \Doctrine\ORM\EntityManager */
        $em->remove($em->find('CorujaTodoBundle:Todo', $id));
        $em->flush();
    }
}<commit_msg>Returns 404 when todo entity is not found<commit_after><?php
namespace Coruja\TodoBundle\Controller;

use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\Annotations\Prefix;
use FOS\RestBundle\Controller\Annotations\NamePrefix;
use FOS\RestBundle\View\RouteRedirectView;
use FOS\RestBundle\View\View;
use FOS\Rest\Util\Codes as HttpCodes;

/**
 * @Prefix("todo/api")
 * @NamePrefix("todo_api_")
 */
class TodoRestController extends FOSRestController
{
    /**
     * @Rest\View()
     * @ApiDoc
     */
    public function getTodosAction()
    {
        $em = $this->get('doctrine')->getEntityManager();
        /* @var $em \Doctrine\ORM\EntityManager */
        $todos = $em->getRepository('CorujaTodoBundle:Todo')->findAll();
        return $todos;
    }

    /**
     * @Rest\View()
     * @ApiDoc
     * @param $id
     */
    public function getTodoAction($id)
    {
        $em = $this->get('doctrine')->getEntityManager();
        /* @var $em \Doctrine\ORM\EntityManager */
        $todo = $em->find('CorujaTodoBundle:Todo', $id);
        return $todo;
    }

    /**
     * Update known resource
     * @Rest\View()
     * @ApiDoc
     */
    public function putTodoAction($id)
    {
        $data = $this->getRequest()->request;
        $em = $this->get('doctrine')->getEntityManager();
        /* @var $em \Doctrine\ORM\EntityManager */
        $todo = $em->find('CorujaTodoBundle:Todo', $id);

        if ($todo !== NULL) {
            $todo->setTitle($data->get('title'));
            $todo->setCompleted($data->get('completed'));
            $em->flush();
            return View::create(null, HttpCodes::HTTP_NO_CONTENT);
        }
        return View::create(null, HttpCodes::HTTP_NOT_FOUND);
    }

    /**
     * Insert new resource
     * @Rest\View()
     * @ApiDoc
     */
    public function postTodosAction()
    {
        $data = $this->getRequest()->request;
        $todo = new \Coruja\TodoBundle\Entity\Todo();
        $todo->setTitle($data->get('title'));
        $todo->setCompleted($data->get('completed'));

        $em = $this->get('doctrine')->getEntityManager();
        /* @var $em \Doctrine\ORM\EntityManager */
        $em->persist($todo);
        $em->flush();

        return RouteRedirectView::create('todo_api_get_todo', array('id' => $todo->getId()), HttpCodes::HTTP_CREATED);
    }


    /**
     * Deletes resource
     * @Rest\View()
     * @ApiDoc
     */
    public function deleteTodoAction($id)
    {
        $em = $this->get('doctrine')->getEntityManager();
        /* @var $em \Doctrine\ORM\EntityManager */
        $todo = $em->find('CorujaTodoBundle:Todo', $id);
        if ($todo !== NULL) {
            $em->remove($todo);
            $em->flush();
            return View::create(null, HttpCodes::HTTP_NO_CONTENT);
        }
        return View::create(null, HttpCodes::HTTP_NOT_FOUND);
    }
}
{'fraction_non_alphanumeric': 0.17270788912579957, 'fraction_numerical': 0.0010660980810234541, 'mean_word_length': 2.6152858060372512, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6033472', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1861, 'n_words': 279}