<commit_before><?php

namespace Demofony2\AppBundle\Controller\Api;

use Demofony2\AppBundle\Entity\Proposal;
use Demofony2\AppBundle\Entity\ProposalAnswer;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;

/**
 * ProposalController.
 *
 * @Rest\NamePrefix("api_")
 */
class ProposalController extends FOSRestController
{
    /**
     * Returns proposal.
     *
     * @param Proposal $proposal
     * @ApiDoc(
     *                           section="Proposal",
     *                           resource=true,
     *                           description="Get proposal",
     *                           statusCodes={
     *                           200="Returned when successful",
     *                           404={
     *                           "Returned when proposal not found",
     *                           }
     *                           },
     *                           requirements={
     *                           {
     *                           "name"="id",
     *                           "dataType"="integer",
     *                           "requirement"="\d+",
     *                           "description"="Proposal id"
     *                           }
     *                           }
     *                           )
     * @ParamConverter("proposal", class="Demofony2AppBundle:Proposal")
     * @Rest\Get("/proposals/{id}")
     * @Rest\View(serializerGroups={"detail"})
     * @Security("is_granted('read', proposal)")
     *
     * @return Proposal
     */
    public function getProposalAction(Proposal $proposal)
    {
        return $proposal;
    }

    /**
     * Vote proposal answer.
     *
     * @param Request        $request
     * @param Proposal       $proposal
     * @param ProposalAnswer $proposalAnswer
     * @ApiDoc(
     *                                       section="Proposal",
     *                                       resource=true,
     *                                       description="Vote proposal answer",
     *                                       statusCodes={
     *                                       201="Returned when successful",
     *                                       400={
     *                                       "Returned when proposal not found",
     *                                       "Returned when answer not found",
     *                                       "Returned when answer not belongs to proposal",
     *                                       },
     *                                       401={
     *                                       "Returned when user is not logged"
     *                                       },
     *                                       500={
     *                                       "Returned when debate is not open",
     *                                       }
     *                                       },
     *                                       input="Demofony2\AppBundle\Form\Type\Api\VoteType",
     *
     * )
     * @Rest\Post("/proposals/{id}/answers/{answer_id}/vote")
     * @ParamConverter("proposal", class="Demofony2AppBundle:Proposal")
     * @ParamConverter("proposalAnswer", class="Demofony2AppBundle:ProposalAnswer", options={"id" = "answer_id"})
     * @Rest\View(serializerGroups={"detail"}, statusCode=201)
     * @Security("is_granted('write', proposal) && has_role('ROLE_USER')")
     *
     * @return \FOS\RestBundle\View\View
     */
    public function postProposalAnswersVoteAction(Request $request, Proposal $proposal, ProposalAnswer $proposalAnswer)
    {
        $result = $this->getProposalManager()->postVote(
            $proposal,
            $proposalAnswer,
            $this->getUser(),
            $request
        );

        return ['vote' => $result, 'votes_count' => $proposalAnswer->getVotesCount()];
    }

    /**
     * Edit a Vote.
     *
     * @param Request        $request
     * @param Proposal       $proposal
     * @param ProposalAnswer $proposalAnswer
     * @ApiDoc(
     *                                       section="Proposal",
     *                                       resource=true,
     *                                       description="Edit a vote",
     *                                       statusCodes={
     *                                       204="Returned when successful",
     *                                       400={
     *                                       "Returned when proposal not found",
     *                                       "Returned when vote not found",
     *                                       "Returned when vote not belongs to proposal answer",
     *                                       "Returned when proposal answer not belongs to proposal",
     *                                       },
     *                                       401={
     *                                       "Returned when user is not logged",
     *                                       "Returned vote not belongs to user logged",
     *                                       },
     *                                       500={
     *                                       "Returned when debate is not open",
     *                                       }
     *                                       },
     *                                       input="Demofony2\AppBundle\Form\Type\Api\VoteType",
     *
     * )
     * @Rest\Put("/proposals/{id}/answers/{answer_id}/vote")
     * @ParamConverter("proposal", class="Demofony2AppBundle:Proposal")
     * @ParamConverter("proposalAnswer", class="Demofony2AppBundle:ProposalAnswer", options={"id" = "answer_id"})
     * @Rest\View(statusCode=204)
     * @Security("is_granted('write', proposal) && has_role('ROLE_USER')")
     *
     * @return \FOS\RestBundle\View\View
     */
    public function putProposalAnswersVoteAction(Request $request, Proposal $proposal, ProposalAnswer $proposalAnswer)
    {
        $result = $this->getProposalManager()->editVote(
            $proposal,
            $proposalAnswer,
            $this->getUser(),
            $request
        );

        return $result;
    }

    /**
     * delete a Vote.
     *
     * @param Proposal       $proposal
     * @param ProposalAnswer $proposalAnswer
     * @ApiDoc(
     *                                       section="Proposal",
     *                                       resource=true,
     *                                       description="Delete vote",
     *                                       statusCodes={
     *                                       204="Returned when successful",
     *                                       400={
     *                                       "Returned when proposal not found",
     *                                       "Returned when proposal answer not belongs to process participation",
     *                                       "Returned when proposal answer not found",
     *                                       "Returned when vote not found",
     *                                       "Returned when vote not belongs to proposal answer",
     *                                       },
     *                                       401={
     *                                       "Returned when user is not logged",
     *                                       "Returned vote not belongs to user logged",
     *                                       },
     *                                       500={
     *                                       "Returned when debate is not open",
     *                                       }
     *                                       },
     *
     * )
     * @Rest\Delete("/proposals/{id}/answers/{answer_id}/vote")
     * @ParamConverter("proposal", class="Demofony2AppBundle:Proposal")
     * @ParamConverter("proposalAnswer", class="Demofony2AppBundle:ProposalAnswer", options={"id" = "answer_id"})
     * @Rest\View(statusCode=204)
     * @Security("is_granted('write', proposal) && has_role('ROLE_USER')")
     *
     * @return \FOS\RestBundle\View\View
     */
    public function deleteProposalAnswersVoteAction(Proposal $proposal, ProposalAnswer $proposalAnswer)
    {
        $result = $this->getProposalManager()->deleteVote(
            $proposal,
            $proposalAnswer,
            $this->getUser()
        );

        return $result;
    }

    protected function getProposalManager()
    {
        return $this->get('app.proposal');
    }
}
<commit_msg>improve digues la teva client-side features 7 - fix it?<commit_after><?php

namespace Demofony2\AppBundle\Controller\Api;

use Demofony2\AppBundle\Entity\Proposal;
use Demofony2\AppBundle\Entity\ProposalAnswer;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;

/**
 * ProposalController.
 *
 * @Rest\NamePrefix("api_")
 */
class ProposalController extends FOSRestController
{
    /**
     * Returns proposal.
     *
     * @param Proposal $proposal
     * @ApiDoc(
     *                           section="Proposal",
     *                           resource=true,
     *                           description="Get proposal",
     *                           statusCodes={
     *                           200="Returned when successful",
     *                           404={
     *                           "Returned when proposal not found",
     *                           }
     *                           },
     *                           requirements={
     *                           {
     *                           "name"="id",
     *                           "dataType"="integer",
     *                           "requirement"="\d+",
     *                           "description"="Proposal id"
     *                           }
     *                           }
     *                           )
     * @ParamConverter("proposal", class="Demofony2AppBundle:Proposal")
     * @Rest\Get("/proposals/{id}")
     * @Rest\View(serializerGroups={"detail"})
     *
     * @return Proposal
     */
    public function getProposalAction(Proposal $proposal)
    {
        return $proposal;
    }

    /**
     * Vote proposal answer.
     *
     * @param Request        $request
     * @param Proposal       $proposal
     * @param ProposalAnswer $proposalAnswer
     * @ApiDoc(
     *                                       section="Proposal",
     *                                       resource=true,
     *                                       description="Vote proposal answer",
     *                                       statusCodes={
     *                                       201="Returned when successful",
     *                                       400={
     *                                       "Returned when proposal not found",
     *                                       "Returned when answer not found",
     *                                       "Returned when answer not belongs to proposal",
     *                                       },
     *                                       401={
     *                                       "Returned when user is not logged"
     *                                       },
     *                                       500={
     *                                       "Returned when debate is not open",
     *                                       }
     *                                       },
     *                                       input="Demofony2\AppBundle\Form\Type\Api\VoteType",
     *
     * )
     * @Rest\Post("/proposals/{id}/answers/{answer_id}/vote")
     * @ParamConverter("proposal", class="Demofony2AppBundle:Proposal")
     * @ParamConverter("proposalAnswer", class="Demofony2AppBundle:ProposalAnswer", options={"id" = "answer_id"})
     * @Rest\View(serializerGroups={"detail"}, statusCode=201)
     * @Security("has_role('ROLE_USER')")
     *
     * @return \FOS\RestBundle\View\View
     */
    public function postProposalAnswersVoteAction(Request $request, Proposal $proposal, ProposalAnswer $proposalAnswer)
    {
        $result = $this->getProposalManager()->postVote(
            $proposal,
            $proposalAnswer,
            $this->getUser(),
            $request
        );

        return ['vote' => $result, 'votes_count' => $proposalAnswer->getVotesCount()];
    }

    /**
     * Edit a Vote.
     *
     * @param Request        $request
     * @param Proposal       $proposal
     * @param ProposalAnswer $proposalAnswer
     * @ApiDoc(
     *                                       section="Proposal",
     *                                       resource=true,
     *                                       description="Edit a vote",
     *                                       statusCodes={
     *                                       204="Returned when successful",
     *                                       400={
     *                                       "Returned when proposal not found",
     *                                       "Returned when vote not found",
     *                                       "Returned when vote not belongs to proposal answer",
     *                                       "Returned when proposal answer not belongs to proposal",
     *                                       },
     *                                       401={
     *                                       "Returned when user is not logged",
     *                                       "Returned vote not belongs to user logged",
     *                                       },
     *                                       500={
     *                                       "Returned when debate is not open",
     *                                       }
     *                                       },
     *                                       input="Demofony2\AppBundle\Form\Type\Api\VoteType",
     *
     * )
     * @Rest\Put("/proposals/{id}/answers/{answer_id}/vote")
     * @ParamConverter("proposal", class="Demofony2AppBundle:Proposal")
     * @ParamConverter("proposalAnswer", class="Demofony2AppBundle:ProposalAnswer", options={"id" = "answer_id"})
     * @Rest\View(statusCode=204)
     * @Security("has_role('ROLE_USER')")
     *
     * @return \FOS\RestBundle\View\View
     */
    public function putProposalAnswersVoteAction(Request $request, Proposal $proposal, ProposalAnswer $proposalAnswer)
    {
        $result = $this->getProposalManager()->editVote(
            $proposal,
            $proposalAnswer,
            $this->getUser(),
            $request
        );

        return $result;
    }

    /**
     * delete a Vote.
     *
     * @param Proposal       $proposal
     * @param ProposalAnswer $proposalAnswer
     * @ApiDoc(
     *                                       section="Proposal",
     *                                       resource=true,
     *                                       description="Delete vote",
     *                                       statusCodes={
     *                                       204="Returned when successful",
     *                                       400={
     *                                       "Returned when proposal not found",
     *                                       "Returned when proposal answer not belongs to process participation",
     *                                       "Returned when proposal answer not found",
     *                                       "Returned when vote not found",
     *                                       "Returned when vote not belongs to proposal answer",
     *                                       },
     *                                       401={
     *                                       "Returned when user is not logged",
     *                                       "Returned vote not belongs to user logged",
     *                                       },
     *                                       500={
     *                                       "Returned when debate is not open",
     *                                       }
     *                                       },
     *
     * )
     * @Rest\Delete("/proposals/{id}/answers/{answer_id}/vote")
     * @ParamConverter("proposal", class="Demofony2AppBundle:Proposal")
     * @ParamConverter("proposalAnswer", class="Demofony2AppBundle:ProposalAnswer", options={"id" = "answer_id"})
     * @Rest\View(statusCode=204)
     * @Security("has_role('ROLE_USER')")
     *
     * @return \FOS\RestBundle\View\View
     */
    public function deleteProposalAnswersVoteAction(Proposal $proposal, ProposalAnswer $proposalAnswer)
    {
        $result = $this->getProposalManager()->deleteVote(
            $proposal,
            $proposalAnswer,
            $this->getUser()
        );

        return $result;
    }

    protected function getProposalManager()
    {
        return $this->get('app.proposal');
    }
}

{'fraction_non_alphanumeric': 0.09594455264062321, 'fraction_numerical': 0.007274601901706954, 'mean_word_length': 1.0134932533733134, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 256, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2402686', 'n_tokens_mistral': 4254, 'n_tokens_neox': 3992, 'n_words': 718}