<commit_before><?php

namespace Cinematics\Controllers;

use Cinematics\DatabaseProvider;
use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class AjaxController
{
    private $model;
    private $router;

    function __construct(ControllerCollection $router, DatabaseProvider $model)
    {
        $this->model = $model;
        $this->router = $router;
        $this->initRoutes();
    }

    /**
     * @return ControllerCollection
     */
    public function getRouter() {
        return $this->router;
    }

    private function initRoutes()
    {
        $this->router->post('/', function() {
            return json_encode([
                'Api Version' => '0.0.2',
                'Author' => '<NAME>'
            ]);
        });

        $this->router->post('/add/movie', function(Request $request) {
            $data = json_decode(urldecode($request->getQueryString()), true);
            return new JsonResponse(['what' => $this->model->addMovie($data)]);
        });

        $this->router->post('/add/seance', function(Request $request) {
            $data = json_decode(urldecode($request->getQueryString()), true);
            return new JsonResponse(['what' => $this->model->addSeance($data)]);
        });

        $this->router->post('/add/ticket', function(Request $request) {
            $data = json_decode(urldecode($request->getQueryString()), true);
            return new JsonResponse(['what' => $this->model->sellTicket($data)]);
        });

        $this->router->post('/json', function(Request $request) {
            $arr = json_decode(urldecode($request->getQueryString()), true);
            return new JsonResponse($arr);
        });

        $this->router->post('/halls', function() {
            return new JsonResponse($this->model->getHallsInfo(), JSON_NUMERIC_CHECK);
        });

        $this->router->post('/halls/{name}', function($name) {
            return new JsonResponse($this->model->getHallsInfo($name), JSON_NUMERIC_CHECK);
        });

        $this->router->post('/seances/{id}', function($id) {
            return new JsonResponse($this->model->getSeanceInfo($id), JSON_NUMERIC_CHECK);
        });

        $this->router->post('/seances/{from}/{to}', function($from, $to) {
            return new JsonResponse($this->model->getSeancesBetweenDates($from, $to), JSON_NUMERIC_CHECK);
        });

        $this->router->post('/movies', function() {
            return new JsonResponse($this->model->getMovies());
        });
    }
}<commit_msg>fixed controllers to REST<commit_after><?php

namespace Cinematics\Controllers;

use Cinematics\DatabaseProvider;
use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class AjaxController
{
    private $model;
    private $router;

    function __construct(ControllerCollection $router, DatabaseProvider $model)
    {
        $this->model = $model;
        $this->router = $router;
        $this->initRoutes();
    }

    /**
     * @return ControllerCollection
     */
    public function getRouter() {
        return $this->router;
    }

    private function initRoutes()
    {
        $this->router->get('/', function() {
            return json_encode([
                'Api Version' => '0.0.3',
                'Author' => '<NAME>'
            ]);
        });

        $this->router->post('/add/movie', function(Request $request) {
            $data = json_decode(urldecode($request->getQueryString()), true);
            return new JsonResponse(['what' => $this->model->addMovie($data)]);
        });

        $this->router->post('/add/seance', function(Request $request) {
            $data = json_decode(urldecode($request->getQueryString()), true);
            return new JsonResponse(['what' => $this->model->addSeance($data)]);
        });

        $this->router->post('/add/ticket', function(Request $request) {
            $data = json_decode(urldecode($request->getQueryString()), true);
            return new JsonResponse(['what' => $this->model->sellTicket($data)]);
        });

        $this->router->get('/json', function(Request $request) {
            $arr = json_decode(urldecode($request->getQueryString()), true);
            return new JsonResponse($arr);
        });

        $this->router->get('/halls', function() {
            return new JsonResponse($this->model->getHallsInfo(), JSON_NUMERIC_CHECK);
        });

        $this->router->get('/halls/{name}', function($name) {
            return new JsonResponse($this->model->getHallsInfo($name), JSON_NUMERIC_CHECK);
        });

        $this->router->get('/seances/{id}', function($id) {
            return new JsonResponse($this->model->getSeanceInfo($id), JSON_NUMERIC_CHECK);
        });

        $this->router->get('/seances/{from}/{to}', function($from, $to) {
            return new JsonResponse($this->model->getSeancesBetweenDates($from, $to), JSON_NUMERIC_CHECK);
        });

        $this->router->get('/movies', function() {
            return new JsonResponse($this->model->getMovies());
        });
    }
}
{'fraction_non_alphanumeric': 0.17096336499321574, 'fraction_numerical': 0.0011630160883892228, 'mean_word_length': 2.649222065063649, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 103, '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': '1346483', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1438, 'n_words': 235}