2025-08-01 05:25:35 +07:00
|
|
|
<?php
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
|
use CodeIgniter\Controller;
|
|
|
|
|
|
2025-08-01 11:37:03 +07:00
|
|
|
class Race extends Controller {
|
|
|
|
|
use ResponseTrait;
|
2025-08-01 05:25:35 +07:00
|
|
|
|
2025-08-01 11:37:03 +07:00
|
|
|
public function __construct() {
|
|
|
|
|
$this->db = \Config\Database::connect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function index() {
|
|
|
|
|
try {
|
2025-08-08 08:37:00 +07:00
|
|
|
$sql = "SELECT * FROM race";
|
2025-08-01 11:37:03 +07:00
|
|
|
$data = $this->db->query($sql)->getResultArray();
|
|
|
|
|
|
2025-08-08 08:37:00 +07:00
|
|
|
return $this->respond([
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'message'=> "Race fetched successfully",
|
|
|
|
|
'data' => $data,
|
|
|
|
|
], 200);
|
2025-08-01 11:37:03 +07:00
|
|
|
} catch (\Exception $e) {
|
2025-08-08 08:37:00 +07:00
|
|
|
return $this->failServerError('Something went wrong'. $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function show($RaceID = null) {
|
|
|
|
|
try {
|
2025-08-08 08:41:02 +07:00
|
|
|
$sql = "SELECT * FROM race WHERE RaceID = $RaceID";
|
2025-08-08 08:37:00 +07:00
|
|
|
$data = $this->db->query($sql)->getResultArray();
|
|
|
|
|
|
|
|
|
|
return $this->respond([
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'message'=> "Race with RaceID $RaceID fetched successfully",
|
|
|
|
|
'data' => $data,
|
|
|
|
|
], 200);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return $this->failServerError('Something went wrong'. $e->getMessage());
|
2025-08-01 05:25:35 +07:00
|
|
|
}
|
2025-08-01 11:37:03 +07:00
|
|
|
}
|
2025-08-01 05:25:35 +07:00
|
|
|
}
|