This commit is contained in:
王思川 2022-11-08 15:25:28 +08:00
parent 996ba0bc73
commit 33035cd827
2 changed files with 20 additions and 10 deletions

View File

@ -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()

View File

@ -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")