Compare commits

...

10 Commits

Author SHA1 Message Date
philipp lang 898e932ceb Update adrema-form 2024-06-18 22:00:59 +02:00
philipp lang 83bf0ebead Update adrema-form 2024-06-18 21:49:43 +02:00
philipp lang 08ddb2b02e Update adrema-form 2024-06-18 21:34:09 +02:00
philipp lang 0bfe09772f Update adrema-form 2024-06-10 21:38:35 +02:00
philipp lang 15502ee2f0 Update adrema-form 2024-06-10 16:51:53 +02:00
philipp lang 712fb479dc Add clear cache via Request 2024-06-10 00:13:43 +02:00
philipp lang 14b6e22b49 Update adrema-form 2024-06-07 00:47:02 +02:00
philipp lang 19fd50901c Update adrema-form 2024-05-27 19:12:02 +02:00
philipp lang abad397dcf Update adrema-form 2024-04-26 20:18:57 +02:00
philipp lang 6f268a224b Add caching for events 2024-04-26 15:31:32 +02:00
6 changed files with 32 additions and 4 deletions

@ -1 +1 @@
Subproject commit b65ae906b25488c56b5c232642d848d95fb57de0
Subproject commit bd4118040fd2643b71f7f152ca2668f2097820a2

View File

@ -149,8 +149,9 @@ abstract class EventManager extends ComponentBase
return;
}
$this->eventMeta = data_get(app(FetchAllEvents::class)->run(), 'meta', []);
$this->events = $this->page['events'] = collect(app(FetchAllEvents::class)->run()['data']);
$eventData = app(FetchAllEvents::class)->run();
$this->eventMeta = data_get($eventData, 'meta', []);
$this->events = $this->page['events'] = collect($eventData['data']);
$this->event = $this->page['event'] = $this->events->first(fn ($event) => $event['slug'] == $eventSlug);
$this->currentUrl = url()->current();
}

View File

@ -1,8 +1,11 @@
<?php
use Silva\Adrema\Support\ClearCache;
use Silva\Adrema\Support\Proxy;
Route::get('/adrema-api/{route}', fn (string $route) => Response::json(app(Proxy::class)->run($route, 'get')))
->where('route', '[a-zA-Z0-9\-/]+')->middleware('api');
Route::post('/adrema-api/{route}', fn (string $route) => app(Proxy::class)->submit($route))
->where('route', '[a-zA-Z0-9\-/]+')->middleware('api');
Route::get('/adrema/clear-cache', fn () => app(ClearCache::class)->run());

13
support/ClearCache.php Normal file
View File

@ -0,0 +1,13 @@
<?php
namespace Silva\Adrema\Support;
use Cache;
class ClearCache
{
public function run(): void
{
Cache::forget('adrema-all-events');
}
}

View File

@ -8,11 +8,12 @@ class FetchAllEvents
{
public function run(): ?Collection
{
$events = app(Proxy::class)->run('/api/form');
$events = app(Proxy::class)->run('api/form');
if (!$events) {
return null;
}
return collect($events);
}
}

View File

@ -2,6 +2,7 @@
namespace Silva\Adrema\Support;
use Cache;
use Silva\Adrema\Models\Settings;
use Http;
use Illuminate\Http\JsonResponse;
@ -9,6 +10,15 @@ use Illuminate\Http\JsonResponse;
class Proxy
{
public function run(string $url): ?array
{
if ($url === 'api/form') {
return Cache::rememberForever('adrema-all-events', fn () => $this->get($url));
}
return $this->get($url);
}
protected function get(string $url): ?array
{
$response = Http::acceptJson()->get($this->url($url));