<?php
namespace App\Controller\Views;
use App\Enum\SettingsKey;
use App\Service\CalendarService;
use App\Service\KeyService;
use App\Service\MessageService;
use App\Service\SerializerService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DashboardController extends AbstractController{
#[Route('/', methods: ['GET'])]
public function index(MessageService $messageService, KeyService $keyService, CalendarService $calendarService): Response
{
$googleAt=$keyService->getValue(SettingsKey::GOOGLE_O2AUTH, true, true);
try {
if(!empty($googleAt)) $calendarService->fetchFromGoogle();
} catch(\Exception $ex){
$googleAt="";
}
$messageSummary=$messageService->getTodaySummary();
return $this->render('views/dashboard/index.html.twig', [
'google_at'=>$googleAt,
'meta_at'=>$keyService->getValue(SettingsKey::META_ACCESS_TOKEN, true, true),
'messages'=>$messageSummary,
'user'=>SerializerService::serialize($this->getUser(), SerializerService::ENCODER_ARRAY)
]);
}
}