<commit_before><?php

namespace Wallabag\ApiBundle\Controller;

use FOS\RestBundle\Controller\FOSRestController;
use Hateoas\Configuration\Route;
use Hateoas\Representation\Factory\PagerfantaFactory;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag;

class WallabagRestController extends FOSRestController
{
    private function validateAuthentication()
    {
        if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
            throw new AccessDeniedException();
        }
    }

    /**
     * Check if an entry exist by url.
     *
     * @ApiDoc(
     *       parameters={
     *          {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"}
     *       }
     * )
     *
     * @return JsonResponse
     */
    public function getEntriesExistsAction(Request $request)
    {
        $this->validateAuthentication();

        $url = $request->query->get('url', '');

        if (empty($url)) {
            throw $this->createAccessDeniedException('URL is empty?, logged user id: '.$user->getId());
        }

        $res = $this->getDoctrine()
            ->getRepository('WallabagCoreBundle:Entry')
            ->findByUrlAndUserId($url, $this->getUser()->getId());

        $exists = false === $res ? false : true;

        $json = $this->get('serializer')->serialize(['exists' => $exists], 'json');

        return (new JsonResponse())->setJson($json);
    }

    /**
     * Retrieve all entries. It could be filtered by many options.
     *<commit_msg>Fix exists API call<commit_after><?php

namespace Wallabag\ApiBundle\Controller;

use FOS\RestBundle\Controller\FOSRestController;
use Hateoas\Configuration\Route;
use Hateoas\Representation\Factory\PagerfantaFactory;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag;

class WallabagRestController extends FOSRestController
{
    private function validateAuthentication()
    {
        if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
            throw new AccessDeniedException();
        }
    }

    /**
     * Check if an entry exist by url.
     *
     * @ApiDoc(
     *       parameters={
     *          {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"}
     *       }
     * )
     *
     * @return JsonResponse
     */
    public function getEntriesExistsAction(Request $request)
    {
        $this->validateAuthentication();

        $url = $request->query->get('url', '');

        if (empty($url)) {
            throw $this->createAccessDeniedException('URL is empty?, logged user id: '.$this->getUser->getId());
        }

        $res = $this->getDoctrine()
            ->getRepository('WallabagCoreBundle:Entry')
            ->findByUrlAndUserId($url, $this->getUser()->getId());

        $exists = false === $res ? false : true;

        $json = $this->get('serializer')->serialize(['exists' => $exists], 'json');

        return (new JsonResponse())->setJson($json);
    }

    /**
     * Retrieve all entries. It could be filtered by many options.
     *
{'fraction_non_alphanumeric': 0.13908872901678657, 'fraction_numerical': 0.0, 'mean_word_length': 3.194413407821229, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '1370556', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1080, 'n_words': 207}