nb
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
from fastapi import APIRouter,Depends,HTTPException,Path
|
from fastapi import APIRouter,Depends,HTTPException,Path,Form
|
||||||
from util.database import get_db
|
from util.database import get_db
|
||||||
from model.all_model import Student_Model
|
from model.all_model import Student_Model
|
||||||
from dao.grade_dao import *
|
from dao.grade_dao import *
|
||||||
|
from schema.grade_schema import *
|
||||||
|
|
||||||
gradeAPI = APIRouter(tags=['学生考核成绩'])
|
gradeAPI = APIRouter(tags=['学生考核成绩'])
|
||||||
|
|
||||||
@@ -12,3 +13,12 @@ def get_grade(stu_id: int,db=Depends(get_db)):
|
|||||||
return {'code': 200,'msg':'查询成功','data':res}
|
return {'code': 200,'msg':'查询成功','data':res}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500,detail=f'数据库查询异常:{str(e)}')
|
raise HTTPException(status_code=500,detail=f'数据库查询异常:{str(e)}')
|
||||||
|
|
||||||
|
@gradeAPI.post('/{stu_id}',summary='添加学生成绩')
|
||||||
|
def post_grade(o:GradeRequest=Form(),db=Depends(get_db)):
|
||||||
|
d=o.model_dump()
|
||||||
|
r=add_grade_dao(g=d,db=db)
|
||||||
|
if not r:
|
||||||
|
raise HTTPException(status_code=400, detail='学生不存在')
|
||||||
|
return GradeResponse
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from fastapi import Depends,HTTPException
|
|||||||
|
|
||||||
from util.database import get_db
|
from util.database import get_db
|
||||||
|
|
||||||
from model.grade_model import *
|
from model.all_model import *
|
||||||
|
|
||||||
|
|
||||||
def get_grade_dao( stu_id:int
|
def get_grade_dao( stu_id:int
|
||||||
@@ -13,3 +13,14 @@ def get_grade_dao( stu_id:int
|
|||||||
return r1
|
return r1
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=404,detail="学生不存在")
|
raise HTTPException(status_code=404,detail="学生不存在")
|
||||||
|
|
||||||
|
def add_grade_dao(o,db=Depends(get_db)):
|
||||||
|
try:
|
||||||
|
o1 = WlScore(**o)
|
||||||
|
db.add(o1)
|
||||||
|
except:
|
||||||
|
db.rollback()
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
db.commit()
|
||||||
|
return True
|
||||||
@@ -160,7 +160,7 @@ class WlScore(Base):
|
|||||||
|
|
||||||
stu_id = Column( Integer
|
stu_id = Column( Integer
|
||||||
,ForeignKey('wl_student.stu_id')
|
,ForeignKey('wl_student.stu_id')
|
||||||
,autoincrement=True
|
,autoincrement=True #自增主建
|
||||||
,comment='学生编号')
|
,comment='学生编号')
|
||||||
|
|
||||||
exam_order = Column(Integer
|
exam_order = Column(Integer
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
from datetime import date
|
from model.all_model import *
|
||||||
from typing import Self
|
|
||||||
from pydantic import BaseModel,Field
|
from pydantic import BaseModel,Field
|
||||||
|
|
||||||
class GradeRequest(BaseModel):
|
class GradeRequest(BaseModel):
|
||||||
stu_id:str|None = Field(description="学生编号")
|
stu_id:str|None = Field(description="学生编号")
|
||||||
|
exam_order:int = Field(description='考核序次')
|
||||||
|
score:float = Field(description='成绩')
|
||||||
|
|
||||||
|
|
||||||
class GradeResponse(BaseModel):
|
class GradeResponse(BaseModel):
|
||||||
|
code: int = 200
|
||||||
|
detail: str = 'OK'
|
||||||
|
stu_id:str
|
||||||
|
exam_order:int
|
||||||
|
score:float
|
||||||
Reference in New Issue
Block a user