Fundamental_Analysis/services/data-persistence-service
Lv, Qi 0c975bb8f1 Refactor: Remove legacy analysis results and implement workflow history
- **Common Contracts**: Updated DTOs and models to support workflow history; removed legacy analysis result DTOs.
- **Data Persistence Service**:
    - Removed `analysis_results` table logic and API endpoints.
    - Implemented `workflow_history` API and DB access (`history.rs`).
    - Fixed compilation errors and updated tests.
    - Exposed Postgres port in `docker-compose.yml` for easier debugging/offline checks.
- **API Gateway**:
    - Implemented `history` endpoints (get history list, get by ID).
    - Removed legacy `analysis-results` endpoints.
    - Fixed routing and handler logic in `api.rs`.
- **Report Generator Service**:
    - Removed dependency on legacy `analysis-results` persistence calls.
    - Fixed compilation errors.
- **Workflow Orchestrator**: Fixed warnings and minor logic issues.
- **Providers**: Updated provider services (alphavantage, tushare, finnhub, yfinance, mock) to align with contract changes.
- **Frontend**:
    - Updated `ReportPage` and stores to use new workflow history.
    - Added `RecentReportsDropdown` component.
    - Cleaned up `RealtimeLogs` component.
- **Documentation**: Moved completed design tasks to `completed/` and added refactoring context docs.

Confirmed all services pass `cargo check`.
2025-11-29 14:46:44 +08:00
..
.cargo feat(realtime): 接入前端实时报价并完善后端缓存 2025-11-09 05:12:14 +08:00
.sqlx Refactor E2E tests and improve error handling in Orchestrator 2025-11-21 20:44:32 +08:00
assets feat(realtime): 接入前端实时报价并完善后端缓存 2025-11-09 05:12:14 +08:00
src Refactor: Remove legacy analysis results and implement workflow history 2025-11-29 14:46:44 +08:00
tests Refactor: Remove legacy analysis results and implement workflow history 2025-11-29 14:46:44 +08:00
Cargo.lock Refactor: Remove legacy analysis results and implement workflow history 2025-11-29 14:46:44 +08:00
Cargo.toml feat: implement API DTO export and verify E2E tests 2025-11-22 22:14:01 +08:00
Dockerfile Refactor: Remove legacy analysis results and implement workflow history 2025-11-29 14:46:44 +08:00
env.sample feat(realtime): 接入前端实时报价并完善后端缓存 2025-11-09 05:12:14 +08:00
README.md feat(realtime): 接入前端实时报价并完善后端缓存 2025-11-09 05:12:14 +08:00

数据持久化服务 (Data Persistence Service)

本服务是“基本面分析”微服务架构中数据库的唯一所有者,为所有数据持久化需求提供一个 RESTful API。

概览

  • 语言: Rust
  • 框架: Axum
  • 数据库: PostgreSQL (带有 TimescaleDB 扩展)
  • 核心任务: 为数据库提供一个稳定、高性能且类型安全的 API 层。

本地开发指南

1. 先决条件

  • Rust 工具链 (rustup)
  • sqlx-cli (cargo install sqlx-cli)
  • 一个正在运行的、并已启用 TimescaleDB 扩展的 PostgreSQL 实例。

2. 配置

env.sample 文件复制为 .env,并根据您的本地环境配置 DATABASE_URL

cp env.sample .env

您的 .env 文件应如下所示:

# 服务监听的端口
PORT=3000

# 用于 sqlx 连接数据库的 URL
# 请确保用户、密码、主机、端口和数据库名称都正确无误
DATABASE_URL=postgres://user:password@localhost:5432/fundamental_analysis

3. 数据库迁移

在首次运行本服务之前,或在任何数据库结构变更之后,请运行迁移命令以更新数据库:

sqlx migrate run

4. 运行服务

编译并运行本服务:

cargo run

服务将会启动并在您 .env 文件中指定的端口(默认为 3000上监听。服务的 OpenAPI 规范 (Swagger JSON) 将在 /api-docs/openapi.json 路径下可用。

测试

要运行所有测试(包括数据库集成测试和 API 集成测试),请使用以下命令。请确保您的 .env 文件中的 DATABASE_URL 指向一个有效的、已应用迁移的测试数据库。

cargo test

如果需要查看详细的测试输出,可以使用:

cargo test -- --nocapture