尝试合并,所有代码需要调整from后文件路径。
This commit is contained in:
@@ -6,9 +6,9 @@ from students.model.students_model import *
|
||||
from students.schema.students_request import *
|
||||
from students.databases import *
|
||||
|
||||
students_api = APIRouter()
|
||||
s_api = APIRouter()
|
||||
|
||||
@students_api.get("/students"
|
||||
@s_api.get("/students"
|
||||
,summary='学生资料查询'
|
||||
,description=f'筛选条件全为空即查询所有学生资料,输入薪资会查询大于输入薪资以上的学生。\n '
|
||||
f'时间格式:YYYY-MM-DD'
|
||||
@@ -24,7 +24,7 @@ def get_students( stu:StudentsQuery = Depends()
|
||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||
|
||||
|
||||
@students_api.post("/students"
|
||||
@s_api.post("/students"
|
||||
,summary='新增学生资料'
|
||||
,description=f'学生ID自动分配,学生姓名、学生手机号和班级是必填项,不能为空。\n '
|
||||
f'时间格式:YYYY-MM-DD'
|
||||
@@ -38,7 +38,7 @@ def add_student( stu:StudentsResponse = Depends()
|
||||
raise HTTPException(status_code=500, detail='手机号已有学生使用或必填项为空。')
|
||||
return result
|
||||
|
||||
@students_api.put("/students"
|
||||
@s_api.put("/students"
|
||||
,summary='学生资料更新'
|
||||
,description=f'请输入需要更新信息的学生ID,学生手机号不可重复,填写即更新,为空即不更新。\n '
|
||||
f'时间格式:YYYY-MM-DD'
|
||||
@@ -52,7 +52,7 @@ def get_students( stu:StudentsUpdate = Depends()
|
||||
raise HTTPException(status_code=500, detail='手机号已有学生使用。')
|
||||
return result
|
||||
|
||||
@students_api.delete("/students"
|
||||
@s_api.delete("/students"
|
||||
,summary='删除学生资料'
|
||||
,description=f'输入需要删除的学生信息,删除条件任选,但不可全为空,工资筛选能删除大于等于输入工资的所有人。\n '
|
||||
f'时间格式:YYYY-MM-DD'
|
||||
|
||||
+11
-1
@@ -3,7 +3,17 @@
|
||||
from sqlalchemy import *
|
||||
from sqlalchemy.orm import sessionmaker,declarative_base
|
||||
|
||||
db_url = "mysql+pymysql://root:420821@localhost:3306/student_manage_system?charset=utf8mb4"
|
||||
# 导入.env参数
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv( )
|
||||
DB_USER = os.getenv("DB_USER", "root")
|
||||
DB_PASSWORD = os.getenv("DB_PASSWORD", "")
|
||||
DB_HOST = os.getenv("DB_HOST", "localhost")
|
||||
DB_PORT = os.getenv("DB_PORT", "3306")
|
||||
DB_NAME = os.getenv("DB_NAME", "student_manage_system")
|
||||
|
||||
db_url = f"mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}?charset=utf8mb4"
|
||||
|
||||
engine1 = create_engine(db_url)
|
||||
|
||||
|
||||
+8
-7
@@ -1,9 +1,11 @@
|
||||
from fastapi import FastAPI
|
||||
from students.api.students_api import students_api
|
||||
from fastapi import FastAPI,APIRouter
|
||||
from students.api.students_api import s_api
|
||||
from students.databases import *
|
||||
from students.model import students_model
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
Students_API = APIRouter()
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
Base.metadata.create_all(engine1)
|
||||
@@ -12,14 +14,13 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
app = FastAPI(title="学生管理系统",lifespan=lifespan) # 这里必须把上面写的加上
|
||||
|
||||
app.include_router(students_api,tags=["students"])
|
||||
|
||||
|
||||
def main():
|
||||
print("Hello from student-manage-system!")
|
||||
app.include_router(s_api,tags=["students"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
def main():
|
||||
print("Hello from student-manage-system!")
|
||||
|
||||
import uvicorn
|
||||
uvicorn.run("main:app", host="0.0.0.0", port=51000)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user