NC app base

This commit is contained in:
Szabo David
2022-11-28 11:25:02 +01:00
parent 6e609d9715
commit cbcbda164c
37 changed files with 1774 additions and 0 deletions

33
lib/Db/Note.php Normal file
View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
// SPDX-FileCopyrightText: Szabó Dávid <daevidt@gmail.com>
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace OCA\Nezd\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
/**
* @method getId(): int
* @method getTitle(): string
* @method setTitle(string $title): void
* @method getContent(): string
* @method setContent(string $content): void
* @method getUserId(): string
* @method setUserId(string $userId): void
*/
class Note extends Entity implements JsonSerializable {
protected string $title = '';
protected string $content = '';
protected string $userId = '';
public function jsonSerialize(): array {
return [
'id' => $this->id,
'title' => $this->title,
'content' => $this->content
];
}
}

48
lib/Db/NoteMapper.php Normal file
View File

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
// SPDX-FileCopyrightText: Szabó Dávid <daevidt@gmail.com>
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace OCA\Nezd\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
/**
* @template-extends QBMapper<Note>
*/
class NoteMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'nezd', Note::class);
}
/**
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws DoesNotExistException
*/
public function find(int $id, string $userId): Note {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('nezd')
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)));
return $this->findEntity($qb);
}
/**
* @param string $userId
* @return array
*/
public function findAll(string $userId): array {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('nezd')
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)));
return $this->findEntities($qb);
}
}