Moved personal metrics to API endpoint
This commit is contained in:
parent
b9f982cb92
commit
226054a634
@ -14,5 +14,6 @@ return [
|
|||||||
|
|
||||||
['name' => 'subscription_change#list', 'url' => '/subscriptions', 'verb' => 'GET'],
|
['name' => 'subscription_change#list', 'url' => '/subscriptions', 'verb' => 'GET'],
|
||||||
['name' => 'subscription_change#create', 'url' => '/subscription_change/create', 'verb' => 'POST'],
|
['name' => 'subscription_change#create', 'url' => '/subscription_change/create', 'verb' => 'POST'],
|
||||||
|
['name' => 'personal_settings#metrics', 'url' => '/personal_settings/metrics', 'verb' => 'GET'],
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
70
lib/Controller/PersonalSettingsController.php
Normal file
70
lib/Controller/PersonalSettingsController.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace OCA\GPodderSync\Controller;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionRepository;
|
||||||
|
use OCA\GPodderSync\Db\SubscriptionChange\SubscriptionChangeEntity;
|
||||||
|
use OCA\GPodderSync\Db\SubscriptionChange\SubscriptionChangeRepository;
|
||||||
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\IL10N;
|
||||||
|
use OCP\IRequest;
|
||||||
|
use OCP\Settings\ISettings;
|
||||||
|
|
||||||
|
class EpisodeActionController extends Controller {
|
||||||
|
|
||||||
|
private IL10N $l;
|
||||||
|
private SubscriptionChangeRepository $subscriptionChangeRepository;
|
||||||
|
private EpisodeActionRepository $episodeActionRepository;
|
||||||
|
private string $userId;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
string $AppName,
|
||||||
|
IRequest $request,
|
||||||
|
$UserId,
|
||||||
|
IL10N $l,
|
||||||
|
SubscriptionChangeRepository $subscriptionChangeRepository,
|
||||||
|
EpisodeActionRepository $episodeActionRepository,
|
||||||
|
) {
|
||||||
|
parent::__construct($AppName, $request);
|
||||||
|
$this->l = $l;
|
||||||
|
$this->subscriptionChangeRepository = $subscriptionChangeRepository;
|
||||||
|
$this->episodeActionRepository = $episodeActionRepository;
|
||||||
|
$this->userId = $UserId ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @NoCSRFRequired
|
||||||
|
*
|
||||||
|
* @return JSONResponse
|
||||||
|
*/
|
||||||
|
public function metrics(): JSONResponse {
|
||||||
|
$sinceDatetime = (new DateTime)->setTimestamp(0);
|
||||||
|
$subscriptions = $this->extractUrlList($this->subscriptionChangeRepository->findAllSubscribed($sinceDatetime, $this->userId));
|
||||||
|
$episodeActions = $this->episodeActionRepository->findAll(0, $this->userId);
|
||||||
|
$subStats = array();
|
||||||
|
foreach ($episodeActions as $action) {
|
||||||
|
$pod = $action->getPodcast();
|
||||||
|
$sub = $subStats[$pod] ?? array();
|
||||||
|
$sub['started']++;
|
||||||
|
$subStats[$pod] = $sub;
|
||||||
|
}
|
||||||
|
return new JSONResponse([
|
||||||
|
'subscriptions' => $subscriptions,
|
||||||
|
'subStats' => $subStats,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $allSubscribed
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function extractUrlList(array $allSubscribed): array {
|
||||||
|
return array_map(static function (SubscriptionChangeEntity $subscription) {
|
||||||
|
return $subscription->getUrl();
|
||||||
|
}, $allSubscribed);
|
||||||
|
}
|
||||||
|
}
|
@ -1,52 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace OCA\GPodderSync\Settings;
|
namespace OCA\GPodderSync\Settings;
|
||||||
|
|
||||||
use DateTime;
|
|
||||||
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionRepository;
|
|
||||||
use OCA\GPodderSync\Db\SubscriptionChange\SubscriptionChangeEntity;
|
|
||||||
use OCA\GPodderSync\Db\SubscriptionChange\SubscriptionChangeRepository;
|
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\Settings\ISettings;
|
use OCP\Settings\ISettings;
|
||||||
|
|
||||||
class GPodderSyncPersonal implements ISettings {
|
class GPodderSyncPersonal implements ISettings {
|
||||||
private IL10N $l;
|
|
||||||
private IConfig $config;
|
|
||||||
private SubscriptionChangeRepository $subscriptionChangeRepository;
|
|
||||||
private EpisodeActionRepository $episodeActionRepository;
|
|
||||||
private string $userId;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
IConfig $config,
|
|
||||||
IL10N $l,
|
|
||||||
$UserId,
|
|
||||||
SubscriptionChangeRepository $subscriptionChangeRepository,
|
|
||||||
EpisodeActionRepository $episodeActionRepository,
|
|
||||||
) {
|
|
||||||
$this->config = $config;
|
|
||||||
$this->l = $l;
|
|
||||||
$this->subscriptionChangeRepository = $subscriptionChangeRepository;
|
|
||||||
$this->episodeActionRepository = $episodeActionRepository;
|
|
||||||
$this->userId = $UserId ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getForm(): TemplateResponse {
|
public function getForm(): TemplateResponse {
|
||||||
$sinceDatetime = (new DateTime)->setTimestamp(0);
|
return new TemplateResponse('gpoddersync', 'settings/personal', []);
|
||||||
$subscriptions = $this->extractUrlList($this->subscriptionChangeRepository->findAllSubscribed($sinceDatetime, $this->userId));
|
|
||||||
$episodeActions = $this->episodeActionRepository->findAll(0, $this->userId);
|
|
||||||
$subStats = array();
|
|
||||||
foreach ($episodeActions as $action) {
|
|
||||||
$pod = $action->getPodcast();
|
|
||||||
$sub = $subStats[$pod] ?? array();
|
|
||||||
$sub['started']++;
|
|
||||||
$subStats[$pod] = $sub;
|
|
||||||
}
|
|
||||||
$params = array(
|
|
||||||
'subscriptions' => $subscriptions,
|
|
||||||
'subStats' => $subStats,
|
|
||||||
);
|
|
||||||
return new TemplateResponse('gpoddersync', 'settings/personal', $params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSection(): string {
|
public function getSection(): string {
|
||||||
@ -56,14 +21,4 @@ class GPodderSyncPersonal implements ISettings {
|
|||||||
public function getPriority(): int {
|
public function getPriority(): int {
|
||||||
return 198;
|
return 198;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $allSubscribed
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
private function extractUrlList(array $allSubscribed): array {
|
|
||||||
return array_map(static function (SubscriptionChangeEntity $subscription) {
|
|
||||||
return $subscription->getUrl();
|
|
||||||
}, $allSubscribed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user