From 359542b37399d0e6c8b591f6d2ec296bf9b939e4 Mon Sep 17 00:00:00 2001 From: 00MSJ1122 <1253313142@qq.com> Date: Tue, 22 Sep 2026 09:56:31 +0800 Subject: [PATCH] 1 --- PythonProject/api/student_api.py | 4 ++-- PythonProject/dao/student_dao.py | 8 ++++---- PythonProject/schema/student_schema.py | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/PythonProject/api/student_api.py b/PythonProject/api/student_api.py index 2295009..7b6e939 100644 --- a/PythonProject/api/student_api.py +++ b/PythonProject/api/student_api.py @@ -24,7 +24,7 @@ def get_students(stu_id:int|None=None raise HTTPException(status_code=404,detail='学生不存在') return StudentPageResponse(page=page, page_size=page_size, - total=total, + totals=total, data=r) @StudentAPI.put('/{stu_id}',tags=['学⽣基本信息管理模块'],summary='学生信息更新接口',description='更新学生信息') @@ -50,7 +50,7 @@ def del_students(stu_id:int @StudentAPI.post('/students',tags=['学⽣基本信息管理模块'],response_model=StugetResponse,summary='学生信息新增接口',description='新增学生信息') def add_students(s:StudentRequest ,db=Depends(get_db)): - d=s.model_dump(exclude_unset=False) + d=s.model_dump(exclude_unset=True) stu_new=add_student_dao(o=d,db=db) if not stu_new: raise HTTPException(status_code=500,detail='添加失败') diff --git a/PythonProject/dao/student_dao.py b/PythonProject/dao/student_dao.py index e1869bf..d5cd939 100644 --- a/PythonProject/dao/student_dao.py +++ b/PythonProject/dao/student_dao.py @@ -44,13 +44,13 @@ def get_student_dao(stu_id:Optional[int] ,db ) -> tuple[List[Dict[str, Any]], int]: try: - q = db.query(Student_Model) + q = db.query(Student_Model).filter(Student_Model.delete_status == 0) if stu_id: - q = q.filter(Student_Model.stu_id == stu_id,Student_Model.delete_status == 0) + q = q.filter(Student_Model.stu_id == stu_id) if stu_name and stu_name.strip() != "": - q = q.filter(Student_Model.stu_name.like(f"%{stu_name}%"),Student_Model.delete_status == 0) + q = q.filter(Student_Model.stu_name.like(f"%{stu_name}%")) if class_id: - q= q.filter(Student_Model.class_id == class_id,Student_Model.delete_status == 0) + q= q.filter(Student_Model.class_id == class_id) total = q.count() r = q.offset((page - 1) * page_size).limit(page_size).all() return r,total diff --git a/PythonProject/schema/student_schema.py b/PythonProject/schema/student_schema.py index 8a16c95..494672b 100644 --- a/PythonProject/schema/student_schema.py +++ b/PythonProject/schema/student_schema.py @@ -1,6 +1,6 @@ from datetime import date from typing import Self,List -from pydantic import BaseModel, field_serializer, field_validator,model_validator +from pydantic import BaseModel, field_serializer, field_validator,model_validator,ConfigDict @@ -49,6 +49,7 @@ class StudentResponse(BaseModel): return d1.get(progress,'暂不明确') class StugetResponse(BaseModel): + model_config = ConfigDict(from_attributes=True) code:int = 200 detail:str = 'ok' class_id: int | None = None