added DiffTask Entity and Mapper

This commit is contained in:
Jonathan Treffler 2023-09-02 02:41:17 +02:00 committed by root
parent 31f0fa6b0f
commit d8651c7780
2 changed files with 65 additions and 0 deletions

28
lib/Db/DiffTask.php Normal file
View file

@ -0,0 +1,28 @@
<?php
namespace OCA\GroupfolderFilesystemSnapshots\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
class DiffTask extends Entity implements JsonSerializable {
protected $userId;
protected $groupfolderId;
protected $snapshotId;
protected $timestamp;
public function __construct() {
$this->addType('id','integer');
$this->addType('groupfolderId','integer');
}
public function jsonSerialize() {
return [
'id' => $this->id,
'groupfolderId' => $this->groupfolderId,
'snapshotId' => $this->snapshotId,
'timestamp' => $this->timestamp,
];
}
}

37
lib/Db/DiffTaskMapper.php Normal file
View file

@ -0,0 +1,37 @@
<?php
namespace OCA\GroupfolderFilesystemSnapshots\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper;
/**
* @extends QBMapper<DiffTask>
*/
class DiffTaskMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'groupfolder_snapshots_tasks', DiffTask::class);
}
public function find(int $id, string $userId) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)));
return $this->findEntity($qb);
}
public function findAll(string $userId) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)));
return $this->findEntities($qb);
}
}