refactor: 🚧 rework metrics
This commit is contained in:
parent
cbe8750fd2
commit
427c6b2ee8
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace OCA\RePod\Controller;
|
||||||
|
|
||||||
|
use OCA\GPodderSync\Core\PodcastData\PodcastDataReader;
|
||||||
|
use OCA\GPodderSync\Core\PodcastData\PodcastMetricsReader;
|
||||||
|
use OCA\RePod\AppInfo\Application;
|
||||||
|
use OCA\RePod\Service\UserService;
|
||||||
|
use OCP\AppFramework\Controller;
|
||||||
|
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
|
||||||
|
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
||||||
|
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
|
||||||
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
|
use OCP\IRequest;
|
||||||
|
|
||||||
|
class MetricsController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
IRequest $request,
|
||||||
|
private PodcastDataReader $podcastDataReader,
|
||||||
|
private PodcastMetricsReader $podcastMetricsReader,
|
||||||
|
private UserService $userService
|
||||||
|
) {
|
||||||
|
parent::__construct(Application::APP_ID, $request);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoAdminRequired]
|
||||||
|
#[NoCSRFRequired]
|
||||||
|
#[FrontpageRoute(verb: 'GET', url: '/metrics')]
|
||||||
|
public function index(): JSONResponse {
|
||||||
|
$subscriptions = $this->podcastMetricsReader->metrics($this->userService->getUserUID());
|
||||||
|
|
||||||
|
foreach ($subscriptions as $id => $subscription) {
|
||||||
|
try {
|
||||||
|
$subscriptions[$id]['data'] = $this->podcastDataReader->getCachedOrFetchPodcastData($subscription->getUrl(), $this->userService->getUserUID());
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new JSONResponse($subscriptions);
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,7 +24,7 @@ export const useSubscriptions = defineStore('subscriptions', {
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
const metrics = await axios.get<PersonalSettingsMetricsInterface>(
|
const metrics = await axios.get<PersonalSettingsMetricsInterface>(
|
||||||
generateUrl('/apps/gpoddersync/personal_settings/metrics'),
|
generateUrl('/apps/repod/metrics'),
|
||||||
)
|
)
|
||||||
|
|
||||||
this.subs = [...metrics.data.subscriptions]
|
this.subs = [...metrics.data.subscriptions]
|
||||||
|
|
Loading…
Reference in New Issue