Added doc
This commit is contained in:
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user