diff --git a/app/api/v1/connector.py b/app/api/v1/connector.py index 550db14e..f3f746d0 100644 --- a/app/api/v1/connector.py +++ b/app/api/v1/connector.py @@ -1,3 +1,4 @@ +from typing import Optional from fastapi import APIRouter, Depends from sqlalchemy.orm import Session import app.schemas.connector as schemas @@ -26,10 +27,10 @@ actions = APIRouter() @router.get("/list", response_model=resp_schemas.CommonResponse, dependencies=[Depends(verify_token)]) -def list_connectors(db: Session = Depends(get_db)): +def list_connectors(db: Session = Depends(get_db), provider_category_id: Optional[int] = None ): """ - Retrieves a list of all connectors from the database. + Retrieves a list of all connectors from the database. If a provider category ID is provided, only connectors from that category are returned. Args: db (Session): Database session dependency. @@ -38,7 +39,10 @@ def list_connectors(db: Session = Depends(get_db)): CommonResponse: A response containing either the list of connectors or an error message. """ - result, error = svc.list_connectors(db) + if provider_category_id: + result, error = svc.list_connectors_by_provider_category(provider_category_id, db) + else: + result, error = svc.list_connectors(db) if error: return commons.is_error_response("DB Error", result, {"connectors": []}) diff --git a/app/schemas/connector.py b/app/schemas/connector.py index 5894c493..01574f53 100644 --- a/app/schemas/connector.py +++ b/app/schemas/connector.py @@ -14,6 +14,7 @@ class ConnectorResponse(ConnectorBase): connector_id:int connector_key :Optional[str]=None icon:Optional[str]=None + provider_id: Optional[int] = None class ConnectorUpdate(BaseModel): connector_type: Optional[int] = None diff --git a/app/services/connector.py b/app/services/connector.py index 384f4700..2d5d2c5f 100644 --- a/app/services/connector.py +++ b/app/services/connector.py @@ -45,11 +45,34 @@ def list_connectors(db: Session): connector_docs=connector.connector_docs, connector_key=connector.provider.key, enable=connector.enable, - icon=connector.provider.icon + icon=connector.provider.icon, + provider_id=connector.provider.category_id ) for connector in connectors] return connectors_response, None +def list_connectors_by_provider_category(category_id: int, db: Session): + """ + Retrieves all connector records from the database filtered by provider category. + + Args: + category_id (int): The ID of the provider category. + db (Session): Database session object. + + Returns: + Tuple: List of connector responses and error message (if any). + """ + connectors, error = list_connectors(db) + + if error: + return [], error + + filtered_connectors = [connector for connector in connectors if connector.provider_id == category_id] + + return filtered_connectors, None + + + def get_connector(connector_id: int, db: Session): """ diff --git a/ui/.env.example b/ui/.env.example deleted file mode 100644 index 54f4d9c9..00000000 --- a/ui/.env.example +++ /dev/null @@ -1,2 +0,0 @@ -# Backend URL -VITE_BACKEND_URL=http://your-backend-url \ No newline at end of file diff --git a/ui/src/pages/Samples/SampleForm.jsx b/ui/src/pages/Samples/SampleForm.jsx index 93d7cc10..68e5a613 100644 --- a/ui/src/pages/Samples/SampleForm.jsx +++ b/ui/src/pages/Samples/SampleForm.jsx @@ -20,7 +20,7 @@ const SampleForm = ({ sample = {}, afterCreate = ()=>{}, onCancel = ()=>{}})=>{ const getAllConnectors = ()=>{ - getConnectors().then(response=>{ + getConnectors(2).then(response=>{ let tempOptions = []; response.data?.data?.connectors?.map(item=>{ @@ -29,7 +29,7 @@ const SampleForm = ({ sample = {}, afterCreate = ()=>{}, onCancel = ()=>{}})=>{ setConnectors(tempOptions) }) } - + const saveSample = (data)=>{ saveSamples(sample.id, { @@ -66,23 +66,23 @@ const SampleForm = ({ sample = {}, afterCreate = ()=>{}, onCancel = ()=>{}})=>{ Question} hasError={errors["question"]?.message} errorMessage={errors["question"]?.message} {...register("question", {required: "This is required"})} />