More return types

This commit is contained in:
Matias De lellis
2021-09-19 22:44:27 -03:00
parent 974faf866a
commit e0d29ecc88
3 changed files with 37 additions and 20 deletions

View File

@@ -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;
}