-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7ed952
commit 5feaecf
Showing
12 changed files
with
145 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from uuid import UUID | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class ApiBrainConfigs(BaseModel): | ||
brain_id: UUID | ||
method: str | ||
url: str | ||
params: dict | ||
search_params: dict | ||
secrets: dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from enum import Enum | ||
from typing import Optional | ||
from uuid import UUID | ||
|
||
from models.ApiBrainConfigs import ApiBrainConfigs | ||
from models.databases.repository import Repository | ||
from pydantic import BaseModel | ||
|
||
|
||
class ApiMethod(str, Enum): | ||
GET = "GET" | ||
POST = "POST" | ||
PUT = "PUT" | ||
DELETE = "DELETE" | ||
|
||
|
||
class CreateApiBrainConfig(BaseModel): | ||
brain_id: UUID | ||
method: ApiMethod | ||
url: str | ||
params: dict | ||
search_params: dict | ||
secrets: dict | ||
|
||
|
||
class ApiBrainConfig(Repository): | ||
def __init__(self, supabase_client): | ||
self.db = supabase_client | ||
|
||
def get_api_brain_configs(self, brain_id: UUID) -> Optional[ApiBrainConfigs]: | ||
response = ( | ||
self.db.table("api_brain_config") | ||
.select("*") | ||
.filter("brain_id", "eq", brain_id) | ||
.execute() | ||
) | ||
if len(response.data) == 0: | ||
return None | ||
|
||
return ApiBrainConfigs(**response.data[0]) | ||
|
||
def add_api_brain_configs( | ||
self, brain_id: UUID, config: CreateApiBrainConfig | ||
) -> Optional[ApiBrainConfigs]: | ||
response = self.db.table("api_brain_config").insert( | ||
[{"brain_id": str(brain_id), **config.dict()}] | ||
) | ||
if len(response.data) == 0: | ||
return None | ||
return ApiBrainConfigs(**response.data[0]) | ||
|
||
def remove_api_brain_configs(self, brain_id: UUID) -> None: | ||
self.db.table("api_brain_config").delete().filter( | ||
"brain_id", "eq", str(brain_id) | ||
).execute() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
12 changes: 12 additions & 0 deletions
12
backend/repository/api_brain_config/add_api_brain_configs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from uuid import UUID | ||
|
||
from models.databases.supabase.api_brain_config import CreateApiBrainConfig | ||
from models.settings import get_supabase_db | ||
|
||
|
||
def add_api_brain_configs( | ||
brain_id: UUID, api_brain_configs: CreateApiBrainConfig | ||
) -> None: | ||
supabase_db = get_supabase_db() | ||
|
||
supabase_db.add_api_brain_configs(brain_id, api_brain_configs) |
9 changes: 9 additions & 0 deletions
9
backend/repository/api_brain_config/delete_api_brain_configs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from uuid import UUID | ||
|
||
from models.settings import get_supabase_db | ||
|
||
|
||
def delete_brain_configs(brain_id: UUID) -> None: | ||
supabase_db = get_supabase_db() | ||
|
||
supabase_db.remove_api_brain_configs(brain_id) |
11 changes: 11 additions & 0 deletions
11
backend/repository/api_brain_config/get_api_brain_configs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from typing import Optional | ||
from uuid import UUID | ||
|
||
from models import get_supabase_db | ||
from models.ApiBrainConfigs import ApiBrainConfigs | ||
|
||
|
||
def get_api_brain_configs(brain_id: UUID) -> Optional[ApiBrainConfigs]: | ||
supabase_db = get_supabase_db() | ||
|
||
return supabase_db.get_api_brain_configs(brain_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- Create the new table with 6 columns | ||
CREATE TABLE IF NOT EXISTS api_brain_config ( | ||
brain_id UUID REFERENCES brains(brain_id), | ||
method VARCHAR(255) CHECK (method IN ('GET', 'POST', 'PUT', 'DELETE')), | ||
url VARCHAR(255), | ||
params JSON, | ||
search_params JSON, | ||
secrets JSON | ||
); | ||
|
||
-- Insert migration record if it doesn't exist | ||
INSERT INTO migrations (name) | ||
SELECT '2023110607100000_add_api_brain_config_table' | ||
WHERE NOT EXISTS ( | ||
SELECT 1 FROM migrations WHERE name = '2023110607100000_add_api_brain_config_table' | ||
); | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters