mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-01-24 12:03:17 +00:00
🗓️ Add MeetupEventFactory, implement rate limiting for calendar downloads, and enhance test coverage
- **Added:** `MeetupEventFactory` for generating test data. - **Implemented:** Rate limiting (`throttle:calendar`) for `stream-calendar` routes to prevent abuse. - **Enhanced:** `DownloadMeetupCalendar` controller with validation and cleaner query structure. - **Added:** Feature tests for calendar downloading, invalid input handling, and rate limiting.
This commit is contained in:
@@ -17,46 +17,50 @@ class DownloadMeetupCalendar extends Controller
|
||||
public function __invoke(Request $request): Response
|
||||
{
|
||||
if ($request->has('meetup')) {
|
||||
$validated = $request->validate([
|
||||
'meetup' => ['required', 'integer'],
|
||||
]);
|
||||
|
||||
$meetup = Meetup::query()
|
||||
->with([
|
||||
'meetupEvents.meetup',
|
||||
])
|
||||
->findOrFail($request->input('meetup'));
|
||||
->with([
|
||||
'meetupEvents.meetup',
|
||||
])
|
||||
->findOrFail($validated['meetup']);
|
||||
$events = $meetup->meetupEvents()->where('start', '>=', now())->get();
|
||||
$image = $meetup->getFirstMediaUrl('logo');
|
||||
} elseif ($request->has('my')) {
|
||||
$ids = $request->input('my');
|
||||
$events = MeetupEvent::query()
|
||||
->with([
|
||||
'meetup',
|
||||
])
|
||||
->where('start', '>=', now())
|
||||
->whereHas('meetup', fn($query) => $query->whereIn('meetups.id', $ids))
|
||||
->get();
|
||||
->with([
|
||||
'meetup',
|
||||
])
|
||||
->where('start', '>=', now())
|
||||
->whereHas('meetup', fn ($query) => $query->whereIn('meetups.id', $ids))
|
||||
->get();
|
||||
$image = asset('img/einundzwanzig-horizontal.png');
|
||||
} else {
|
||||
$events = MeetupEvent::query()
|
||||
->with([
|
||||
'meetup',
|
||||
])
|
||||
->where('start', '>=', now())
|
||||
->get();
|
||||
->with([
|
||||
'meetup',
|
||||
])
|
||||
->where('start', '>=', now())
|
||||
->get();
|
||||
$image = asset('img/einundzwanzig-horizontal.png');
|
||||
}
|
||||
|
||||
$entries = [];
|
||||
foreach ($events as $event) {
|
||||
$entries[] = Event::create($event->meetup->name)
|
||||
->uniqueIdentifier(str($event->meetup->name)->slug().$event->id)
|
||||
->address($event->location ?? __('no location set'))
|
||||
->description(str_replace(["\r", "\n"], '', $event->description).' Link: '.$event->link)
|
||||
->image($event->meetup->getFirstMedia('logo') ? $event->meetup->getFirstMediaUrl('logo') : $image)
|
||||
->startsAt($event->start);
|
||||
->uniqueIdentifier(str($event->meetup->name)->slug().$event->id)
|
||||
->address($event->location ?? __('no location set'))
|
||||
->description(str_replace(["\r", "\n"], '', $event->description).' Link: '.$event->link)
|
||||
->image($event->meetup->getFirstMedia('logo') ? $event->meetup->getFirstMediaUrl('logo') : $image)
|
||||
->startsAt($event->start);
|
||||
}
|
||||
|
||||
$calendar = Calendar::create()
|
||||
->refreshInterval(5)
|
||||
->event($entries);
|
||||
->refreshInterval(5)
|
||||
->event($entries);
|
||||
|
||||
return response($calendar->get())
|
||||
->header('Content-Type', 'text/calendar; charset=utf-8');
|
||||
|
||||
Reference in New Issue
Block a user