mirror of
https://github.com/thrillfall/nextcloud-gpodder.git
synced 2024-12-28 00:30:20 +01:00
72bf365285
persist and list with database create episodeAction list reponse (with mocked timestamp, started and total) create episodeActions with received values update existing episodeActions by unique episode link receive and store subscription changes deal with multiple subscription changes in single request split database into subdirectories only return subscription changes younger then passed parameter since parse passed timestamp parse passed timestamp for episode_actions listing only return list of urls for subscription changes align list endpoint naming schema store userId with episode actions and subscriptions return json object on application root route
70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\GPodderSync\Db\SubscriptionChange;
|
|
|
|
use OCP\AppFramework\Db\DoesNotExistException;
|
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
use OCP\IDBConnection;
|
|
|
|
class SubscriptionChangeMapper extends \OCP\AppFramework\Db\QBMapper {
|
|
public function __construct(IDBConnection $db) {
|
|
parent::__construct($db, 'gpoddersync_subscriptions', SubscriptionChangeEntity::class);
|
|
}
|
|
|
|
public function findAll(string $userId): array {
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
$qb->select('*')
|
|
->from($this->getTableName())
|
|
->where(
|
|
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
|
);
|
|
|
|
return $this->findEntities($qb);
|
|
}
|
|
|
|
public function findByUrl(string $url, string $userId): SubscriptionChangeEntity {
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
$qb->select('*')
|
|
->from($this->getTableName())
|
|
->where(
|
|
$qb->expr()->eq('url', $qb->createNamedParameter($url))
|
|
)
|
|
->andWhere(
|
|
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
|
);
|
|
|
|
try {
|
|
return $this->findEntity($qb);
|
|
} catch (DoesNotExistException $e) {
|
|
} catch (MultipleObjectsReturnedException $e) {
|
|
}
|
|
}
|
|
|
|
public function remove(SubscriptionChangeEntity $subscriptionChangeEntity) {
|
|
$this->delete($subscriptionChangeEntity);
|
|
}
|
|
|
|
public function findAllSubscriptionState(bool $subscribed, \DateTime $sinceTimestamp, string $userId) {
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
$qb->select('url')
|
|
->from($this->getTableName())
|
|
->where(
|
|
$qb->expr()->eq('subscribed', $qb->createNamedParameter($subscribed, IQueryBuilder::PARAM_BOOL))
|
|
)->andWhere(
|
|
$qb->expr()->gt('updated', $qb->createNamedParameter($sinceTimestamp, IQueryBuilder::PARAM_DATE))
|
|
)
|
|
->andWhere(
|
|
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
|
);
|
|
|
|
return $this->findEntities($qb);
|
|
}
|
|
|
|
|
|
}
|