class FilterParams(BaseModel): customername: List[str] = None # type: ignore…
- User
class FilterParams(BaseModel): customer_name: List[str] = None # type: ignore
@case_router.post("/filtering") async def case_filtering(filter_params: FilterParams, db: Session = Depends(get_db)):
try: query: Query = db.query(model_case) for column_name, column_values in filter_params.dict().items(): if column_values is not None: query = query.filter(getattr(model_case, column_name).in_(column_values)) items = query.all() return {"items": items} except Exception as e: raise HTTPException(status_code=500, detail=str(e)) - Assistant
This endpoint receives a POST request with a
FilterParamsobject that contains a list of customer names to filter cases. If thecustomer_namelist is not provided, all cases will be returned. The function receives adbobject that represents a connection to the database.It first creates a database query object for the
model_casetable. Then, for each column in theFilterParamsobject, it checks if the column is notNone. If it is notNone, it filters the query by the values in the column.Finally, it returns a list of case objects that match the filter criteria. If an exception occurs during the process, it returns a 500 HTTP status code with the error message.