From dccc0b609259b1c5d8497465100ac6a2a4e140bf Mon Sep 17 00:00:00 2001 From: 00MSJ1122 <1253313142@qq.com> Date: Tue, 22 Sep 2026 10:39:41 +0800 Subject: [PATCH] 1 --- PythonProject/api/student_api.py | 4 ++-- PythonProject/dao/student_dao.py | 6 ++++-- PythonProject/schema/student_schema.py | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/PythonProject/api/student_api.py b/PythonProject/api/student_api.py index 7b6e939..981de80 100644 --- a/PythonProject/api/student_api.py +++ b/PythonProject/api/student_api.py @@ -44,7 +44,7 @@ def del_students(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='没有删除') + raise HTTPException(status_code=404,detail='对象已被删除') return {'code':200,'totals':rows,'detail':'删除成功'} @StudentAPI.post('/students',tags=['学⽣基本信息管理模块'],response_model=StugetResponse,summary='学生信息新增接口',description='新增学生信息') @@ -53,5 +53,5 @@ def add_students(s:StudentRequest 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='添加失败') + raise HTTPException(status_code=404,detail='添加失败') return stu_new diff --git a/PythonProject/dao/student_dao.py b/PythonProject/dao/student_dao.py index d5cd939..9f755ac 100644 --- a/PythonProject/dao/student_dao.py +++ b/PythonProject/dao/student_dao.py @@ -28,12 +28,14 @@ def delete_student_dao(stu_id,db): def update_student_dao(stu_id,update_data,db): try: - rows = db.query( Student_Model ).filter( Student_Model.stu_id == stu_id,Student_Model.delete_status == 0).update( update_data ) + rows = (db.query( Student_Model ) + .filter( Student_Model.stu_id == stu_id,Student_Model.delete_status == 0) + .update( update_data )) + db.commit() except: db.rollback() return False else: - db.commit() return rows def get_student_dao(stu_id:Optional[int] diff --git a/PythonProject/schema/student_schema.py b/PythonProject/schema/student_schema.py index 494672b..58894ec 100644 --- a/PythonProject/schema/student_schema.py +++ b/PythonProject/schema/student_schema.py @@ -52,6 +52,7 @@ class StugetResponse(BaseModel): model_config = ConfigDict(from_attributes=True) code:int = 200 detail:str = 'ok' + stu_id:int | None = None class_id: int | None = None stu_name: str | None = None age: int | None = None