<commit_before><?php

namespace LBSS\MyAngularApiBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use LBSS\MyAngularApiBundle\Entity\User;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

use FOS\RestBundle\Controller\Annotations as Rest;
/*use FOS\RestBundle\View\ViewHandler;
use FOS\RestBundle\View\View;
*/
use LBSS\MyAngularApiBundle\Form\UserType;


class UserController extends Controller
{
    /**
     * @Rest\View()
     * @Rest\Get("/users")
     */  
    public function getUsersAction(Request $request)
    {   
    	$users = $this->getDoctrine()->getRepository('LBSSMyAngularApiBundle:User')->findAll();

        return $users;

    }
    
    /**
     * @Rest\View()
     * @Rest\Get("/user/{id}")
     */
    public function getUserAction(User $user)
    {   
    	$user = $this->getDoctrine()->getRepository('LBSSMyAngularApiBundle:User')->find($user);

         return $user;

    }

    /**
     * @Rest\View(statusCode=Response::HTTP_CREATED)
     * @Rest\Post("/users")
     */
    public function postUsersAction(Request $request)
    { 
        /*$userName = "Da vinci";
        $email = "<EMAIL>" ;*/

        $user = new User();
        $form = $this->createForm(UserType::class, $user);

        $form->submit($request->request->all());
        /*$user->setUsername($request->get('username'))
            ->setEmail($request->get('email'));*/
       /* $user->setUsername($userName)
            ->setEmail($email);*/

         if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($user);
            $em->flush();
            return $user;
        } else {
            return $form;
        }

    }

    /**
     * @Rest\View(statusCode=Response::HTTP_NO_CONTENT)
     * @Rest\Delete("/users/{id}")
     */
    public function removeUserAction(User $user)
    {
        $user = $this->getDoctrine()->getRepository('LBSSMyAngularApiBundle:User')->find($user);
        $em = $this->getDoctrine()->getManager();

        if ($place) {
            $em->remove($user);
            $em->flush();
        }

    }



   
}<commit_msg>Add method PUT and method Patch<commit_after><?php

namespace LBSS\MyAngularApiBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use LBSS\MyAngularApiBundle\Entity\User;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

use FOS\RestBundle\Controller\Annotations as Rest;
/*use FOS\RestBundle\View\ViewHandler;
use FOS\RestBundle\View\View;
*/
use LBSS\MyAngularApiBundle\Form\UserType;


class UserController extends Controller
{
    /**
     * @Rest\View()
     * @Rest\Get("/users")
     */  
    public function getUsersAction(Request $request)
    {   
    	$users = $this->getDoctrine()->getRepository('LBSSMyAngularApiBundle:User')->findAll();

        return $users;

    }
    
    /**
     * @Rest\View()
     * @Rest\Get("/user/{id}")
     */
    public function getUserAction(User $user)
    {   
    	$user = $this->getDoctrine()->getRepository('LBSSMyAngularApiBundle:User')->find($user);

         return $user;

    }

    /**
     * @Rest\View(statusCode=Response::HTTP_CREATED)
     * @Rest\Post("/users")
     */
    public function postUsersAction(Request $request)
    { 
        /*$userName = "Da vinci";
        $email = "<EMAIL>" ;*/

        $user = new User();
        $form = $this->createForm(UserType::class, $user);

        $form->submit($request->request->all());
        /*$user->setUsername($request->get('username'))
            ->setEmail($request->get('email'));*/
       /* $user->setUsername($userName)
            ->setEmail($email);*/

         if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($user);
            $em->flush();
            return $user;
        } else {
            return $form;
        }

    }

    /**
     * @Rest\View(statusCode=Response::HTTP_NO_CONTENT)
     * @Rest\Delete("/users/{id}")
     */
    public function removeUserAction(User $user)
    {
        $user = $this->getDoctrine()->getRepository('LBSSMyAngularApiBundle:User')->find($user);
        $em = $this->getDoctrine()->getManager();

        if ($place) {
            $em->remove($user);
            $em->flush();
        }

    }
    
    /**
     * @Rest\View()
     * @Rest\Put("/user/{id}")
     */
    public function putUserAction(Request $request)
    {
        $user = $this->getDoctrine()->getRepository('LBSSMyAngularApiBundle:User')
                ->find($request->get('id')); 
       
        if (empty($user)) {
            return new JsonResponse(['message' => 'User not found'], Response::HTTP_NOT_FOUND);
        }

        $form = $this->createForm(UserType::class, $user);

        $form->submit($request->request->all());

        if ($form->isValid()) {
            $em = $this->get('doctrine.orm.entity_manager');
            
            $em->flush();
            return $user;
        } else {
            return $form;
        }
    }

    /**
     * @Rest\View()
     * @Rest\Patch("/user/{id}")
     */
    public function patchPlaceAction(Request $request)
    {
        $user = $this->getDoctrine()->getRepository('LBSSMyAngularApiBundle:User')
                ->find($request->get('id')); 

        if (empty($user)) {
            return \FOS\RestBundle\View\View::create(['message' => 'user not found !!!'], Response::HTTP_NOT_FOUND);
        }

        $form = $this->createForm(UserType::class, $user);

         // Le paramètre false dit à Symfony de garder les valeurs dans notre 
         // entité si l'utilisateur n'en fournit pas une dans sa requête
        $form->submit($request->request->all(), false);

        if ($form->isValid()) {
            $em = $this->get('doctrine.orm.entity_manager');            
            $em->flush();
            return $user;
        } else {
            return $form;
        }
    }



   
}
{'fraction_non_alphanumeric': 0.16925847110820103, 'fraction_numerical': 0.0, 'mean_word_length': 2.299136069114471, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 85, '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': '4227212', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1841, 'n_words': 279}