From be75d8d3fafe3d9fe532572ff07bee1eb0e50db9 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Fri, 10 Jan 2025 00:26:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E6=8D=A2=E8=85=BE=E8=AE=AF=E4=BA=91?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 ++- app/api/endpoints/merchant.py | 20 +++++++++++++------- app/core/config.py | 15 +++++++++++---- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 19b8f98..5a0476c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,8 @@ COPY requirements.txt . COPY app app/ # 安装Python依赖 -RUN pip install --no-cache-dir -r requirements.txt +RUN pip install --no-cache-dir -r requirements.txt \ + && pip install --no-cache-dir uvicorn # 暴露端口 EXPOSE 8000 diff --git a/app/api/endpoints/merchant.py b/app/api/endpoints/merchant.py index 7f95215..9959a06 100644 --- a/app/api/endpoints/merchant.py +++ b/app/api/endpoints/merchant.py @@ -1,6 +1,6 @@ from fastapi import APIRouter, Depends from sqlalchemy.orm import Session -from typing import List, Optional +from typing import List, Optional, Dict, Any from sqlalchemy import text from app.models.merchant import ( MerchantDB, @@ -127,16 +127,22 @@ async def list_merchants( text("distance") ).offset(skip).limit(limit).all() - return success_response(data=[{ + merchant_list = [{ **MerchantInfo.model_validate(m[0]).model_dump(), "distance": round(m[1]) # 四舍五入到整数米 - } for m in merchants]) + } for m in merchants] else: # 如果没有提供经纬度,按创建时间排序 merchants = db.query(MerchantDB).order_by( MerchantDB.create_time.desc() ).offset(skip).limit(limit).all() - - return success_response(data=[ - MerchantInfo.model_validate(m) for m in merchants - ]) \ No newline at end of file + + merchant_list = [MerchantInfo.model_validate(m) for m in merchants] + + # 获取总数 + total = db.query(MerchantDB).count() + + return success_response(data={ + "total": total, + "items": merchant_list + }) \ No newline at end of file diff --git a/app/core/config.py b/app/core/config.py index e176774..4f99624 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -27,11 +27,18 @@ class Settings(BaseSettings): UNI_SMS_SIGN: str = "BAISIJI" # 短信签名 # MySQL配置 - MYSQL_HOST: str = "101.36.120.145" - MYSQL_PORT: int = 3306 + # MYSQL_HOST: str = "101.36.120.145" + # MYSQL_PORT: int = 3306 + # MYSQL_USER: str = "root" + # MYSQL_PASSWORD: str = "mariadb_4rMwpT" + # MYSQL_DB: str = "deliveryman" + + MYSQL_HOST: str = "gz-cynosdbmysql-grp-2j1cnopr.sql.tencentcdb.com" + MYSQL_PORT: int = 27469 MYSQL_USER: str = "root" - MYSQL_PASSWORD: str = "mariadb_4rMwpT" - MYSQL_DB: str = "deliveryman" + MYSQL_PASSWORD: str = "Aa#223388" + MYSQL_DB: str = "beefastapp" + @property def SQLALCHEMY_DATABASE_URL(self) -> str: