Files
daily_stock_analysis/api/deps.py
Krane 9847157980 Feature/React web support 新的WebUI (#256)
* feat(web): add FastAPI & React web connect

* feat: add FastAPI package

* feat: system base struct

* feat: frontend base struct

* feat: 基础分析接口,历史记录接口

* fix: 使用正确的 FastAPI 方法定义,避免线程阻塞

* fix: 对接历史报告页、详情页

* fix: 修复接口问题

* fix: 网络配置 允许公网访问 跨域配置

* fix: 页面打包 & 提供 Server 静态访问

* fix: 优化dock栏样式

* fix: 优化图标样式

* fix: 修改部分配色

* fix: 删除垃圾文档

* fix: 删除垃圾代码

* fix: 驼峰转换工具

* fix: 历史记录列表滚动加载(分页)

* feat: 显示分析中任务

* fix: 调整布局

* fix: 优化 Market Sentiment 组件动效

* fix: 历史列表组件bug

* fix: FastAPI 日志配置

* feat: 新闻历史接口

* feat: 资讯列表

* feat: 优化布局

* fix: 修复页面元素变宽问题

* fix: 中文标题

* fix: 任务列表状态显示问题

* fix: 抽取日志配置

* fix: 优化报告价格显示

* fix: 修复编译错误

* fix: FastAPI 启动提取到 main.py

* fix: 补充新web-ui启动文档

* fix: 默认发送通知

* fix: FastAPI 模式适配 docker

* fix: FastAPI 模式文档

* Update api/v1/endpoints/stocks.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix: package-lock.json

* fix: 修改错别字

* fix: 更新文档说明

* fix: 更新文档说明

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-05 20:56:38 +08:00

61 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
"""
===================================
API 依赖注入模块
===================================
职责:
1. 提供数据库 Session 依赖
2. 提供配置依赖
3. 提供服务层依赖
"""
from typing import Generator
from sqlalchemy.orm import Session
from src.storage import DatabaseManager
from src.config import get_config, Config
def get_db() -> Generator[Session, None, None]:
"""
获取数据库 Session 依赖
使用 FastAPI 依赖注入机制,确保请求结束后自动关闭 Session
Yields:
Session: SQLAlchemy Session 对象
Example:
@router.get("/items")
async def get_items(db: Session = Depends(get_db)):
...
"""
db_manager = DatabaseManager.get_instance()
session = db_manager.get_session()
try:
yield session
finally:
session.close()
def get_config_dep() -> Config:
"""
获取配置依赖
Returns:
Config: 配置单例对象
"""
return get_config()
def get_database_manager() -> DatabaseManager:
"""
获取数据库管理器依赖
Returns:
DatabaseManager: 数据库管理器单例对象
"""
return DatabaseManager.get_instance()