Conversation
There was a problem hiding this comment.
Pull request overview
参加登録済みイベント一覧で「参加していないイベントまで表示される」不具合(Issue #2)を修正し、ログイン中ユーザーが参加登録しているイベントのみ取得するように変更するPRです。
Changes:
Event.findByAtendeeUserId()を追加し、EventAttendee経由で指定ユーザーの参加イベントのみ取得するクエリを実装- 参加登録済みイベント一覧コンポーネントを
Event.findAll()からEvent.findByAtendeeUserId(userId)に切り替え - 未ログイン時は空配列を返し、一覧に何も表示しない挙動に変更
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/lib/event.ts | 参加者(EventAttendee / participants)で絞り込んだイベント取得APIを追加 |
| src/components/AtendedEventList.tsx | セッションからユーザーIDを取得し、参加登録済みイベントのみ表示するように変更 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const events = await prisma.event.findMany({ | ||
| where: { | ||
| ...(status ? { status: { in: status } } : {}), | ||
| participants: { | ||
| some: { | ||
| userId, | ||
| status: { in: atendeeStatuses }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| return events.map( | ||
| (event) => | ||
| new Event({ | ||
| id: event.id, | ||
| title: event.title, | ||
| description: event.description || undefined, | ||
| date: event.date, | ||
| startAt: event.startTime || undefined, | ||
| endAt: event.endTime || undefined, | ||
| registrationDeadline: event.registrationDeadline || undefined, | ||
| capacity: event.capacity || undefined, | ||
| location: event.location || undefined, | ||
| status: event.status as EventStatus, | ||
| createdAt: event.createdAt || undefined, | ||
| updatedAt: event.updatedAt || undefined, | ||
| }), | ||
| ); |
There was a problem hiding this comment.
findByAtendeeUserId duplicates the same Prisma->Event mapping logic already used in create / findById / findAll. Adding another copy increases the chance of future drift when fields are added/renamed. Consider extracting a shared converter (e.g., a private fromDb(event) helper) and reusing it here and in the existing find methods.
| const session = await auth.api.getSession({ | ||
| headers: await headers(), | ||
| }); | ||
| const userId = session?.user?.id; | ||
| const events = userId ? await Event.findByAtendeeUserId(userId) : []; |
There was a problem hiding this comment.
AttendedEventList fetches the session itself. On pages that already call auth.api.getSession() (e.g. src/app/events/attended/page.tsx), this results in duplicate session lookups per request. Consider passing userId (or the session) into this component when available and only calling getSession as a fallback when the prop isn’t provided.
3fb96fa to
e4d6201
Compare
Issue
#2
変更内容
event.tsにEvent.findByAtendeeUserId()を追加し、EventAttendee経由で「指定ユーザーが参加登録しているイベントのみ」を取得するクエリを実装。
AtendedEventList.tsxでauth.api.getSession()を使ってユーザーIDを取得し、Event.findByAtendeeUserId(userId)に切り替え。未ログイン時は空配列を返すように変更。