feat: add portfolio ownership model, auth guards, and migration
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
# API Contracts
|
||||
|
||||
- Related REQ: `REQ-001`, `REQ-002`, `REQ-003`
|
||||
- Related REQ: `REQ-001`, `REQ-002`, `REQ-003`, `REQ-004`
|
||||
|
||||
## 공통 원칙
|
||||
- 응답은 JSON 기반으로 반환한다.
|
||||
- 인증이 필요한 엔드포인트는 `Authorization: Bearer <token>`을 사용한다.
|
||||
- 권한 계층은 `read` < `trade-write` < `admin`이다.
|
||||
- `admin`이 아닌 요청은 포트폴리오 리소스 접근 시 `owner_user_id` 소유권 검사를 추가로 통과해야 한다.
|
||||
- 에러 응답은 HTTP 상태 코드와 함께 원인 메시지를 제공한다.
|
||||
- Base URL 예시는 `http://localhost:8000`을 기준으로 한다.
|
||||
- JSON 예시는 대표 형태이며 일부 선택 필드를 생략할 수 있다.
|
||||
@@ -95,6 +96,7 @@
|
||||
|
||||
#### `GET /portfolios`
|
||||
- Auth: `read`
|
||||
- Ownership: `admin`은 전체 조회, 그 외는 본인 소유(`owner_user_id == auth_context.user_id`)만 조회
|
||||
- Query:
|
||||
- `broker: string | null`
|
||||
- `status_filter: string | null`
|
||||
@@ -131,6 +133,7 @@ curl -X GET "http://localhost:8000/portfolios?broker=upbit&status_filter=enabled
|
||||
|
||||
#### `GET /portfolios/{portfolio_id}`
|
||||
- Auth: `read`
|
||||
- Ownership: `admin`이 아니고 소유주 불일치 시 `403`
|
||||
- Query:
|
||||
- `recent_trades: int = 5`
|
||||
- 응답 `200`: `PortfolioDetailResponse`
|
||||
@@ -148,6 +151,7 @@ curl -X GET "http://localhost:8000/portfolios/krw-btc?recent_trades=5" \
|
||||
"status": "enabled",
|
||||
"name": "Bitcoin",
|
||||
"symbol": "KRW-BTC",
|
||||
"owner_user_id": "user-1",
|
||||
"cash_balance": 1000000.0,
|
||||
"asset_quantity": 0.1,
|
||||
"price": 100000000.0,
|
||||
@@ -188,6 +192,7 @@ curl -X GET "http://localhost:8000/portfolios/krw-btc?recent_trades=5" \
|
||||
|
||||
#### `POST /portfolios`
|
||||
- Auth: `trade-write`
|
||||
- Ownership: 요청 body로 owner를 받지 않고 인증 컨텍스트 사용자로 `owner_user_id`를 강제 설정
|
||||
- Body: `CreatePortfolioRequest`
|
||||
- 응답 `201`: `PortfolioDetailResponse`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user