17 Commits
Author SHA1 Message Date
zhutt 02b5e31307 Merge remote-tracking branch 'origin/main' 2026-09-20 22:48:46 +08:00
zhutt 8c048d65e4 0920第一次定义班级表模型 2026-09-20 22:47:53 +08:00
lookerZz ebdfb9016b Merge pull request '添加示例' (#5) from 张昕浩 into main
Reviewed-on: #5
2026-09-20 19:59:33 +08:00
lookerZz 1d085867d6 添加示例 2026-09-20 19:58:44 +08:00
lookerZz 59fe699940 Merge pull request '添加示例' (#4) from 张昕浩 into main
Reviewed-on: #4
2026-09-20 19:47:43 +08:00
lookerZz 03f0761974 添加示例 2026-09-20 19:45:36 +08:00
lookerZz de755c3c26 Merge pull request '添加示例' (#3) from 张昕浩 into main
Reviewed-on: #3
2026-09-20 17:07:37 +08:00
lookerZz 8a131c1b7b 添加示例 2026-09-20 17:06:24 +08:00
lookerZz 71aafe32e9 V1-架构 2026-09-20 04:09:38 +08:00
lookerZz 50b30d6eb0 恢复API 2026-09-20 03:24:49 +08:00
lookerZz 343a4e1532 恢复init文件 2026-09-20 03:24:48 +08:00
lookerZz a96ee13276 提交api 2026-09-20 03:24:16 +08:00
lookerZz f31743d670 删除 api/__init__.py 2026-09-20 03:11:04 +08:00
lookerZz 0f7a0dba2f 文件夹添加 2026-09-20 03:09:13 +08:00
lookerZz 6d76d6af48 初始化库 2026-09-20 02:50:58 +08:00
lookerZz ddbdd3f041 Merge pull request '22' (#2) from nanfangyu into main
Reviewed-on: lookerZz/test2222#2
2026-09-19 18:12:47 +08:00
wolin_nanfangyu_mj e234cd66da Merge pull request 'test22' (#1) from nanfangyu into main
Reviewed-on: lookerZz/test2222#1
2026-09-19 18:11:29 +08:00
47 changed files with 152 additions and 2 deletions
View File
View File
View File
View File
View File
+8
View File
@@ -0,0 +1,8 @@
#这是一个示例文件,确保api端口能被正常调用
from fastapi import APIRouter
example_router = APIRouter()
@example_router.get("/example")
def example():
return {'hello DoubaoTeam'}
View File
View File
View File
View File
+1
View File
@@ -0,0 +1 @@
+6
View File
@@ -0,0 +1,6 @@
"mysql+pymysql://root:123456@localhost/fastapi_db?charset=utf8mb4"
database_connect_user = 'root'
database_connect_password = '123456'
database_connect_ip = 'localhost'
database_connect_database_name = 'student_manager'
+33
View File
@@ -0,0 +1,33 @@
'''
1.此文件已经配置 engine 和 SessionLocal .
由于还没合库,需要自己去 /core/database 配置库名。默认为 student_manager
具体配置如下
用户:root
密码:123456
IP:localhost
库名:student_manager
2.如果还没开始建库,建库时统一将名称命名为 student_manager。
如果已经建库或在 models 目录写好Base函数,那先别提交分支,不然合并的时候会出问题,后天合库的时候再说。
'''
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from .config import (
database_connect_user,
database_connect_password,
database_connect_ip,
database_connect_database_name,
)
engine = create_engine( #engine负责连接mysql
f"mysql+pymysql://{database_connect_user}:{database_connect_password}@{database_connect_ip}/{database_connect_database_name}?charset=utf8mb4",
pool_size=50
)
SessionLocal = sessionmaker(bind=engine, autoflush=False,autocommit=False)
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
+1
View File
@@ -0,0 +1 @@
View File
View File
View File
View File
View File
View File
View File
View File
BIN
View File
Binary file not shown.
-2
View File
@@ -1,2 +0,0 @@
1111
2222
+26
View File
@@ -0,0 +1,26 @@
from fastapi import FastAPI
from api.example import example_router
from middleware import log_middleware
import uvicorn
app = FastAPI()
app.middleware("http")(log_middleware)
#-------------朱婷婷--------------
#-------------李玉杰--------------
#-------------张义---------------
#-------------薄鑫---------------
#-------------张昕浩---------------
app.include_router(example_router)
#-------------曾凯---------------
#-------------南方宇---------------
#-----------主程序----------------
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=23333)
+9
View File
@@ -0,0 +1,9 @@
import time
async def log_middleware(request, call_next):
start_time = time.time()
response = await call_next(request)
end_time = time.time()
cost = end_time - start_time
print(f'{request.method} {request.url.path} cost={cost}')
return response
+1
View File
@@ -0,0 +1 @@
+50
View File
@@ -0,0 +1,50 @@
from sqlalchemy import *
from datetime import datetime,time,date
Base = declarative_base() # 执行函数,返回一个基类
class Classes( Base ): # 在python里的名字
__tablename__ = 'classes' # 在数据库中表的名字
#————创建班级"主键"的字段名————
id = Column( Integer # 声明字段的数据类型是"整数"
, primary_key = True # 声明是"主键"
, autoincrement = True # 声明是"自增主键"
, nullable = False # 声明是"非空"
)
# ————创建班级"编号"的字段名————
class_no = Column( String(50) # 声明字段的数据类型是"字符串,且最长为50个字符"
, unique = True # 声明是"唯一约束"
, nullable = False # 声明是"非空"
)
# ————创建"班级名称"的字段名————
class_name = Column( String(100) # 声明字段的数据类型是"字符串,且最长为100个字符"
, nullable = False # 声明是"非空"
)
# ————创建班级"开课时间"的字段名————
start_date = Column( DATE # 声明是字段数据类型是日期
, nullable = True # 声明是'可为空'
)
# ————创建班级"结课时间"的字段名————
end_date = Column( DATE # 声明是字段数据类型是'日期'
, nullable = True # 声明是"可为空"
)
# ————创建班级"创建时间"的字段名————
created_at = Column( DATETIME # 声明是字段数据类型是"日期时间"
, default=datetime.now # 声明是创建的默认值就是"当前时间"
, nullable = False # 声明是"非空"
)
# ————创建班级"更新时间"的字段名————
update_at = Column( DATETIME # 声明是字段数据类型是"日期时间"
, default=datetime.now #声明是第一次更新的时间就是第一次创建的时间一致
, onupdate=datetime.now # 声明"最后修改的时间"
, nullable = False # 声明是"非空"
)
# ————创建班级"备注信息"的字段名————
remark = Column( String(100) # 声明是字段数据类型是"字符串"
, nullable = True # 声明是"可以为空"
)
# ————创建班级"逻辑删除"的字段名————
is_deleted = Column( INTEGER # 声明是字段数据类型是"数字"
, default = 0 # 声明默认值是"0,未删除"
, nullable = False # 声明是"非空"
)
View File
View File
View File
View File
View File
View File
+5
View File
@@ -0,0 +1,5 @@
fastapi==0.128.0
uvicorn==0.40.0
SQLAlchemy==2.0.49
PyMySQL==1.1.2
pydantic==2.13.3
+1
View File
@@ -0,0 +1 @@
View File
+10
View File
@@ -0,0 +1,10 @@
'''
两种情况:
1.响应成功,响应体设置为SuccessResponse。
2.响应失败,需要主动调用HTTPExpection报错,不然会产生响应码200,响应失败的问题。
'''
from pydantic import BaseModel,Field
from typing import Any
class SuccessResponse(BaseModel):
status_code:int=Field(default=200, ge= 200, lt = 300)
msg: Any=Field(default='OK')
View File
View File
View File
View File
View File
View File
+1
View File
@@ -0,0 +1 @@
View File
View File