Compare commits

..

4 commits

Author SHA1 Message Date
e8a81b789b chore: bump Vegvisir to 3.2.8 (#52)
Reviewed-on: https://codeberg.org/vlw/vlw.se/pulls/52
2025-09-11 12:31:53 +02:00
5e9317def5 fix: enable strict parameter checks for /coffee POST endpoint (#51)
This will prevent typos from slipping through, which is nice.

Reviewed-on: https://codeberg.org/vlw/vlw.se/pulls/51
2025-08-30 08:27:36 +02:00
8209ea5ecc fix: /coffee DELETE endpoint incorrectly configured and missing table reference (#50)
Fix class config and missing `from()` method for the `/coffee` DELETE endpoint

Reviewed-on: https://codeberg.org/vlw/vlw.se/pulls/50
2025-08-30 08:27:12 +02:00
85e8e00091 feat(api): create DateTimeImmutable from timestamp for coffee POST endpoint (#49)
This PR allows creation of coffee entities at a specific date from a Unix timestamp by passing an integer to `date_created` when making a POST request to the `/coffee` endpoint.

Reviewed-on: https://codeberg.org/vlw/vlw.se/pulls/49
2025-08-24 03:40:58 +02:00
4 changed files with 14 additions and 6 deletions

View file

@ -8,12 +8,11 @@
use VLW\Database\Models\Coffee\Coffee;
use VLW\Database\Tables\Coffee\Coffee as CoffeeTable;
require_once Path::root("src/UUID.php");
require_once Path::root("src/API/API.php");
require_once Path::root("src/Database/Models/Coffee/Coffee.php");
require_once Path::root("src/Database/Tables/Coffee/Coffee.php");
final class POST_Coffee extends API {
final class DELETE_Coffee extends API {
public function __construct() {
parent::__construct(new Ruleset()->GET([
new Rules(CoffeeTable::ID->value)

View file

@ -13,9 +13,10 @@
final class POST_Coffee extends API {
public function __construct() {
parent::__construct(new Ruleset()->POST([
parent::__construct(new Ruleset(strict: true)->POST([
new Rules(CoffeeTable::DATE_CREATED->value)
->type(Type::STRING)
->type(Type::NUMBER)
->default(null)
]));
}
@ -26,7 +27,10 @@
// Parse DateTime from POST string
if ($_POST[CoffeeTable::DATE_CREATED->value]) {
try {
$datetime = new DateTimeImmutable($_POST[CoffeeTable::DATE_CREATED->value]);
// Create DateTimeImmutable from Unix timestamp or datetime string
$datetime = gettype($_POST[CoffeeTable::DATE_CREATED->value]) === "integer"
? DateTimeImmutable::createFromTimestamp($_POST[CoffeeTable::DATE_CREATED->value])
: new DateTimeImmutable($_POST[CoffeeTable::DATE_CREATED->value]);
} catch (DateMalformedStringException $error) {
return new Response($error->getMessage(), 400);
}

View file

@ -3,6 +3,7 @@
namespace VLW\Database\Models\Coffee;
use \VV;
use \Exception;
use \vlw\MySQL\Order;
use \DateTimeImmutable;
@ -61,7 +62,11 @@
}
public function delete(): bool {
return $this->db->delete([CoffeeTable::ID->value => $this->id]);
try {
return $this->db->from(CoffeeTable::TABLE)->delete([CoffeeTable::ID->value => $this->id]);
} catch (Exception $error) {
return false;
}
}
final public DateTimeImmutable $date_created {

@ -1 +1 @@
Subproject commit 461b2cc82b268ca09919a3506625957a868a9d27
Subproject commit 016b88068212243ce33894fbba9ffa91009146f0