vlw.se/endpoints/coffee/stats/GET.php
Victor Westerlund f4279c0343 feat: add coffee stats endpoints and counter to about page (#28)
This PR refactors some texts on the about page (again), and also a adds two new endpoints for a database table that I have now made public that tracks the coffee cups I've had. The endpoint itself is not public now but I might make a page (something like `/about/coffee`) that presents it in a not-ugly way.

Reviewed-on: https://codeberg.org/vlw/vlw.se/pulls/28
2025-03-13 15:16:53 +00:00

42 lines
No EOL
1.1 KiB
PHP

<?php
use vlw\MySQL\Order;
use Reflect\{Response, Path, Call};
use ReflectRules\{Ruleset, Rules, Type};
use VLW\API\Endpoints;
use VLW\Database\Database;
use const VLW\COFFEE_STATS_UPDATE_PARAM;
use VLW\Database\Tables\Coffee\StatsTable;
require_once Path::root("src/Consts.php");
require_once Path::root("src/API/Endpoints.php");
require_once Path::root("src/Database/Database.php");
require_once Path::root("src/Database/Tables/Coffee/Stats.php");
class GET_CoffeeStats extends Database {
protected readonly Ruleset $ruleset;
public function __construct() {
$this->ruleset = new Ruleset(strict: true);
$this->ruleset->GET([
(new Rules(COFFEE_STATS_UPDATE_PARAM))
->type(Type::BOOLEAN)
->default(false)
]);
$this->ruleset->validate_or_exit();
parent::__construct();
}
public function main(): Response {
// Freshen cache if update flag is set
if ($_GET[COFFEE_STATS_UPDATE_PARAM]) {
(new Call(Endpoints::COFFEE_STATS->value))->post();
}
return $this->list(StatsTable::NAME, StatsTable::values());
}
}