diff --git a/backend/__init__.py b/backend/__init__.py index 2deb7ea..185e80f 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -1,11 +1,11 @@ from flask import Flask from flask_restx import Api -from backend.apis.account import api as account_ns -from backend.apis.fund import api as fund_ns -from backend.apis.portfolio import api as portfolio_ns -from backend.apis.runtime import api as runtime_ns -from backend.apis.task import api as task_ns +from backend.api.account import api as account_ns +from backend.api.fund import api as fund_ns +from backend.api.portfolio import api as portfolio_ns +from kz_dash.backend.api.runtime import api as runtime_ns +from backend.api.task import api as task_ns from config import API_CONFIG from scheduler.job_manager import JobManager from scheduler.tasks import init_tasks diff --git a/backend/apis/account.py b/backend/api/account.py similarity index 97% rename from backend/apis/account.py rename to backend/api/account.py index 563be0c..739d375 100644 --- a/backend/apis/account.py +++ b/backend/api/account.py @@ -2,7 +2,7 @@ from flask_restx import Namespace, Resource, fields -from backend.apis.common import create_list_response_model, create_response_model +from kz_dash.backend.api.common import create_list_response_model, create_response_model from models.account import ModelAccount, update_account from models.database import delete_record, get_record, get_record_list, update_record from kz_dash.utility.response import format_response diff --git a/backend/apis/fund.py b/backend/api/fund.py similarity index 98% rename from backend/apis/fund.py rename to backend/api/fund.py index d9ac792..2c6b2d3 100644 --- a/backend/apis/fund.py +++ b/backend/api/fund.py @@ -1,6 +1,6 @@ from flask_restx import Namespace, Resource, fields -from backend.apis.common import create_list_response_model, create_response_model +from kz_dash.backend.api.common import create_list_response_model, create_response_model from models.database import ( add_fund_position, delete_record, diff --git a/backend/apis/portfolio.py b/backend/api/portfolio.py similarity index 97% rename from backend/apis/portfolio.py rename to backend/api/portfolio.py index a50610f..4e10def 100644 --- a/backend/apis/portfolio.py +++ b/backend/api/portfolio.py @@ -2,7 +2,7 @@ from flask_restx import Namespace, Resource, fields -from backend.apis.common import create_list_response_model, create_response_model +from kz_dash.backend.api.common import create_list_response_model, create_response_model from models.account import ModelPortfolio from models.database import delete_record, get_record, get_record_list, update_record from kz_dash.utility.response import format_response diff --git a/backend/apis/task.py b/backend/api/task.py similarity index 98% rename from backend/apis/task.py rename to backend/api/task.py index a40b324..3552e13 100644 --- a/backend/apis/task.py +++ b/backend/api/task.py @@ -6,7 +6,7 @@ from flask import request from flask_restx import Namespace, Resource, fields -from backend.apis.common import create_list_response_model, create_response_model +from kz_dash.backend.api.common import create_list_response_model, create_response_model from models.database import get_record_list from models.task import ModelTask from scheduler.job_manager import JobManager diff --git a/backend/apis/common.py b/backend/apis/common.py deleted file mode 100644 index 2ef21a5..0000000 --- a/backend/apis/common.py +++ /dev/null @@ -1,27 +0,0 @@ -from typing import Any - -from flask_restx import Model, fields - - -def create_response_model(api: Any, name: str, data_model: Model) -> Model: - """创建统一的响应模型""" - return api.model( - f"{name}Response", - { - "code": fields.Integer(description="响应代码"), - "message": fields.String(description="响应消息"), - "data": fields.Nested(data_model, description="响应数据"), - }, - ) - - -def create_list_response_model(api: Any, name: str, data_model: Model) -> Model: - """创建统一的列表响应模型""" - return api.model( - f"{name}ListResponse", - { - "code": fields.Integer(description="响应代码"), - "message": fields.String(description="响应消息"), - "data": fields.List(fields.Nested(data_model), description="响应数据列表"), - }, - ) diff --git a/backend/apis/runtime.py b/backend/apis/runtime.py deleted file mode 100644 index dd82146..0000000 --- a/backend/apis/runtime.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import logging -from datetime import datetime - -from flask_restx import Namespace, Resource, fields - -from backend.apis.common import create_response_model -from config import VERSION -from kz_dash.utility.response import format_response - -logger = logging.getLogger(__name__) - -api = Namespace("runtime", description="运行时状态") - -# 记录应用启动时间 -DEPLOY_TIME = datetime.now() - -# 定义基础数据模型 -runtime_base = api.model( - "RuntimeBase", - { - "deploy_time": fields.String(description="部署时间"), - "uptime": fields.String(description="运行时间"), - "version": fields.String(description="版本号"), - }, -) - -# 使用通用函数创建响应模型 -runtime_response = create_response_model(api, "Runtime", runtime_base) - - -@api.route("/status") -class RuntimeStatus(Resource): - @api.doc("获取运行时状态") - @api.marshal_with(runtime_response) - def get(self): - """获取系统运行状态""" - now = datetime.now() - uptime = now - DEPLOY_TIME - - # 计算运行时间 - total_seconds = uptime.total_seconds() - days = int(total_seconds // (24 * 3600)) - hours = int((total_seconds % (24 * 3600)) // 3600) - minutes = int((total_seconds % 3600) // 60) - seconds = int(total_seconds % 60) - - return format_response( - data={ - "deploy_time": DEPLOY_TIME.strftime("%Y-%m-%d %H:%M:%S"), - "uptime": f"{days}天{hours}时{minutes}分{seconds}秒", - "version": VERSION, - }, - message="获取运行时状态成功", - ) diff --git a/kz_dash b/kz_dash index 3f3ef41..68038f2 160000 --- a/kz_dash +++ b/kz_dash @@ -1 +1 @@ -Subproject commit 3f3ef41b6ca3c7d8793d53f30d9b9b2772a1ad55 +Subproject commit 68038f2ac228538c1e20cb886697b9b4f7261630