AnlaAnla 1 сар өмнө
parent
commit
d332500389

+ 7 - 0
.idea/dataSources.xml

@@ -8,5 +8,12 @@
       <jdbc-url>jdbc:mysql://localhost:3306</jdbc-url>
       <working-dir>$ProjectFileDir$</working-dir>
     </data-source>
+    <data-source source="LOCAL" name="服务器1" uuid="d455fdf3-b4f3-466c-b306-d62db890c85e">
+      <driver-ref>mariadb</driver-ref>
+      <synchronize>true</synchronize>
+      <jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
+      <jdbc-url>jdbc:mariadb://192.168.31.243:3306</jdbc-url>
+      <working-dir>$ProjectFileDir$</working-dir>
+    </data-source>
   </component>
 </project>

+ 2 - 0
.idea/encodings.xml

@@ -2,6 +2,8 @@
 <project version="4">
   <component name="Encoding">
     <file url="file://$PROJECT_DIR$/Test/test01.py" charset="GBK" />
+    <file url="file://$PROJECT_DIR$/app/api/cards.py" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/app/api/images.py" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/app/utils/scheme.py" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/run.py" charset="UTF-8" />
     <file url="PROJECT" charset="GBK" />

+ 0 - 6
.idea/sqldialects.xml

@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="SqlDialectMappings">
-    <file url="file://$PROJECT_DIR$/app/api/image_data.py" dialect="GenericSQL" />
-  </component>
-</project>

+ 25 - 13
Test/test01.py

@@ -1,27 +1,39 @@
-# -*- coding: utf-8 -*-
 import requests
 
-url = 'http://192.168.31.243:7745/api/image_data/data_list'
+# 基础 URL
+base_url = 'http://192.168.31.243:7745/api/cards/card_list'
+
+# 查询参数 (query parameters)
 params = {
-    'start_id': 5,
-    'end_id': 9,
     'skip': 0,
     'limit': 100
 }
+
+# 请求头 (headers)
 headers = {
     'accept': 'application/json'
 }
 
-
-
 try:
-    response = requests.get(url, params=params, headers=headers)
+    # 发送 GET 请求
+    response = requests.get(base_url, params=params, headers=headers)
+
+    # 检查响应状态码
     response.raise_for_status()
 
-    # 打印响应内容
-    print("Status Code:", response.status_code)
-    print("Response JSON:", response.json()) # 如果响应是JSON格式
-    # print("Response Text:", response.text) # 如果响应是纯文本
+    # 打印响应内容 (JSON格式)
+    data = response.json()
+    print("Success! Response Data:")
+    print(data)
+
+    # 打印状态码
+    print(f"Status Code: {response.status_code}")
 
-except requests.exceptions.RequestException as e:
-    print(f"An error occurred: {e}")
+except requests.exceptions.HTTPError as errh:
+    print(f"Http Error: {errh}")
+except requests.exceptions.ConnectionError as errc:
+    print(f"Error Connecting: {errc}")
+except requests.exceptions.Timeout as errt:
+    print(f"Timeout Error: {errt}")
+except requests.exceptions.RequestException as err:
+    print(f"An Error Occurred: {err}")

+ 1 - 1
app/api/images.py

@@ -30,8 +30,8 @@ async def upload_image_for_card(
         card_id: int = Path(..., description="要关联的卡牌ID"),
         image_type: ImageType = Form(..., description="图片类型 (front_face, back_face, etc.)"),
         image: UploadFile = File(..., description="图片文件"),
-        json_data_str: str = Form(..., description="与图片关联的JSON字符串"),
         image_name: Optional[str] = Form(None, description="图片的可选名称"),
+        json_data_str: str = Form(..., description="与图片关联的JSON字符串"),
         db_conn: PooledMySQLConnection = db_dependency
 ):
     """

+ 11 - 2
app/main.py

@@ -1,11 +1,12 @@
 
 from fastapi import FastAPI
+from fastapi.middleware.cors import CORSMiddleware
 from contextlib import asynccontextmanager
 import os
 
 from .core.database_loader import init_database, load_database_pool, close_database_pool
-from app.api import cards as cards_router # 导入新路由
-from app.api import images as images_router # 导入新路由
+from app.api import cards as cards_router
+from app.api import images as images_router
 from .core.config import settings
 from .core.logger import setup_logging, get_logger
 
@@ -25,5 +26,13 @@ async def lifespan(main_app: FastAPI):
 
 app = FastAPI(title="卡片分数数据存储服务", lifespan=lifespan)
 
+app.add_middleware(
+    CORSMiddleware,
+    allow_origins=["*"],
+    allow_credentials=True,
+    allow_methods=["*"],
+    allow_headers=["*"]
+)
+
 app.include_router(cards_router.router, prefix=f"{settings.API_PREFIX}/cards", tags=["Cards"])
 app.include_router(images_router.router, prefix=f"{settings.API_PREFIX}/images", tags=["Images"])