From 33035cd827d614284e1f8bebb50d5e861e468601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=9D=E5=B7=9D?= Date: Tue, 8 Nov 2022 15:25:28 +0800 Subject: [PATCH] changes --- AppIndicators/Crud.py | 4 ++-- AppIndicators/RoutersIndicators.py | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/AppIndicators/Crud.py b/AppIndicators/Crud.py index 25f778e..8a8c98b 100644 --- a/AppIndicators/Crud.py +++ b/AppIndicators/Crud.py @@ -78,8 +78,8 @@ def delete_indicator_parameter(db: Session, pid: str): db.commit() -def edit_indicator_parameter(db: Session, pid: str, body: Schemas.ParameterEdit): - db.query(Models.Parameters).filter_by(pid=pid).update(body.dict()) +def edit_indicator_parameter(db: Session, pid: str, schema: Schemas.ParameterEdit): + db.query(Models.Parameters).filter_by(pid=pid).update(schema.dict()) db.commit() diff --git a/AppIndicators/RoutersIndicators.py b/AppIndicators/RoutersIndicators.py index 87cc466..77f8ca5 100644 --- a/AppIndicators/RoutersIndicators.py +++ b/AppIndicators/RoutersIndicators.py @@ -18,7 +18,7 @@ router = APIRouter( # 新建指标 @router.post("/create", summary='新建指标', response_model=Schemas.Indicator) -def create_indicator(body: Schemas.IndicatorCreate, db: Session = Depends(get_db)): +def func01(body: Schemas.IndicatorCreate, db: Session = Depends(get_db)): data = Crud.get_indicator_by_ename(db, ename=body.ename) if data: @@ -35,14 +35,14 @@ def create_indicator(body: Schemas.IndicatorCreate, db: Session = Depends(get_db # 删除指标 @router.post("/delete/{iid}", summary='删除指标') -def delete_indicator(iid: str, db: Session = Depends(get_db)): +def func02(iid: str, db: Session = Depends(get_db)): Crud.delete_indicator(db=db, iid=iid) return {"info": "Success"} # 编辑指标 @router.post("/edit/{iid}", summary='编辑指标', response_model=Schemas.Indicator) -def edit_indicator(iid: str, body: Schemas.IndicatorEdit, db: Session = Depends(get_db)): +def func03(iid: str, body: Schemas.IndicatorEdit, db: Session = Depends(get_db)): db_indicator = Crud.get_indicator_by_iid(db=db, iid=iid) if not db_indicator: raise HTTPException(status_code=202, detail="Indicator Not Found") @@ -51,7 +51,7 @@ def edit_indicator(iid: str, body: Schemas.IndicatorEdit, db: Session = Depends( # 查看指标 @router.get("/view/{iid}", summary='查看指标', response_model=Schemas.Indicator) -def read_indicator(iid: str, db: Session = Depends(get_db)): +def func04(iid: str, db: Session = Depends(get_db)): data = Crud.get_indicator_by_iid(db, iid=iid) if data is None: raise HTTPException(status_code=202, detail="Indicator Not Found") @@ -60,27 +60,37 @@ def read_indicator(iid: str, db: Session = Depends(get_db)): # 查询指标描述 @router.post("/describe/{iid}", summary='查看指标描述') -def indicators_description(iid: str, db: Session = Depends(get_db)): +def func05(iid: str, db: Session = Depends(get_db)): indicators = Crud.get_indicator_description_by_iid(db, iid=iid) return indicators # 查询指标 @router.post("/search", summary='查询指标') -def read_indicators(body: Schemas.IndicatorSearch, db: Session = Depends(get_db)): +def func06(body: Schemas.IndicatorSearch, db: Session = Depends(get_db)): indicators, total = Crud.search_indicators(db, body=body, page=body.page, pagesize=body.pagesize) return {"items": indicators, "total": total} # 新建参数 @router.post("/param/create/{iid}", summary='新建参数', response_model=Schemas.Parameter) -def create_index_param(iid: str, body: Schemas.ParameterEdit, db: Session = Depends(get_db)): +def func07(iid: str, body: Schemas.ParameterEdit, db: Session = Depends(get_db)): return Crud.create_indicator_parameter(db=db, body=body, _iid=iid) +@router.post("/param/edit/{pid}", summary='编辑参数') +def func08(pid: str, schema: Schemas.ParameterEdit, db: Session = Depends(get_db)): + data = Crud.get_parameter_by_pid(db=db, pid=pid) + if not data: + raise HTTPException(status_code=202, detail="Parameter Not Existed") + + Crud.edit_indicator_parameter(db=db, pid=pid, schema=schema) + return {"info": "Success"} + + # 删除参数 @router.post("/param/delete/{pid}", summary='删除参数') -def delete_parameters_for_indicator(pid: str, db: Session = Depends(get_db)): +def func09(pid: str, db: Session = Depends(get_db)): data = Crud.get_parameter_by_pid(db=db, pid=pid) if not data: raise HTTPException(status_code=202, detail="Parameter Not Existed")