mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-06-17 04:30:31 +00:00
✨ Add attendee count helpers and enhance Meetup API responses
- ➕ Introduce `attendeesCount` and `mightAttendeesCount` methods in `MeetupEvent` model for cleaner attendee calculations. - 🛠️ Refactor API responses to use attendee count helpers in `Meetup` and `MeetupEventController`. - 🧪 Update tests to validate JSON structure with attendee-related fields (`id`, `attendees`, `might_attendees`).
This commit is contained in:
@@ -59,10 +59,13 @@ class MeetupEventController extends Controller
|
||||
->get();
|
||||
|
||||
return $events->map(fn ($event) => [
|
||||
'id' => $event->id,
|
||||
'start' => $event->start->format('Y-m-d H:i'),
|
||||
'location' => $event->location,
|
||||
'description' => $event->description,
|
||||
'link' => $event->link,
|
||||
'attendees' => $event->attendeesCount(),
|
||||
'might_attendees' => $event->mightAttendeesCount(),
|
||||
'meetup.name' => $event->meetup->name,
|
||||
'meetup.portalLink' => url()->route(
|
||||
'meetups.landingpage',
|
||||
@@ -202,8 +205,8 @@ class MeetupEventController extends Controller
|
||||
{
|
||||
return [
|
||||
'status' => $meetupEvent->rsvpStatusFor($user)->value,
|
||||
'attendees' => count($meetupEvent->attendees ?? []),
|
||||
'might_attendees' => count($meetupEvent->might_attendees ?? []),
|
||||
'attendees' => $meetupEvent->attendeesCount(),
|
||||
'might_attendees' => $meetupEvent->mightAttendeesCount(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,8 +272,8 @@ class Meetup extends Model implements HasMedia
|
||||
'location' => $nextEvent->location,
|
||||
'description' => $nextEvent->description,
|
||||
'link' => $nextEvent->link,
|
||||
'attendees' => count($nextEvent->attendees ?? []),
|
||||
'might_attendees' => count($nextEvent->might_attendees ?? []),
|
||||
'attendees' => $nextEvent->attendeesCount(),
|
||||
'might_attendees' => $nextEvent->mightAttendeesCount(),
|
||||
'nostr_note' => str($nextEvent->nostr_status)->after('Sent event ')->before(' to '),
|
||||
] : null,
|
||||
);
|
||||
|
||||
@@ -65,6 +65,19 @@ class MeetupEvent extends Model
|
||||
return $this->belongsTo(Meetup::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Anzahl der Zusagen bzw. Vielleicht-Sagen (die Listen sind JSON-Arrays).
|
||||
*/
|
||||
public function attendeesCount(): int
|
||||
{
|
||||
return count($this->attendees ?? []);
|
||||
}
|
||||
|
||||
public function mightAttendeesCount(): int
|
||||
{
|
||||
return count($this->might_attendees ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Eindeutige Kennung eines angemeldeten Nutzers in den Teilnehmer-Listen.
|
||||
* Einträge werden als `id_<userId>|<name>` abgelegt; der angehängte Pipe
|
||||
|
||||
@@ -80,7 +80,9 @@ it('returns meetup events as JSON on GET /api/meetup-events', function () {
|
||||
|
||||
$response = $this->getJson('/api/meetup-events');
|
||||
|
||||
$response->assertSuccessful();
|
||||
$response->assertSuccessful()
|
||||
// id + Zähler werden für das RSVP im mobilen Slide-In gebraucht.
|
||||
->assertJsonStructure([['id', 'start', 'attendees', 'might_attendees', 'meetup.name']]);
|
||||
expect($response->json())->toBeArray()->not->toBeEmpty();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user