async def dashboard_apps_list_api(session: Session = Depends(get_session)): explore_states = session.query(ExploreState).filter( ExploreState.is_archived == False) # noqa result = [] for es in explore_states: result.append(explore_state_response_serializer(es)) return result
async def dashboard_apps_get_api(app_id: str, session: Session = Depends(get_session)): explore_state = session.query(ExploreState) \ .filter(ExploreState.uuid == app_id, ExploreState.is_archived == False) \ .first() # noqa if not explore_state: raise HTTPException(status_code=404) return explore_state_response_serializer(explore_state)
async def dashboard_apps_create_api(explore_state_in: ExploreStateCreateIn, session: Session = Depends(get_session)): explore_state = ExploreState() explore_state.type = explore_state_in.type explore_state.state = json.dumps(explore_state_in.state) session.add(explore_state) session.commit() return explore_state_response_serializer(explore_state)
async def dashboard_apps_create_api(request: Request, session: Session = Depends(get_session)): """ Use response model's app_state as an example for request body \n Note: every field is optional """ explore_state = ExploreState() request_data = await request.json() serializer = ExploreStateModelSerializer(model_instance=explore_state, json_data=request_data) serializer.validate() if serializer.error_messages: return JSONResponse(content=serializer.error_messages, status_code=403) explore_state = serializer.save() session.add(explore_state) session.commit() return explore_state_response_serializer(explore_state)
async def dashboard_apps_put_api(app_id: str, explore_state_in: ExploreStateUpdateIn, session: Session = Depends(get_session)): explore_state = session.query(ExploreState) \ .filter(ExploreState.uuid == app_id, ExploreState.is_archived == False) \ .first() # noqa if not explore_state: raise HTTPException(status_code=404) if explore_state_in.type: explore_state.type = explore_state_in.type if explore_state_in.state: explore_state.state = json.dumps(explore_state_in.state) session.commit() return explore_state_response_serializer(explore_state)
async def dashboard_apps_put_api(app_id: str, request: Request, session: Session = Depends(get_session)): """ Use response model's app_state as an example for request body \n Note: every field is optional """ explore_state = session.query(ExploreState) \ .filter(ExploreState.uuid == app_id, ExploreState.is_archived == False) \ .first() # noqa if not explore_state: raise HTTPException(status_code=404) request_data = await request.json() serializer = ExploreStateModelSerializer(model_instance=explore_state, json_data=request_data) serializer.validate() if serializer.error_messages: return JSONResponse(content=serializer.error_messages, status_code=403) explore_state = serializer.save() session.add(explore_state) session.commit() return explore_state_response_serializer(explore_state)