from dao import get_db from schema import Test from fastapi import APIRouter,Depends from dao import a,a1,a2,a3,a4,a5 ScoreAPI=APIRouter() ScoreAPI1=APIRouter() @ScoreAPI.post('/scores',tags=['增']) def scores(s:Test,db=Depends(get_db)): a(s,db) return {'code':200,'detail':'添加成功!',} @ScoreAPI.delete('/scores',tags=['删']) def scores1(stu_id:int,db=Depends(get_db)): r = a1(stu_id,db) if r==0: return '没有该学生' else: return f'已删除学生编号为{stu_id}的学生' @ScoreAPI.put('/scores',tags=['改']) def scores2(stu_id:int,exam_seq:int,s:Test,db=Depends(get_db)): r=a2(stu_id,exam_seq,s,db) if r!=0: return '更新成功' else: return '没有该数据' @ScoreAPI.get('/scores',tags=['查']) def Scores3(stu_id:int,exam_seq:int,db=Depends(get_db)): r=a3(stu_id,exam_seq,db) try: return {'成绩编号':r.id,'学生编号':r.stu_id,f'第{exam_seq}次成绩:':r.score,'创建日期':r.create_date,'更新日期':r.update_date} except: return '没有该学生' @ScoreAPI1.put('/scores/{stu_id}',tags=['软删除']) def scores4(stu_id:int,exam_seq:int,db=Depends(get_db)): r=a4(stu_id, exam_seq, db) if r ==0: return '没有该数据' else: return '已删除' @ScoreAPI1.get('/scores/{stu_id}',tags=['总分,平均分,最大值,最小值']) def scores5(stu_id:int,db=Depends(get_db)): s,r,a=a5(stu_id,db) return f'总分:{s},平均分:{s/len(r)},最大值:{max(a)},最小值:{min(a)}'