docs: API 라우터 분리 및 버전 폴백 시스템 문서화
- api-rules.md: 라우팅 섹션 전면 개편 - 도메인별 라우트 파일 구조 (13개) - ApiVersionMiddleware 설명 - API 버전 폴백 시스템 상세 설명 - system-overview.md: 라우팅 구조 섹션 확장 - 도메인별 분리 구조 다이어그램 - 미들웨어 스택에 ApiVersionMiddleware 추가 - dev-commands.md: 라우트 관리 명령어 추가 - INDEX.md: 2026-01-28 변경 이력 추가 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# SAM API 개발 규칙
|
||||
|
||||
**업데이트**: 2025-11-10
|
||||
**업데이트**: 2026-01-28
|
||||
|
||||
---
|
||||
|
||||
@@ -80,14 +80,68 @@ class YourModel extends Model
|
||||
## 3. Middleware Stack
|
||||
|
||||
- ApiKeyMiddleware, CheckSwaggerAuth, CorsMiddleware, CheckPermission, PermMapper
|
||||
- **ApiVersionMiddleware** - API 버전 선택 및 폴백 처리 (v2 없으면 v1 사용)
|
||||
- Default route group: auth.apikey (some with auth:sanctum)
|
||||
|
||||
---
|
||||
|
||||
## 4. Routing (v1)
|
||||
## 4. Routing
|
||||
|
||||
- Auth, Common codes, Files, Tenants, Users (me/tenants/switch), Menus+Permissions, Roles/Permissions, Departments, Field settings, Options, Categories, Classifications, Products, BOM
|
||||
- REST conventions: index/show/store/update/destroy + extensions (toggle, bulkUpsert, reorder)
|
||||
### 4.1 라우트 파일 구조
|
||||
|
||||
API 라우트는 도메인별로 분리되어 있습니다:
|
||||
|
||||
```
|
||||
routes/api/
|
||||
├── v1/ # v1 API 라우트
|
||||
│ ├── auth.php # 인증 (login, logout, signup, token)
|
||||
│ ├── admin.php # 관리자 (users, global-menus, FCM)
|
||||
│ ├── users.php # 사용자 (me, profiles, invitations, roles)
|
||||
│ ├── tenants.php # 테넌트 (CRUD, settings, stat-fields)
|
||||
│ ├── hr.php # HR (departments, positions, employees, attendances)
|
||||
│ ├── finance.php # 재무 (cards, deposits, withdrawals, payrolls)
|
||||
│ ├── sales.php # 영업 (clients, quotes, orders, pricing)
|
||||
│ ├── inventory.php # 재고 (items, BOM, stocks, shipments)
|
||||
│ ├── production.php # 생산 (processes, work-orders, inspections)
|
||||
│ ├── design.php # 설계 (models, versions, BOM templates)
|
||||
│ ├── files.php # 파일 (upload, download, folders)
|
||||
│ ├── boards.php # 게시판 (boards, posts, comments)
|
||||
│ └── common.php # 공통 (menus, roles, permissions, settings)
|
||||
├── v2/ # v2 API 라우트 (필요시 생성)
|
||||
└── api.php # 라우트 로더
|
||||
```
|
||||
|
||||
### 4.2 API 버전 폴백 시스템
|
||||
|
||||
**버전 선택 방법 (우선순위 순):**
|
||||
1. `Accept-Version` 헤더: `Accept-Version: v2`
|
||||
2. `X-API-Version` 헤더: `X-API-Version: v2`
|
||||
3. `api_version` 쿼리 파라미터: `?api_version=v2`
|
||||
4. 기본값: `v1`
|
||||
|
||||
**폴백 동작:**
|
||||
- v2 요청 시 해당 라우트가 v2에 없으면 자동으로 v1 라우트 사용
|
||||
- 응답 헤더 `X-API-Version`에 실제 사용된 버전 표시
|
||||
|
||||
**사용 예시:**
|
||||
```bash
|
||||
# v1 명시적 요청
|
||||
curl -H "Accept-Version: v1" https://api.sam.kr/api/v1/users
|
||||
|
||||
# v2 요청 (v2 없으면 v1으로 폴백)
|
||||
curl -H "Accept-Version: v2" https://api.sam.kr/api/v1/users
|
||||
|
||||
# 쿼리 파라미터로 버전 지정
|
||||
curl "https://api.sam.kr/api/v1/users?api_version=v2"
|
||||
|
||||
# 버전 미지정 (기본 v1)
|
||||
curl https://api.sam.kr/api/v1/users
|
||||
```
|
||||
|
||||
### 4.3 REST 컨벤션
|
||||
|
||||
- 기본 CRUD: `index`, `show`, `store`, `update`, `destroy`
|
||||
- 확장 메서드: `toggle`, `bulkUpsert`, `reorder`, `stats`, `options`
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user