更新所有模块框架,建表已写好,学生查询模块已经写好,正在写新增模块。
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
# students_api所有students的api路由、接口
|
||||
|
||||
from fastapi import APIRouter , Depends , HTTPException
|
||||
from students.dao.students_dao import *
|
||||
from students.model.students_model import *
|
||||
from students.schema.students_request import *
|
||||
from students.databases import *
|
||||
|
||||
students_api = APIRouter()
|
||||
|
||||
@students_api.get("/students/"
|
||||
,summary='学生资料查询'
|
||||
,description='筛选条件全为空即查询所有学生资料,输入薪资会查询大于输入薪资以上的学生'
|
||||
,response_model=StudentsQuery
|
||||
)
|
||||
def get_students( stu:StudentsQuery = Depends()
|
||||
, db=Depends(get_db)
|
||||
):
|
||||
s_dick = stu.model_dump(exclude_unset=True)
|
||||
result = get_student_dao( s=s_dick , db=db )
|
||||
if result:
|
||||
return result
|
||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||
|
||||
|
||||
@students_api.post("/students/"
|
||||
,summary='新增学生资料'
|
||||
,description='学生ID自动分配,学生姓名和班级是必填项'
|
||||
,response_model=StudentsResponse )
|
||||
def add_student( stu:StudentsResponse = Depends()
|
||||
, db=Depends(get_db)
|
||||
):
|
||||
s_dick = stu.model_dump()
|
||||
result = add_student_dao( s=s_dick , db=db )
|
||||
if not result:
|
||||
raise HTTPException(status_code=500, detail='服务器繁忙或用户不存在!')
|
||||
return result
|
||||
|
||||
@students_api.put("/students/"
|
||||
,summary='学生资料更新'
|
||||
,description='填写即更新,全为空即不更新,学生ID无法修改'
|
||||
,response_model=StudentsUpdate )
|
||||
def get_students( stu:StudentsUpdate = Depends()
|
||||
, db=Depends(get_db)
|
||||
):
|
||||
s_dick = stu.model_dump()
|
||||
|
||||
return '学生资料已更新'
|
||||
|
||||
@students_api.delete("/students/"
|
||||
,summary='删除学生资料'
|
||||
,description='输入需要删除的学生ID'
|
||||
,response_model=StudentsDelete ) # 逻辑删除/软删除
|
||||
def delete_students( stu:StudentsDelete = Depends()
|
||||
, db=Depends(get_db)
|
||||
):
|
||||
s_dick = stu.model_dump()
|
||||
|
||||
return '学生已删除'
|
||||
Reference in New Issue
Block a user