<commit_before><?php

namespace App\Controller\Api;

use App\Entity\Picture;
use App\Repository\PictureRepository;
use App\Repository\TagRepository;
use App\Service\Path;
use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class PictureController extends AbstractController
{
	#[Route(path: '/api/picture/untagged', name: 'api_untagged_picture', methods: ['GET'])]
	public function viewUntaggedAction(PictureRepository $pictureRepository, NormalizerInterface $normalizer): JsonResponse
	{
		$picture = $pictureRepository->getPictureWithoutTags();

		return new JsonResponse($normalizer->normalize($picture, context: ['groups' => ['export']]));
	}

	#[Route(path: '/api/picture/view/{picture}', name:'api_view_picture', methods: ['GET'])]
	public function viewPicture(Picture $picture, Path $path, EntityManagerInterface $entityManager, Security $security): Response
	{
		$picture->incrementViews($security->getUser());
		$entityManager->flush();

		return new Response(
			file_get_contents($path->getPictureFullpath($picture)) ?: '',
			Response::HTTP_OK,
			['Content-Type' => $picture->getMime()]
		);
	}

	#[Route(path: '/api/picture/{id}/tag', name: 'api_tag_picture', methods: ['POST'])]
	#[ParamConverter('picture', Picture::class)]
	public function tagPicture(EntityManagerInterface $entityManager, TagRepository $tagRepository, Picture $picture, Request $request): JsonResponse
	{
		$tags = $tagRepository->findBy(['id' => json_decode($request->getContent(), true)['tags']]);

		if (empty($tags)) {
			return new JsonResponse(null, Response::HTTP_BAD_REQUEST);
		}

		foreach ($tags as $tag) {
			$picture->addTag($tag);
		}

		$entityManager->flush();

		return new JsonResponse(null, Response::HTTP_CREATED);
	}
}
<commit_msg>Add route for single picture<commit_after><?php

namespace App\Controller\Api;

use App\Entity\Picture;
use App\Repository\PictureRepository;
use App\Repository\TagRepository;
use App\Service\Path;
use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class PictureController extends AbstractController
{
	#[Route(path: '/api/picture/untagged', name: 'api_untagged_picture', methods: ['GET'])]
	public function viewUntaggedAction(PictureRepository $pictureRepository, NormalizerInterface $normalizer): JsonResponse
	{
		$picture = $pictureRepository->getPictureWithoutTags();

		return new JsonResponse($normalizer->normalize($picture, context: ['groups' => ['export']]));
	}

	#[Route(path: '/api/picture/view/{picture}', name:'api_view_picture', methods: ['GET'])]
	public function viewPicture(Picture $picture, Path $path, EntityManagerInterface $entityManager, Security $security): Response
	{
		$picture->incrementViews($security->getUser());
		$entityManager->flush();

		return new Response(
			file_get_contents($path->getPictureFullpath($picture)) ?: '',
			Response::HTTP_OK,
			['Content-Type' => $picture->getMime()]
		);
	}

	#[Route(path: '/api/picture/{picture}', name: 'api_picture', methods: ['GET'])]
	public function getPicture(Picture $picture, NormalizerInterface $normalizer, Security $security, EntityManagerInterface $entityManager): JsonResponse
	{
		$picture->incrementViews($security->getUser());
		$entityManager->flush();

		return new JsonResponse($normalizer->normalizer($picture, context: ['groups' => ['export']]));
	}

	#[Route(path: '/api/picture/{id}/tag', name: 'api_tag_picture', methods: ['POST'])]
	#[ParamConverter('picture', Picture::class)]
	public function tagPicture(EntityManagerInterface $entityManager, TagRepository $tagRepository, Picture $picture, Request $request): JsonResponse
	{
		$tags = $tagRepository->findBy(['id' => json_decode($request->getContent(), true)['tags']]);

		if (empty($tags)) {
			return new JsonResponse(null, Response::HTTP_BAD_REQUEST);
		}

		foreach ($tags as $tag) {
			$picture->addTag($tag);
		}

		$entityManager->flush();

		return new JsonResponse(null, Response::HTTP_CREATED);
	}
}

{'fraction_non_alphanumeric': 0.14726890756302521, 'fraction_numerical': 0.0, 'mean_word_length': 7.124573378839591, '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': '3420225', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1353, 'n_words': 265}