diff --git a/lib/Db/NoteShareMapper.php b/lib/Db/NoteShareMapper.php index 50fcc67..4b7111e 100644 --- a/lib/Db/NoteShareMapper.php +++ b/lib/Db/NoteShareMapper.php @@ -5,6 +5,8 @@ use OCP\IDBConnection; use OCP\AppFramework\Db\Mapper; use OCP\AppFramework\Db\DoesNotExistException; +use OCA\QuickNotes\Db\NoteShare; + class NoteShareMapper extends Mapper { public function __construct(IDBConnection $db) { @@ -16,40 +18,43 @@ class NoteShareMapper extends Mapper { return $this->findEntity($sql, [$id, $userId]); }*/ - public function findForUser($userId) { + public function findForUser(string $userId): array { $sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_user = ?'; return $this->findEntities($sql, [$userId]); } - public function findForGroup($groupId) { + public function findForGroup($groupId): array { $sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_group = ?'; return $this->findEntities($sql, [$groupId]); } - public function findByNoteAndUser($noteId, $userId) { + public function findByNoteAndUser($noteId, $userId): NoteShare { $sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_user = ? AND note_id = ?'; return $this->findEntity($sql, [$userId, $noteId]); } - public function findByNoteAndGroup($noteId, $groupId) { + public function findByNoteAndGroup($noteId, $groupId): NoteShare { $sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_group = ? AND note_id = ?'; return $this->findEntity($sql, [$groupId, $noteId]); } - public function getSharesForNote($noteId) { + public function getSharesForNote(int $noteId): array { $sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE note_id = ?'; return $this->findEntities($sql, [$noteId]); } - public function deleteByNoteId($noteId) { + public function deleteByNoteId(int $noteId): void { $sql = 'DELETE FROM *PREFIX*quicknotes_shares WHERE note_id = ?'; $this->execute($sql, [$noteId]); } - public function existsByNoteAndUser($noteId, $userId) { + /** + * @return bool + */ + public function existsByNoteAndUser(int $noteId, $userId) { $sql = 'SELECT * FROM *PREFIX*quicknotes_shares WHERE shared_user = ? AND note_id = ?'; try { - return $this->findEntities($sql, [$userId, $noteId]); + $this->findEntities($sql, [$userId, $noteId]); } catch (DoesNotExistException $e) { return false; } diff --git a/lib/Db/NoteTagMapper.php b/lib/Db/NoteTagMapper.php index a5f4b5a..a14db01 100644 --- a/lib/Db/NoteTagMapper.php +++ b/lib/Db/NoteTagMapper.php @@ -3,6 +3,9 @@ namespace OCA\QuickNotes\Db; use OCP\IDBConnection; use OCP\AppFramework\Db\Mapper; +use OCP\AppFramework\Db\DoesNotExistException; + +use OCA\QuickNotes\Db\NoteTag; class NoteTagMapper extends Mapper { @@ -10,25 +13,28 @@ class NoteTagMapper extends Mapper { parent::__construct($db, 'quicknotes_note_tags', '\OCA\QuickNotes\Db\NoteTag'); } - public function find($id, $userId) { + public function find($id, $userId): NoteTag { $sql = 'SELECT * FROM *PREFIX*quicknotes_note_tags WHERE id = ? AND user_id = ?'; return $this->findEntity($sql, [$id, $userId]); } - public function findAll($userId) { + public function findAll($userId): array { $sql = 'SELECT * FROM *PREFIX*quicknotes_note_tags WHERE user_id = ?'; return $this->findEntities($sql, [$userId]); } - public function findNoteTag($userId, $noteId, $tagId) { + public function findNoteTag(string $userId, int $noteId, $tagId): NoteTag { $sql = 'SELECT * FROM *PREFIX*quicknotes_note_tags WHERE user_id = ? AND note_id = ? AND tag_id = ?'; return $this->findEntity($sql, [$userId, $noteId, $tagId]); } - public function noteTagExists($userId, $noteId, $tagId) { + /** + * @return bool + */ + public function noteTagExists(string $userId, int $noteId, int $tagId): bool { $sql = 'SELECT * FROM *PREFIX*quicknotes_note_tags WHERE user_id = ? AND note_id = ? AND tag_id = ?'; try { - return $this->findEntities($sql, [$userId, $noteId, $tagId]); + $this->findEntities($sql, [$userId, $noteId, $tagId]); } catch (DoesNotExistException $e) { return false; } diff --git a/lib/Db/TagMapper.php b/lib/Db/TagMapper.php index b4a866f..cdcb7bd 100644 --- a/lib/Db/TagMapper.php +++ b/lib/Db/TagMapper.php @@ -3,6 +3,9 @@ namespace OCA\QuickNotes\Db; use OCP\IDBConnection; use OCP\AppFramework\Db\Mapper; +use OCP\AppFramework\Db\DoesNotExistException; + +use OCA\QuickNotes\Db\Tag; class TagMapper extends Mapper { @@ -10,17 +13,17 @@ class TagMapper extends Mapper { parent::__construct($db, 'quicknotes_tags', '\OCA\QuickNotes\Db\Tag'); } - public function find($id, $userId) { + public function find($id, $userId): Tag { $sql = 'SELECT * FROM *PREFIX*quicknotes_tags WHERE id = ? AND user_id = ?'; return $this->findEntity($sql, [$id, $userId]); } - public function findAll($userId) { + public function findAll($userId): array { $sql = 'SELECT * FROM *PREFIX*quicknotes_tags WHERE user_id = ?'; return $this->findEntities($sql, [$userId]); } - public function getTagsForNote($userId, $noteId) { + public function getTagsForNote(string $userId, int $noteId): array { $sql = 'SELECT T.id, T.name FROM *PREFIX*quicknotes_tags T '; $sql.= 'INNER JOIN *PREFIX*quicknotes_note_tags NT '; $sql.= 'ON T.id = NT.tag_id '; @@ -28,15 +31,18 @@ class TagMapper extends Mapper { return $this->findEntities($sql, [$userId, $noteId]); } - public function getTag($userId, $name) { + public function getTag(string $userId, $name): Tag { $sql = 'SELECT * FROM *PREFIX*quicknotes_tags WHERE user_id = ? AND name = ?'; return $this->findEntity($sql, [$userId, $name]); } - public function tagExists($userId, $name) { + /** + * @return bool + */ + public function tagExists(string $userId, $name): bool { $sql = 'SELECT * FROM *PREFIX*quicknotes_tags WHERE user_id = ? AND name = ?'; try { - return $this->findEntities($sql, [$userId, $name]); + $this->findEntities($sql, [$userId, $name]); } catch (DoesNotExistException $e) { return false; } @@ -46,6 +52,6 @@ class TagMapper extends Mapper { public function dropOld () { $sql = 'DELETE FROM *PREFIX*quicknotes_tags WHERE '; $sql.= 'id NOT IN (SELECT tag_id FROM *PREFIX*quicknotes_note_tags)'; - return $this->execute($sql, []); + $this->execute($sql, []); } } \ No newline at end of file