Merge remote-tracking branch 'origin/conding' into conding
This commit is contained in:
@@ -1,11 +1,44 @@
|
||||
from fastapi import APIRouter
|
||||
from dao.student_dao import select_age
|
||||
from fastapi import APIRouter,Depends,HTTPException
|
||||
from schema.student_schema import StudentResponse
|
||||
from dao.student_dao import delete_student_dao,add_student_dao,update_student_dao,get_student_dao,select_age
|
||||
from schema.student_schema import StudentRequest,StudentResponse
|
||||
from model.student_model import Student_Model
|
||||
from util.database import get_db
|
||||
|
||||
studentapi = APIRouter()
|
||||
|
||||
@studentapi.get("/age",response_model=StudentResponse,tags=['统计分析模块'],description='根据年龄查询学生信息')
|
||||
StudentAPI = APIRouter()
|
||||
|
||||
@StudentAPI.get("/age",response_model=StudentResponse,tags=['统计分析模块'],description='根据年龄查询学生信息')
|
||||
def get_students(min_age:int|None=None,max_age:int|None=None):
|
||||
l = select_age(min_age,max_age)
|
||||
return [i for i in l]
|
||||
|
||||
@StudentAPI.get('',description='查询学生信息')
|
||||
def get_students(stu_id:int|None=None
|
||||
,stu_name:str|None=None
|
||||
,class_id:int|None=None
|
||||
,db=Depends(get_db)
|
||||
,page:int=1
|
||||
,page_size:int=10):
|
||||
r=get_student_dao(stu_id,stu_name,class_id,db,page,page_size)
|
||||
if r:
|
||||
return r
|
||||
raise HTTPException(status_code=404,detail='学生不存在')
|
||||
|
||||
@StudentAPI.put('/{stu_id}')
|
||||
def update_orders(s:StudentRequest,stu_id:int,db=Depends(get_db)):
|
||||
d = s.model_dump(exclude_unset=True)
|
||||
r = update_student_dao( stu_id=stu_id,update_data=d,db=db )
|
||||
if not r:
|
||||
raise HTTPException(status_code=500, detail='没有更新!')
|
||||
return {'code':200,'totals':r,'detail':'更新成功'}
|
||||
|
||||
@StudentAPI.delete('/{stu_id}')
|
||||
def del_student(stu_id:int,db=Depends(get_db)):
|
||||
rows=delete_student_dao( stu_id=stu_id,db=db )
|
||||
if not rows:
|
||||
raise HTTPException(status_code=500,detail='没有删除')
|
||||
return {'code':200,'totals':rows,'detail':'删除成功'}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user