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
61 lines
2.3 KiB
PHP
61 lines
2.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\GPodderSync\Core\SubscriptionChange;
|
|
|
|
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
|
use OCA\GPodderSync\Db\SubscriptionChange\SubscriptionChangeEntity;
|
|
use OCA\GPodderSync\Db\SubscriptionChange\SubscriptionChangeRepository;
|
|
use OCA\GPodderSync\Db\SubscriptionChange\SubscriptionChangeWriter;
|
|
|
|
class SubscriptionChangeSaver {
|
|
|
|
/**
|
|
* @var SubscriptionChangesReader
|
|
*/
|
|
private SubscriptionChangesReader $subscriptionChangeReader;
|
|
/**
|
|
* @var SubscriptionChangeRepository
|
|
*/
|
|
private SubscriptionChangeRepository $subscriptionChangeRepository;
|
|
/**
|
|
* @var SubscriptionChangeWriter
|
|
*/
|
|
private SubscriptionChangeWriter $subscriptionChangeWriter;
|
|
/**
|
|
* @var SubscriptionChangeRequestParser
|
|
*/
|
|
private SubscriptionChangeRequestParser $subscriptionChangeRequestParser;
|
|
|
|
public function __construct(
|
|
SubscriptionChangeRequestParser $subscriptionChangeRequestParser,
|
|
SubscriptionChangeRepository $subscriptionChangeRepository,
|
|
SubscriptionChangeWriter $subscriptionChangeWriter
|
|
) {
|
|
$this->subscriptionChangeRepository = $subscriptionChangeRepository;
|
|
$this->subscriptionChangeWriter = $subscriptionChangeWriter;
|
|
$this->subscriptionChangeRequestParser = $subscriptionChangeRequestParser;
|
|
}
|
|
|
|
public function saveSubscriptionChanges(string $urlsSubscribed, string $urlsUnsubscribed, string $userId) : void {
|
|
$subscriptionChanges = $this->subscriptionChangeRequestParser->createSubscriptionChangeList($urlsSubscribed, $urlsUnsubscribed);
|
|
foreach ($subscriptionChanges as $urlChangedSubscriptionStatus) {
|
|
$subscriptionChangeEntity = new SubscriptionChangeEntity();
|
|
$subscriptionChangeEntity->setUrl($urlChangedSubscriptionStatus->getUrl());
|
|
$subscriptionChangeEntity->setSubscribed($urlChangedSubscriptionStatus->isSubscribed());
|
|
$subscriptionChangeEntity->setUpdated((new \DateTime())->format("Y-m-d\TH:i:s"));
|
|
$subscriptionChangeEntity->setUserId($userId);
|
|
|
|
try {
|
|
$this->subscriptionChangeWriter->create($subscriptionChangeEntity);
|
|
} catch (UniqueConstraintViolationException $ex) {
|
|
$idEpisodeActionEntityToUpdate = $this->subscriptionChangeRepository->findByUrl($subscriptionChangeEntity->getUrl(), $userId)->getId();
|
|
$subscriptionChangeEntity->setId($idEpisodeActionEntityToUpdate);
|
|
$this->subscriptionChangeWriter->update($subscriptionChangeEntity);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|