Skip to content

Commit

Permalink
add / to show api version
Browse files Browse the repository at this point in the history
  • Loading branch information
kernel64 committed Sep 28, 2024
1 parent 70462b2 commit f1be2c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Api-choufli-7all",
"name": "mabslabs/Api-choufli-7all",
"description": "It's a REST API that returns quotes from the Tunisian TV series Choufli 7all.",
"type": "project",
"require": {
Expand Down
10 changes: 7 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
ini_set('display_errors', 'on');
error_reporting(E_ALL);
header('Access-Control-Allow-Origin: *');

require_once __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/config.php';
Expand All @@ -10,6 +9,10 @@
$app = new App\APIChoufli7allApp();
$container = $app->getContainer();

$app->get('/', function () {
new JsonResponse(['version' => '1.0']);
});

$app->get('random', function () use ($container) {
$quote = [];
$stmt = $container['pdo']->query('SELECT COUNT(*) AS count FROM quotes');
Expand All @@ -18,7 +21,7 @@
if ($count > 0) {
// Get a random quote
$randomIndex = rand(0, $count - 1);
$stmt = $container['pdo']->prepare('SELECT quotes.quotes_text, actors.actors_name FROM quotes JOIN actors ON quotes.id_author = actors.actors_id LIMIT 1 OFFSET :offset');
$stmt = $container['pdo']->prepare('SELECT quotes.quotes_text, actors.actors_slug, actors.actors_name FROM quotes JOIN actors ON quotes.id_author = actors.actors_id LIMIT 1 OFFSET :offset');
$stmt->bindValue(':offset', $randomIndex, PDO::PARAM_INT);
$stmt->execute();

Expand All @@ -27,6 +30,7 @@
$quote = [
'quote' => $row['quotes_text'],
'actor' => $row['actors_name'],
'actor_slug' => $row['actors_slug'],
];
}

Expand Down

0 comments on commit f1be2c8

Please sign in to comment.