<commit_before><?php
namespace MessengerBundle\Controller;

use FOS\RestBundle\Controller\Annotations\Get;
use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Controller\Annotations\RequestParam;
use FOS\RestBundle\Request\ParamFetcher;
use MessengerBundle\Entity\Conversation;
use MessengerBundle\Utils\Traits\GetManagersTrait;
use MessengerBundle\Utils\Traits\PopulateValueObjectsTrait;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use FOS\RestBundle\Controller\Annotations\RouteResource;
use FOS\RestBundle\Controller\FOSRestController;
use Symfony\Component\HttpFoundation\Request;
use UserBundle\Controller\LoginApiController;

/**
 * Class ConversationsController
 * @package MessengerBundle\Controller
 *
 * @RouteResource("Conversation")
 */
class ConversationsController extends FOSRestController
{
    use GetManagersTrait;
    use PopulateValueObjectsTrait;

    // Get

    /**
     * @ApiDoc(
     *  resource = true,
     *  description = "Returns all conversations of an user",
     *  statusCodes = {
     *      200 = "Returned when sucessful",
     *      404 = "Returned when no messages are found"
     *  }
     * )
     *
     * @Get("/get/{username}")
     *
     * @throws NotFoundHttpException
     */
    public function cgetAction($username)
    {
        $userRepository = $this->getUserRepository();

        $user = $userRepository->findOneByUsernameWithConversations($username);

        if (null === $user) {
            throw new NotFoundHttpException('The user provided does not exist');
        }

        /** @var Conversation[] $conversationsFromBase */
        $conversationsFromBase = $user->getConversations();

        if (empty($conversationsFromBase)) {
            throw new NotFoundHttpException('No message found');
        }

        $conversations = [];
        foreach($conversationsFromBase as $conversation) {
            $conversationValueObject = $this->populateConversationValueObject($conversation);

            $conversations[] = $conversationValueObject;
        }

        $view = $this->view($conversations);

        return $this->handleView($view);
    }

    // Post

    /**
     * @param ParamFetcher $paramFetcher
     * @param Request $request
     *
     * @return View
     * @throws \HttpInvalidParamException
     *
     * @Post("/new")
     *
     * @RequestParam(name="to", nullable=true, description="Message receiver")
     */
    public function postAction(ParamFetcher $paramFetcher, Request $request)
    {
        $em = $this->getManager();
        $user1 = LoginApiController::checkAuthentication($request, $em);

        $to = $paramFetcher->get('to');<commit_msg>Added missing ApiDoc for conversations<commit_after><?php
namespace MessengerBundle\Controller;

use FOS\RestBundle\Controller\Annotations\Get;
use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Controller\Annotations\RequestParam;
use FOS\RestBundle\Request\ParamFetcher;
use MessengerBundle\Entity\Conversation;
use MessengerBundle\Utils\Traits\GetManagersTrait;
use MessengerBundle\Utils\Traits\PopulateValueObjectsTrait;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use FOS\RestBundle\Controller\Annotations\RouteResource;
use FOS\RestBundle\Controller\FOSRestController;
use Symfony\Component\HttpFoundation\Request;
use UserBundle\Controller\LoginApiController;

/**
 * Class ConversationsController
 * @package MessengerBundle\Controller
 *
 * @RouteResource("Conversation")
 */
class ConversationsController extends FOSRestController
{
    use GetManagersTrait;
    use PopulateValueObjectsTrait;

    // Get

    /**
     * @ApiDoc(
     *  resource = true,
     *  description = "Returns all conversations of an user",
     *  statusCodes = {
     *      200 = "Returned when sucessful",
     *      404 = "Returned when no messages are found"
     *  }
     * )
     *
     * @Get("/get/{username}")
     *
     * @throws NotFoundHttpException
     */
    public function cgetAction($username)
    {
        $userRepository = $this->getUserRepository();

        $user = $userRepository->findOneByUsernameWithConversations($username);

        if (null === $user) {
            throw new NotFoundHttpException('The user provided does not exist');
        }

        /** @var Conversation[] $conversationsFromBase */
        $conversationsFromBase = $user->getConversations();

        if (empty($conversationsFromBase)) {
            throw new NotFoundHttpException('No message found');
        }

        $conversations = [];
        foreach($conversationsFromBase as $conversation) {
            $conversationValueObject = $this->populateConversationValueObject($conversation);

            $conversations[] = $conversationValueObject;
        }

        $view = $this->view($conversations);

        return $this->handleView($view);
    }

    // Post

    /**
     *
     * @ApiDoc(
     *  resource = true,
     *  description = "Create a new conversation NEED X-AUTH-TOKEN",
     *  statusCodes = {
     *      200 = "Returned when successful",
     *      400 = "Returned when data has errors",
     *      403 = "Returned when authentication failed"
     *  }
     * )
     *
     * @param ParamFetcher $paramFetcher
     * @param Request $request
     *
     * @return View
     * @throws \HttpInvalidParamException
     *
     * @Post("/new")
     *
     * @RequestParam(name="to", nullable=true, description="Message receiver")
     */
    public function postAction(ParamFetcher $paramFetcher, Request $request)
    {
        $em = $this->getManager();
        $user1 = LoginApiController::checkAuthentication($request, $em);

        $to = $paramFetcher->get('to');
{'fraction_non_alphanumeric': 0.11411411411411411, 'fraction_numerical': 0.004062886415827592, 'mean_word_length': 3.0587813620071684, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '5322995', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1595, 'n_words': 303}