From c0e08bd9059ce6f51b08145be3a4bc20eb9a685b Mon Sep 17 00:00:00 2001 From: wolin_ck666_999 Date: Tue, 22 Sep 2026 21:33:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20api/student=5Fapi.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/student_api.py | 168 --------------------------------------------- 1 file changed, 168 deletions(-) delete mode 100644 api/student_api.py diff --git a/api/student_api.py b/api/student_api.py deleted file mode 100644 index f47a83d..0000000 --- a/api/student_api.py +++ /dev/null @@ -1,168 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException -from sqlalchemy.orm import Session -from database import get_db -from dao.student_dao import create_student, get_student_by_id, get_student_list, update_student, delete_student_logic -from schema.student_schema import ( - StudentCreateRequest, - StudentUpdateRequest, - StudentQuery, - StudentResponse, - StudentPageResponse -) - -# 创建路由对象 API Router1 -router = APIRouter( tags=["学生管理模块"]) -@router.post("/", response_model=StudentResponse,summary="新增学生") -def add_student( - student_req: StudentCreateRequest, - db: Session = Depends(get_db) -): - db_stu = create_student(db, student_req) - # 手动转字典:model的stu_id映射响应体的id - stu_dict = { - "id": db_stu.id, - "stu_id": db_stu.stu_id, - "class_id": db_stu.class_id, - "stu_name": db_stu.stu_name, - "native_place": db_stu.native_place, - "graduate_school": db_stu.graduate_school, - "major": db_stu.major, - "enroll_date": db_stu.enroll_date, - "graduate_date": db_stu.graduate_date, - "education": db_stu.education, - "advisor_no": db_stu.advisor_no, - "age": db_stu.age, - "gender": db_stu.gender, - "is_deleted": db_stu.is_deleted - } - return StudentResponse(**stu_dict) - - -@router.get("/", response_model=StudentPageResponse,summary="根据学号姓名班级查询") -def get_student_page( - query: StudentQuery = Depends(), - db: Session = Depends(get_db) -): - - total, db_stu_list = get_student_list( - db, - stu_id=query.stu_id, - stu_name=query.stu_name, - class_id=query.class_id, - page=query.page, - page_size=query.page_size - ) - item_list = [] - for db_stu in db_stu_list: - stu_dict = { - "id": db_stu.id, - "stu_id": db_stu.stu_id, - "class_id": db_stu.class_id, - "stu_name": db_stu.stu_name, - "native_place": db_stu.native_place, - "graduate_school": db_stu.graduate_school, - "major": db_stu.major, - "enroll_date": db_stu.enroll_date, - "graduate_date": db_stu.graduate_date, - "education": db_stu.education, - "advisor_no": db_stu.advisor_no, - "age": db_stu.age, - "gender": db_stu.gender, - "is_deleted": db_stu.is_deleted - } - item_list.append(StudentResponse(**stu_dict)) - - return StudentPageResponse( - total=total, - page=query.page, - page_size=query.page_size, - items=item_list - ) - - -@router.get("/{stu_id}", response_model=StudentResponse,summary="根据id查询") -def get_one_student( - stu_id: int, - db: Session = Depends(get_db) -): - #根据主键stu_id查询单个学生 - db_stu = get_student_by_id(db, stu_id) - if db_stu is None: - raise HTTPException(status_code=404, detail="该学生不存在") - - stu_dict = { - "id": db_stu.id, - "stu_id": db_stu.stu_id, - "class_id": db_stu.class_id, - "stu_name": db_stu.stu_name, - "native_place": db_stu.native_place, - "graduate_school": db_stu.graduate_school, - "major": db_stu.major, - "enroll_date": db_stu.enroll_date, - "graduate_date": db_stu.graduate_date, - "education": db_stu.education, - "advisor_no": db_stu.advisor_no, - "age": db_stu.age, - "gender": db_stu.gender, - "is_deleted": db_stu.is_deleted - } - return StudentResponse(**stu_dict) - - -@router.put("/{stu_id}", response_model=StudentResponse,summary="修改学生信息") -def edit_student( - stu_id: int, - update_req: StudentUpdateRequest, - db: Session = Depends(get_db) -): - #修改学生信息 - db_stu = update_student(db, stu_id, update_req) - if db_stu is None: - raise HTTPException(status_code=404, detail="该学生不存在") - - stu_dict = { - "id": db_stu.id, - "stu_id": db_stu.stu_id, - "class_id": db_stu.class_id, - "stu_name": db_stu.stu_name, - "native_place": db_stu.native_place, - "graduate_school": db_stu.graduate_school, - "major": db_stu.major, - "enroll_date": db_stu.enroll_date, - "graduate_date": db_stu.graduate_date, - "education": db_stu.education, - "advisor_no": db_stu.advisor_no, - "age": db_stu.age, - "gender": db_stu.gender, - "is_deleted": db_stu.is_deleted - } - return StudentResponse(**stu_dict) - - -@router.delete("/{stu_id}", response_model=StudentResponse,summary="删除学生信息") -def remove_student( - stu_id: int, - db: Session = Depends(get_db) -): - #逻辑删除学生 - db_stu = delete_student_logic(db, stu_id) - if db_stu is None: - raise HTTPException(status_code=404, detail="该学生不存在") - - stu_dict = { - "id": db_stu.id, - "stu_id": db_stu.stu_id, - "stu_name": db_stu.stu_name, - "class_id": db_stu.class_id, - "native_place": db_stu.native_place, - "graduate_school": db_stu.graduate_school, - "major": db_stu.major, - "enroll_date": db_stu.enroll_date, - "graduate_date": db_stu.graduate_date, - "education": db_stu.education, - "advisor_no": db_stu.advisor_no, - "age": db_stu.age, - "gender": db_stu.gender, - "is_deleted": db_stu.is_deleted - } - return StudentResponse(**stu_dict)