1
0
Fork 0

added Subscription Entity and Mapper

This commit is contained in:
Jonathan Treffler 2024-06-12 01:50:04 +02:00
parent 32aa0aa386
commit 05bbfe100d
2 changed files with 66 additions and 0 deletions

31
lib/Db/Subscription.php Normal file
View file

@ -0,0 +1,31 @@
<?php
namespace OCA\DavPush\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
class Subscription extends Entity implements JsonSerializable {
protected $userId;
protected $collectionName;
protected $data;
protected $creationTimestamp;
protected $expirationTimestamp;
public function __construct() {
$this->addType('creationTimestamp','integer');
$this->addType('expirationTimestamp','integer');
}
public function jsonSerialize(): array {
return [
'id' => $this->id,
'userId' => $this->userId,
'collectionName' => $this->collectionName,
'data' => $this->data,
'creationTimestamp' => $this->creationTimestamp,
'expirationTimestamp' => $this->expirationTimestampv
];
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace OCA\DavPush\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
class SubscriptionMapper extends QBMapper {
public const TABLENAME = 'dav_push_subscriptions';
public function __construct(IDBConnection $db) {
parent::__construct($db, self::TABLENAME, Subscription::class);
}
/**
* @param string $userId
* @param string $id
* @return Entity|Subscription
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws DoesNotExistException
*/
public function find(string $userId, int $id): Subscription {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from(self::TABLENAME)
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)));
return $this->findEntity($qb);
}
}