<commit_before><?php


namespace Bolt\Extension\Bolt\JsonApi\Action;

use Bolt\Extension\Bolt\JsonApi\Converter\Parameter\ParameterCollection;
use Bolt\Extension\Bolt\JsonApi\Exception\ApiNotFoundException;
use Bolt\Extension\Bolt\JsonApi\Response\ApiResponse;
use Bolt\Storage\Query\QueryResultset;
use Symfony\Component\HttpFoundation\Request;

/**
 * Class SingleAction
 * @package Bolt\Extension\Bolt\JsonApi\Action
 */
class SingleAction extends FetchAction
{
    /**
     * @param $contentType
     * @param $slug
     * @param $relatedContentType
     * @param Request $request
     * @param ParameterCollection $parameters
     * @return array|ApiResponse
     */
    public function handle($contentType, $slug, $relatedContentType, Request $request, ParameterCollection $parameters)
    {
        $queryParameters = array_merge($parameters->getQueryParameters(), ['returnsingle' => true, 'id' => $slug]);

        /** @var QueryResultset $results */
        $results = $this->query->getContent($contentType, $queryParameters);

        $this->throwErrorOnNoResults($results, "No [$contentType] found with id/slug: [$slug].");

        if ($relatedContentType !== null) {
            $relatedItemsTotal = $results->getRelation()->getField($relatedContentType)->count();
            if ($relatedItemsTotal <= 0) {
                throw new ApiNotFoundException(
                    "No related items of type [$relatedContentType] found for [$contentType] with id/slug: [$slug]."
                );
            }

            //$allFields = $this->APIHelper->getAllFieldNames($relatedContentType);
            //$fields = $this->APIHelper->getFields($relatedContentType, $allFields, 'list-fields');
            // @todo item-fields INSTEAD of list-items
            $fields = $parameters->get('fields')->getFields();

            foreach ($results->relation[$relatedContentType] as $item) {
                $items[] = $this->parser->parseItem($item, $fields);
            }
<commit_msg>Fixed minor issue where slugs were not being found in the url<commit_after><?php


namespace Bolt\Extension\Bolt\JsonApi\Action;

use Bolt\Extension\Bolt\JsonApi\Converter\Parameter\ParameterCollection;
use Bolt\Extension\Bolt\JsonApi\Exception\ApiNotFoundException;
use Bolt\Extension\Bolt\JsonApi\Response\ApiResponse;
use Bolt\Storage\Query\QueryResultset;
use Symfony\Component\HttpFoundation\Request;

/**
 * Class SingleAction
 * @package Bolt\Extension\Bolt\JsonApi\Action
 */
class SingleAction extends FetchAction
{
    /**
     * @param $contentType
     * @param $slug
     * @param $relatedContentType
     * @param Request $request
     * @param ParameterCollection $parameters
     * @return array|ApiResponse
     */
    public function handle($contentType, $slug, $relatedContentType, Request $request, ParameterCollection $parameters)
    {
        $additionalParameters = ['returnsingle' => true];

        if (is_numeric($slug)) {
            $additionalParameters['id'] = $slug;
        } else {
            $additionalParameters['slug'] = $slug;
        }

        $queryParameters = array_merge($parameters->getQueryParameters(), $additionalParameters);

        /** @var QueryResultset $results */
        $results = $this->query->getContent($contentType, $queryParameters);

        $this->throwErrorOnNoResults($results, "No [$contentType] found with id/slug: [$slug].");

        if ($relatedContentType !== null) {
            $relatedItemsTotal = $results->getRelation()->getField($relatedContentType)->count();
            if ($relatedItemsTotal <= 0) {
                throw new ApiNotFoundException(
                    "No related items of type [$relatedContentType] found for [$contentType] with id/slug: [$slug]."
                );
            }

            //$allFields = $this->APIHelper->getAllFieldNames($relatedContentType);
            //$fields = $this->APIHelper->getFields($relatedContentType, $allFields, 'list-fields');
            // @todo item-fields INSTEAD of list-items
            $fields = $parameters->get('fields')->getFields();

            foreach ($results->relation[$relatedContentType] as $item) {
                $items[] = $this->parser->parseItem($item, $fields);
            }

{'fraction_non_alphanumeric': 0.13391591875295228, 'fraction_numerical': 0.0004723665564478035, 'mean_word_length': 3.0604026845637584, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 38, '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': '1654841', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1131, 'n_words': 230}