Added doc

This commit is contained in:
julien
2026-03-09 10:15:08 +01:00
parent 60bd8178e8
commit 393561f6b0
4 changed files with 155 additions and 36 deletions

View File

@@ -25,7 +25,13 @@ class PostRepositoryMedoo
public function allDesc(): array
{
$rows = $this->db->select('post', ['id', 'title', 'content'], ['ORDER' => ['id' => 'DESC']]);
return is_array($rows) ? $rows : [];
return is_array($rows) ? array_map(function ($r) {
return [
'id' => (int)($r['id'] ?? 0),
'title' => (string)($r['title'] ?? ''),
'content' => (string)($r['content'] ?? ''),
];
}, $rows) : [];
}
/**
@@ -46,6 +52,10 @@ class PostRepositoryMedoo
];
}
/**
* @param array{title:string,content:string} $data
* @return int Inserted id
*/
public function create(array $data): int
{
$this->db->insert('post', [
@@ -55,6 +65,11 @@ class PostRepositoryMedoo
return (int)$this->db->id();
}
/**
* @param int $id
* @param array{title:string,content:string} $data
* @return void
*/
public function update(int $id, array $data): void
{
$this->db->update('post', [
@@ -63,6 +78,10 @@ class PostRepositoryMedoo
], ['id' => $id]);
}
/**
* @param int $id
* @return void
*/
public function delete(int $id): void
{
$this->db->delete('post', ['id' => $id]);