feat: Airwallex 发卡管理后台完整实现
- 后端: FastAPI + SQLAlchemy + SQLite, JWT认证, 代理支持的AirwallexClient - 前端: React 18 + Vite + Ant Design 5, 中文界面 - 功能: 卡片管理, 持卡人管理, 交易记录, API令牌, 系统设置, 审计日志 - 第三方API: X-API-Key认证, 权限控制 - Docker部署: docker-compose编排前后端
This commit is contained in:
0
backend/app/models/__init__.py
Normal file
0
backend/app/models/__init__.py
Normal file
67
backend/app/models/db_models.py
Normal file
67
backend/app/models/db_models.py
Normal file
@@ -0,0 +1,67 @@
|
||||
"""SQLAlchemy ORM models for the application database."""
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, Integer, String, Text, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from ..database import Base
|
||||
|
||||
|
||||
class SystemSetting(Base):
|
||||
"""Stores application-level configuration key-value pairs."""
|
||||
|
||||
__tablename__ = "system_settings"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
key: Mapped[str] = mapped_column(String(255), unique=True, nullable=False, index=True)
|
||||
value: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
encrypted: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=func.now(), onupdate=func.now()
|
||||
)
|
||||
|
||||
|
||||
class ApiToken(Base):
|
||||
"""API tokens for programmatic access."""
|
||||
|
||||
__tablename__ = "api_tokens"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
token: Mapped[str] = mapped_column(String(512), unique=True, nullable=False, index=True)
|
||||
permissions: Mapped[str] = mapped_column(Text, default="[]") # JSON string
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
||||
expires_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
last_used_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
|
||||
|
||||
class CardLog(Base):
|
||||
"""Logs for card-related operations."""
|
||||
|
||||
__tablename__ = "card_logs"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
card_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
cardholder_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
action: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
status: Mapped[str] = mapped_column(String(50), nullable=False)
|
||||
operator: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
request_data: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
response_data: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
||||
|
||||
|
||||
class AuditLog(Base):
|
||||
"""General audit trail for all administrative actions."""
|
||||
|
||||
__tablename__ = "audit_logs"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
action: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
resource_type: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
resource_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
operator: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
ip_address: Mapped[str | None] = mapped_column(String(45), nullable=True)
|
||||
details: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
||||
148
backend/app/models/schemas.py
Normal file
148
backend/app/models/schemas.py
Normal file
@@ -0,0 +1,148 @@
|
||||
"""Pydantic schemas for request/response validation."""
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# --- Auth ---
|
||||
|
||||
class LoginRequest(BaseModel):
|
||||
username: str
|
||||
password: str
|
||||
|
||||
|
||||
class TokenResponse(BaseModel):
|
||||
access_token: str
|
||||
token_type: str = "bearer"
|
||||
|
||||
|
||||
# --- System Settings ---
|
||||
|
||||
class SystemSettingUpdate(BaseModel):
|
||||
key: str
|
||||
value: str
|
||||
|
||||
|
||||
class SystemSettingResponse(BaseModel):
|
||||
key: str
|
||||
value: str
|
||||
updated_at: datetime | None = None
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
# --- API Tokens ---
|
||||
|
||||
class ApiTokenCreate(BaseModel):
|
||||
name: str
|
||||
permissions: list[str] = Field(default_factory=list)
|
||||
expires_in_days: int | None = None
|
||||
|
||||
|
||||
class ApiTokenResponse(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
token: str | None = None # Only shown on create
|
||||
permissions: list[str] = Field(default_factory=list)
|
||||
is_active: bool
|
||||
created_at: datetime | None = None
|
||||
expires_at: datetime | None = None
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
# --- Logs ---
|
||||
|
||||
class CardLogResponse(BaseModel):
|
||||
id: int
|
||||
card_id: str | None = None
|
||||
cardholder_id: str | None = None
|
||||
action: str
|
||||
status: str
|
||||
operator: str
|
||||
request_data: str | None = None
|
||||
response_data: str | None = None
|
||||
created_at: datetime | None = None
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class AuditLogResponse(BaseModel):
|
||||
id: int
|
||||
action: str
|
||||
resource_type: str
|
||||
resource_id: str | None = None
|
||||
operator: str
|
||||
ip_address: str | None = None
|
||||
details: str | None = None
|
||||
created_at: datetime | None = None
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
# --- Dashboard ---
|
||||
|
||||
class DashboardResponse(BaseModel):
|
||||
total_cards: int = 0
|
||||
active_cards: int = 0
|
||||
today_card_count: int = 0
|
||||
daily_card_limit: int = 0
|
||||
account_balance: dict[str, Any] | None = None
|
||||
|
||||
|
||||
# --- Cards ---
|
||||
|
||||
class CardCreateRequest(BaseModel):
|
||||
cardholder_id: str
|
||||
card_nickname: str | None = None
|
||||
authorization_controls: dict[str, Any] | None = None
|
||||
form_factor: str = "VIRTUAL"
|
||||
purpose: str | None = None
|
||||
|
||||
|
||||
class CardUpdateRequest(BaseModel):
|
||||
card_nickname: str | None = None
|
||||
authorization_controls: dict[str, Any] | None = None
|
||||
status: str | None = None
|
||||
|
||||
|
||||
# --- Cardholders ---
|
||||
|
||||
class CardholderCreateRequest(BaseModel):
|
||||
email: str
|
||||
type: str = "INDIVIDUAL"
|
||||
individual: dict[str, Any] = Field(
|
||||
...,
|
||||
description="Individual details: first_name, last_name, date_of_birth, etc.",
|
||||
)
|
||||
address: dict[str, Any] = Field(
|
||||
...,
|
||||
description="Address: street_address, city, state, postcode, country_code.",
|
||||
)
|
||||
|
||||
|
||||
# --- Pagination ---
|
||||
|
||||
class PaginatedResponse(BaseModel):
|
||||
items: list[Any]
|
||||
page_num: int = 0
|
||||
page_size: int = 20
|
||||
total: int | None = None
|
||||
has_more: bool = False
|
||||
|
||||
|
||||
# --- External / Third-party ---
|
||||
|
||||
class ExternalCardCreateRequest(BaseModel):
|
||||
cardholder_id: str
|
||||
card_nickname: str | None = None
|
||||
authorization_controls: dict[str, Any] | None = None
|
||||
form_factor: str = "VIRTUAL"
|
||||
purpose: str | None = None
|
||||
|
||||
|
||||
# --- Balance ---
|
||||
|
||||
class BalanceResponse(BaseModel):
|
||||
available: list[dict[str, Any]] = Field(default_factory=list)
|
||||
Reference in New Issue
Block a user