<commit_before><?php

namespace App\Http\Controllers;

use App\Contracts\WineHandler;
use App\Exceptions\InvalidCompetitionStateException;
use App\Exceptions\ValidationException;
use App\MasterData\Competition;
use App\Wine;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use function response;
use function route;

class WineApiController extends BaseController {

	/** @var WineHandler */
	private $wineHandler;

	public function __construct(WineHandler $wineHandler) {
		$this->wineHandler = $wineHandler;
	}

	/**
	 * @return Response
	 */
	public function index(Request $request) {
		$competitionId = $request->get('competition_id');
		$competition = Competition::find($competitionId);
		if (is_null($competitionId)) {
			return response()->json([], 404);
		}

		$wines = $this->wineHandler->getUsersWines(Auth::user(), $competition);
		$wines->setPath(route('wines.index', [
			'competition_id' => $competitionId,
		]));

		return response()->json($wines->toJson());
	}

	public function update(Wine $wines, Request $request) {
		$this->authorize('update-wine', $wines);

		try {
			$oldData = $wines->toArray();
			$data = array_merge($oldData,
				[
				'kdb' => $request->get('kdb'),
				'sosi' => $request->get('sosi'),
				'excluded' => $request->get('excluded'),
				'chosen' => $request->get('chosen'),
			]);
			return $this->wineHandler->update($wines, $data);
		} catch (ValidationException $ex) {
			return response()->json(['errors' => $ex->getErrors()], 412);
		} catch (InvalidCompetitionStateException $ex) {
			return response()->json(['error' => $ex->getMessage()], 400);
		}
	}<commit_msg>return proper json and not a string<commit_after><?php

namespace App\Http\Controllers;

use App\Contracts\WineHandler;
use App\Exceptions\InvalidCompetitionStateException;
use App\Exceptions\ValidationException;
use App\MasterData\Competition;
use App\Wine;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use function response;
use function route;

class WineApiController extends BaseController {

	/** @var WineHandler */
	private $wineHandler;

	public function __construct(WineHandler $wineHandler) {
		$this->wineHandler = $wineHandler;
	}

	/**
	 * @return Response
	 */
	public function index(Request $request) {
		$competitionId = $request->get('competition_id');
		$competition = Competition::find($competitionId);
		if (is_null($competitionId)) {
			return response()->json([], 404);
		}

		$wines = $this->wineHandler->getUsersWines(Auth::user(), $competition);
		$wines->setPath(route('wines.index', [
			'competition_id' => $competitionId,
		]));

		return response()->json($wines);
	}

	public function update(Wine $wines, Request $request) {
		$this->authorize('update-wine', $wines);

		try {
			$oldData = $wines->toArray();
			$data = array_merge($oldData,
				[
				'kdb' => $request->get('kdb'),
				'sosi' => $request->get('sosi'),
				'excluded' => $request->get('excluded'),
				'chosen' => $request->get('chosen'),
			]);
			return $this->wineHandler->update($wines, $data);
		} catch (ValidationException $ex) {
			return response()->json(['errors' => $ex->getErrors()], 412);
		} catch (InvalidCompetitionStateException $ex) {
			return response()->json(['error' => $ex->getMessage()], 400);
		}
	}
{'fraction_non_alphanumeric': 0.17446043165467626, 'fraction_numerical': 0.00539568345323741, 'mean_word_length': 5.001798561151079, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 56, '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': '7577624', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1076, 'n_words': 206}