-
-
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 3f31638
Showing
12 changed files
with
148 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 ApiBrainDefinition(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.ApiBrainDefinition import ApiBrainDefinition | ||
from models.databases.repository import Repository | ||
from pydantic import BaseModel | ||
|
||
|
||
class ApiMethod(str, Enum): | ||
GET = "GET" | ||
POST = "POST" | ||
PUT = "PUT" | ||
DELETE = "DELETE" | ||
|
||
|
||
class CreateApiBrainDefinition(BaseModel): | ||
brain_id: UUID | ||
method: ApiMethod | ||
url: str | ||
params: dict | ||
search_params: dict | ||
secrets: dict | ||
|
||
|
||
class ApiBrainDefinitions(Repository): | ||
def __init__(self, supabase_client): | ||
self.db = supabase_client | ||
|
||
def get_api_brain_definition(self, brain_id: UUID) -> Optional[ApiBrainDefinition]: | ||
response = ( | ||
self.db.table("api_brain_definition") | ||
.select("*") | ||
.filter("brain_id", "eq", brain_id) | ||
.execute() | ||
) | ||
if len(response.data) == 0: | ||
return None | ||
|
||
return ApiBrainDefinition(**response.data[0]) | ||
|
||
def add_api_brain_definition( | ||
self, brain_id: UUID, config: CreateApiBrainDefinition | ||
) -> Optional[ApiBrainDefinition]: | ||
response = self.db.table("api_brain_definition").insert( | ||
[{"brain_id": str(brain_id), **config.dict()}] | ||
) | ||
if len(response.data) == 0: | ||
return None | ||
return ApiBrainDefinition(**response.data[0]) | ||
|
||
def delete_api_brain_definition(self, brain_id: UUID) -> None: | ||
self.db.table("api_brain_definition").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.
14 changes: 14 additions & 0 deletions
14
backend/repository/api_brain_definition/add_api_brain_definition.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,14 @@ | ||
from uuid import UUID | ||
|
||
from models.databases.supabase.api_brain_definition import ( | ||
CreateApiBrainDefinition, | ||
) | ||
from models.settings import get_supabase_db | ||
|
||
|
||
def add_api_brain_definition( | ||
brain_id: UUID, api_brain_configs: CreateApiBrainDefinition | ||
) -> None: | ||
supabase_db = get_supabase_db() | ||
|
||
supabase_db.add_api_brain_definition(brain_id, api_brain_configs) |
9 changes: 9 additions & 0 deletions
9
backend/repository/api_brain_definition/delete_api_brain_definition.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_api_brain_definition(brain_id: UUID) -> None: | ||
supabase_db = get_supabase_db() | ||
|
||
supabase_db.delete_api_brain_definition(brain_id) |
11 changes: 11 additions & 0 deletions
11
backend/repository/api_brain_definition/get_api_brain_definition.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.ApiBrainDefinition import ApiBrainDefinition | ||
|
||
|
||
def get_api_brain_definition(brain_id: UUID) -> Optional[ApiBrainDefinition]: | ||
supabase_db = get_supabase_db() | ||
|
||
return supabase_db.get_api_brain_definition(brain_id) |
18 changes: 18 additions & 0 deletions
18
scripts/2023110607100000_add_api_brain_definition_table.sql
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_definition ( | ||
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_definition_table' | ||
WHERE NOT EXISTS ( | ||
SELECT 1 FROM migrations WHERE name = '2023110607100000_add_api_brain_definition_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