1
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from fastapi import APIRouter,Depends,HTTPException
|
from fastapi import APIRouter,Depends,HTTPException
|
||||||
from schema.student_schema import StudentResponse
|
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 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 schema.student_schema import StudentRequest,StudentResponse,StugetResponse
|
||||||
from model.student_model import Student_Model
|
from model.student_model import Student_Model
|
||||||
from util.database import get_db
|
from util.database import get_db
|
||||||
|
|
||||||
@@ -9,24 +9,27 @@ from util.database import get_db
|
|||||||
StudentAPI = APIRouter()
|
StudentAPI = APIRouter()
|
||||||
|
|
||||||
@StudentAPI.get("/age",response_model=StudentResponse,tags=['统计分析模块'],description='根据年龄查询学生信息')
|
@StudentAPI.get("/age",response_model=StudentResponse,tags=['统计分析模块'],description='根据年龄查询学生信息')
|
||||||
def get_students(min_age:int|None=None,max_age:int|None=None):
|
def get_students(min_age:int|None=None
|
||||||
|
,max_age:int|None=None):
|
||||||
l = select_age(min_age,max_age)
|
l = select_age(min_age,max_age)
|
||||||
return [i for i in l]
|
return [i for i in l]
|
||||||
|
|
||||||
@StudentAPI.get('',description='查询学生信息')
|
@StudentAPI.get('',description='查询学生信息')
|
||||||
def get_students(stu_id:int|None=None
|
def get_students(stu_id:int|None=None
|
||||||
,stu_name:str|None=None
|
,stu_name:str|None=None
|
||||||
,class_id:int|None=None
|
,class_id:int|None=None
|
||||||
,db=Depends(get_db)
|
,db=Depends(get_db)
|
||||||
,page:int=1
|
,page:int=1
|
||||||
,page_size:int=10):
|
,page_size:int=10):
|
||||||
r=get_student_dao(stu_id,stu_name,class_id,db,page,page_size)
|
r=get_student_dao(stu_id,stu_name,class_id,db,page,page_size)
|
||||||
if r:
|
if r:
|
||||||
return r
|
return r
|
||||||
raise HTTPException(status_code=404,detail='学生不存在')
|
raise HTTPException(status_code=404,detail='学生不存在')
|
||||||
|
|
||||||
@StudentAPI.put('/{stu_id}')
|
@StudentAPI.put('/{stu_id}')
|
||||||
def update_orders(s:StudentRequest,stu_id:int,db=Depends(get_db)):
|
def update_students(s:StudentRequest
|
||||||
|
,stu_id:int
|
||||||
|
,db=Depends(get_db)):
|
||||||
d = s.model_dump(exclude_unset=True)
|
d = s.model_dump(exclude_unset=True)
|
||||||
r = update_student_dao( stu_id=stu_id,update_data=d,db=db )
|
r = update_student_dao( stu_id=stu_id,update_data=d,db=db )
|
||||||
if not r:
|
if not r:
|
||||||
@@ -34,11 +37,30 @@ def update_orders(s:StudentRequest,stu_id:int,db=Depends(get_db)):
|
|||||||
return {'code':200,'totals':r,'detail':'更新成功'}
|
return {'code':200,'totals':r,'detail':'更新成功'}
|
||||||
|
|
||||||
@StudentAPI.delete('/{stu_id}')
|
@StudentAPI.delete('/{stu_id}')
|
||||||
def del_student(stu_id:int,db=Depends(get_db)):
|
def del_students(stu_id:int
|
||||||
|
,db=Depends(get_db)):
|
||||||
rows=delete_student_dao( stu_id=stu_id,db=db )
|
rows=delete_student_dao( stu_id=stu_id,db=db )
|
||||||
if not rows:
|
if not rows:
|
||||||
raise HTTPException(status_code=500,detail='没有删除')
|
raise HTTPException(status_code=500,detail='没有删除')
|
||||||
return {'code':200,'totals':rows,'detail':'删除成功'}
|
return {'code':200,'totals':rows,'detail':'删除成功'}
|
||||||
|
|
||||||
|
@StudentAPI.post('',response_model=list[StugetResponse])
|
||||||
|
def add_students(s:StudentRequest
|
||||||
|
,db=Depends(get_db)):
|
||||||
|
d=s.model_dump(exclude_unset=True)
|
||||||
|
r=add_student_dao(o=d,db=db)
|
||||||
|
if not r:
|
||||||
|
raise HTTPException(status_code=500,detail='添加失败')
|
||||||
|
|
||||||
|
|
||||||
|
@StudentAPI.put('')
|
||||||
|
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='学生不存在!')
|
||||||
|
|||||||
@@ -66,14 +66,7 @@ def get_student_dao(stu_id:Optional[int]
|
|||||||
q= q.filter(Student_Model.class_id == class_id,Student_Model.delete_status == 0)
|
q= q.filter(Student_Model.class_id == class_id,Student_Model.delete_status == 0)
|
||||||
total = q.count()
|
total = q.count()
|
||||||
r = q.offset((page - 1) * page_size).limit(page_size).all()
|
r = q.offset((page - 1) * page_size).limit(page_size).all()
|
||||||
data = []
|
|
||||||
for i in r:
|
return r
|
||||||
data.append({'stu_id': i.stu_id
|
|
||||||
,'stu_name': i.stu_name
|
|
||||||
,'class_id': i.class_id
|
|
||||||
,'create_date': i.create_date
|
|
||||||
,'update_date': i.update_date
|
|
||||||
})
|
|
||||||
return data, total
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from typing import Self
|
|||||||
from pydantic import BaseModel, field_serializer, field_validator,model_validator
|
from pydantic import BaseModel, field_serializer, field_validator,model_validator
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class StudentRequest(BaseModel):
|
class StudentRequest(BaseModel):
|
||||||
class_id:int |None = None
|
class_id:int |None = None
|
||||||
stu_name:str |None = None
|
stu_name:str |None = None
|
||||||
@@ -29,6 +30,7 @@ class StudentRequest(BaseModel):
|
|||||||
raise ValueError ('入学日期不能晚于毕业日期')
|
raise ValueError ('入学日期不能晚于毕业日期')
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
class StudentResponse(BaseModel):
|
class StudentResponse(BaseModel):
|
||||||
code:int = 200
|
code:int = 200
|
||||||
detail:str = 'ok'
|
detail:str = 'ok'
|
||||||
@@ -45,3 +47,20 @@ class StudentResponse(BaseModel):
|
|||||||
2:'已就业'
|
2:'已就业'
|
||||||
}
|
}
|
||||||
return d1.get(progress,'暂不明确')
|
return d1.get(progress,'暂不明确')
|
||||||
|
|
||||||
|
class StugetResponse(BaseModel):
|
||||||
|
code:int = 200
|
||||||
|
detail:str = 'ok'
|
||||||
|
page: int
|
||||||
|
page_size: int
|
||||||
|
class_id: int
|
||||||
|
stu_name: str
|
||||||
|
age: int
|
||||||
|
gender: str
|
||||||
|
native_place: str
|
||||||
|
birthday: date
|
||||||
|
school: str
|
||||||
|
major: str
|
||||||
|
degree: str
|
||||||
|
admission_date: date
|
||||||
|
graduation_date: date
|
||||||
Reference in New Issue
Block a user