tkr/src/Controller/TickController/TickController.php
Greg Sarjeant 2e82f946ae Add TickController tests and logs (#50)
Closes https://gitea.subcultureofone.org/greg/tkr/issues/45

Reviewed-on: https://gitea.subcultureofone.org/greg/tkr/pulls/50
Co-authored-by: Greg Sarjeant <greg@subcultureofone.org>
Co-committed-by: Greg Sarjeant <greg@subcultureofone.org>
2025-08-02 20:57:01 +00:00

29 lines
988 B
PHP

<?php
class TickController extends Controller{
public function index(int $id){
global $app;
Log::debug("Fetching tick with ID: {$id}");
try {
$tickModel = new TickModel($app['db'], $app['config']);
$vars = $tickModel->get($id);
if (empty($vars) || !isset($vars['tick'])) {
Log::warning("Tick not found for ID: {$id}");
http_response_code(404);
echo '<h1>404 - Tick Not Found</h1>';
return;
}
Log::info("Successfully loaded tick {$id}: " . substr($vars['tick'], 0, 50) . (strlen($vars['tick']) > 50 ? '...' : ''));
$this->render('tick.php', $vars);
} catch (Exception $e) {
Log::error("Failed to load tick {$id}: " . $e->getMessage());
http_response_code(500);
echo '<h1>500 - Internal Server Error</h1>';
}
}
}