mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-06-22 06:10:30 +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();
|
->get();
|
||||||
|
|
||||||
return $events->map(fn ($event) => [
|
return $events->map(fn ($event) => [
|
||||||
|
'id' => $event->id,
|
||||||
'start' => $event->start->format('Y-m-d H:i'),
|
'start' => $event->start->format('Y-m-d H:i'),
|
||||||
'location' => $event->location,
|
'location' => $event->location,
|
||||||
'description' => $event->description,
|
'description' => $event->description,
|
||||||
'link' => $event->link,
|
'link' => $event->link,
|
||||||
|
'attendees' => $event->attendeesCount(),
|
||||||
|
'might_attendees' => $event->mightAttendeesCount(),
|
||||||
'meetup.name' => $event->meetup->name,
|
'meetup.name' => $event->meetup->name,
|
||||||
'meetup.portalLink' => url()->route(
|
'meetup.portalLink' => url()->route(
|
||||||
'meetups.landingpage',
|
'meetups.landingpage',
|
||||||
@@ -202,8 +205,8 @@ class MeetupEventController extends Controller
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'status' => $meetupEvent->rsvpStatusFor($user)->value,
|
'status' => $meetupEvent->rsvpStatusFor($user)->value,
|
||||||
'attendees' => count($meetupEvent->attendees ?? []),
|
'attendees' => $meetupEvent->attendeesCount(),
|
||||||
'might_attendees' => count($meetupEvent->might_attendees ?? []),
|
'might_attendees' => $meetupEvent->mightAttendeesCount(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -272,8 +272,8 @@ class Meetup extends Model implements HasMedia
|
|||||||
'location' => $nextEvent->location,
|
'location' => $nextEvent->location,
|
||||||
'description' => $nextEvent->description,
|
'description' => $nextEvent->description,
|
||||||
'link' => $nextEvent->link,
|
'link' => $nextEvent->link,
|
||||||
'attendees' => count($nextEvent->attendees ?? []),
|
'attendees' => $nextEvent->attendeesCount(),
|
||||||
'might_attendees' => count($nextEvent->might_attendees ?? []),
|
'might_attendees' => $nextEvent->mightAttendeesCount(),
|
||||||
'nostr_note' => str($nextEvent->nostr_status)->after('Sent event ')->before(' to '),
|
'nostr_note' => str($nextEvent->nostr_status)->after('Sent event ')->before(' to '),
|
||||||
] : null,
|
] : null,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -65,6 +65,19 @@ class MeetupEvent extends Model
|
|||||||
return $this->belongsTo(Meetup::class);
|
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.
|
* Eindeutige Kennung eines angemeldeten Nutzers in den Teilnehmer-Listen.
|
||||||
* Einträge werden als `id_<userId>|<name>` abgelegt; der angehängte Pipe
|
* 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 = $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();
|
expect($response->json())->toBeArray()->not->toBeEmpty();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user