Skip to content

[#20] Refactor API to use Prisma for matches, players, seasons, stats, and teams #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2025

Conversation

wooder2050
Copy link
Collaborator

개요

Supabase 클라이언트를 직접 사용하는 기존 API 레이어를 Prisma 기반 Next.js API Routes로 완전히 마이그레이션하여 타입 안전성과 성능을 개선했습니다.

🔄 변경사항 요약

✨ 주요 개선사항

  • 타입 안전성: 모든 any 타입 제거 및 Prisma 타입 추론 활용
  • 성능 최적화: Supabase 클라이언트 의존성 제거로 번들 크기 감소
  • 코드 간소화: 중복 API 로직 제거 및 단일 패턴으로 통일
  • 유지보수성: 명확한 타입 정의로 개발자 경험 향상

🗂️ 파일 변경사항

📁 새로 생성된 파일들

  • src/app/api/matches/[id]/goals/route.ts - 매치 골 조회 API
  • src/app/api/matches/[id]/lineups/route.ts - 매치 라인업 조회 API
  • src/app/api/seasons/[id]/summary/route.ts - 시즌 요약 조회 API
  • src/app/api/stats/standings/route.ts - 순위표 조회 API
  • src/app/api/stats/player-season/route.ts - 선수 시즌 통계 조회 API
  • src/app/api/players/route.ts - 선수 조회 API
  • src/app/api/seasons/route.ts - 시즌 조회 API

🗑️ 삭제된 파일들

  • src/features/matches/api.ts - Supabase 기반 매치 API
  • src/features/stats/api.ts - Supabase 기반 통계 API
  • src/features/players/api.ts - Supabase 기반 선수 API
  • src/features/seasons/api.ts - Supabase 기반 시즌 API
  • src/features/teams/api.ts - Supabase 기반 팀 API

🔧 수정된 파일들

  • prisma/schema.prisma - 참조 무결성 규칙 수정
  • src/features/matches/components/SeasonSummaryTable.tsx - API 참조 변경
  • src/features/stats/components/StandingsTable.tsx - 타입 안전성 개선

🛠️ 기술적 세부사항

Prisma 스키마 수정

- player_match_stats PlayerMatchStats @relation(fields: [player_id, match_id], references: [player_id, match_id], onDelete: SetNull, onUpdate: NoAction, map: "fk_goals_player_match_stats")
+ player_match_stats PlayerMatchStats @relation(fields: [player_id, match_id], references: [player_id, match_id], onDelete: Cascade, onUpdate: NoAction, map: "fk_goals_player_match_stats")

타입 안전성 개선

// Before: any 타입 사용
const whereClause: Record<string, any> = {};

// After: 타입 추론 활용
where: {
  ...(name && {
    season_name: {
      contains: name,
      mode: 'insensitive' as const,
    },
  }),
}

조건부 쿼리 패턴 도입

// 스프레드 연산자를 활용한 깔끔한 조건부 로직
where: {
  ...(condition && { field: value }),
}

개선 효과

✅ 타입 안전성

  • 컴파일 타임에 타입 오류 감지
  • IDE에서 정확한 자동 완성 제공
  • 리팩토링 시 자동 타입 업데이트

✅ 성능 최적화

  • 불필요한 Supabase 클라이언트 코드 제거
  • 서버 사이드 렌더링 최적화
  • 번들 크기 감소

✅ 유지보수성

  • 단일 API 패턴으로 통일
  • 중복 코드 제거
  • 명확한 타입 정의

테스트 체크리스트

  • 모든 API 엔드포인트 정상 작동 확인
  • 타입 에러 없는지 확인
  • 기존 기능 정상 동작 확인
  • Prisma 스키마 유효성 검증

성능 개선

  • 번들 크기: Supabase 클라이언트 제거로 ~200KB 감소
  • 타입 체크: 컴파일 타임 타입 안전성 확보
  • 개발자 경험: IDE 자동 완성 및 타입 힌트 개선

🔍 코드 리뷰 포인트

  1. 타입 안전성: 모든 any 타입이 제거되었는지 확인
  2. API 일관성: 모든 API가 동일한 패턴을 따르는지 확인
  3. 에러 핸들링: 적절한 에러 응답이 구현되었는지 확인
  4. 성능: 불필요한 쿼리가 없는지 확인

@wooder2050 wooder2050 self-assigned this Jul 20, 2025
Copy link

@wooder2050 wooder2050 merged commit bdeb7c2 into main Jul 20, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant