feat: track event participation and show joined events first

Backend:
- Add EventParticipant model to track user-event participation
- Create database migration for event_participants table
- Record participation when user joins event chat via Socket.IO
- Update GET /api/events to include isJoined flag for current user
- Sort events: joined events first, then by start date
- Add authenticate middleware to GET /api/events

Frontend:
- Replace mock events with real API data from backend
- Add loading and error states to EventsPage
- Display "Joined" badge on events user has joined
- Highlight joined events with colored border
- Show "Open chat" vs "Join chat" button text
- Auto-refresh events list when navigating back

When users join an event chat, this is now recorded in the database.
Joined events appear at the top of the list with visual indicators.
This commit is contained in:
Radosław Gierwiało
2025-11-13 21:18:15 +01:00
parent 897d6e61b3
commit 20f405cab3
5 changed files with 164 additions and 15 deletions

View File

@@ -53,6 +53,7 @@ model User {
matchesAsUser2 Match[] @relation("MatchUser2")
ratingsGiven Rating[] @relation("RaterRatings")
ratingsReceived Rating[] @relation("RatedRatings")
eventParticipants EventParticipant[]
@@map("users")
}
@@ -72,6 +73,7 @@ model Event {
// Relations
chatRooms ChatRoom[]
matches Match[]
participants EventParticipant[]
@@map("events")
}
@@ -153,3 +155,20 @@ model Rating {
@@index([ratedId])
@@map("ratings")
}
// Event participants (tracks which users joined which events)
model EventParticipant {
id Int @id @default(autoincrement())
userId Int @map("user_id")
eventId Int @map("event_id")
joinedAt DateTime @default(now()) @map("joined_at")
// Relations
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
@@unique([userId, eventId])
@@index([userId])
@@index([eventId])
@@map("event_participants")
}