-
Notifications
You must be signed in to change notification settings - Fork 2
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
cbbe593
commit c067d2d
Showing
14 changed files
with
448 additions
and
175 deletions.
There are no files selected for viewing
Empty file.
File renamed without changes.
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
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 |
---|---|---|
@@ -1,32 +1,29 @@ | ||
from fastapi import APIRouter, HTTPException, Depends | ||
from sqlalchemy.orm import Session | ||
from fastapi import APIRouter, HTTPException | ||
|
||
from models.account import AccountModel, AccountCreate | ||
from db import get_db | ||
|
||
from .crud import AccountHelper | ||
from services.account import AccountService | ||
|
||
router = APIRouter() | ||
account_router = router | ||
|
||
|
||
@router.post("/", response_model=AccountModel) | ||
async def create_account(model: AccountCreate, session: Session = Depends(get_db), ): | ||
model = await AccountHelper.create(session, model) | ||
return AccountModel.model_validate(model) | ||
async def create_account(model: AccountCreate) -> AccountModel: | ||
account_model = await AccountService.create(model) | ||
return account_model | ||
|
||
|
||
@router.get("/{user_id}", response_model=AccountModel) | ||
async def get_account_by_id(user_id, db: Session = Depends(get_db)): | ||
model = AccountHelper.get_by_id(db, user_id) | ||
async def get_account_by_id(user_id): | ||
model = AccountService.get_by_id(user_id) | ||
if model is None: | ||
raise HTTPException(404) | ||
return AccountModel.model_validate(model) | ||
return model | ||
|
||
|
||
@router.get("/email/{email}", response_model=AccountModel) | ||
async def get_account_by_email(email, db: Session = Depends(get_db)): | ||
model = AccountHelper.get_by_email(db, email) | ||
async def get_account_by_email(email): | ||
model = AccountService.get_by_email(email) | ||
if model is None: | ||
raise HTTPException(404) | ||
return AccountModel.model_validate(model) |
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 |
---|---|---|
@@ -1,75 +1,70 @@ | ||
from fastapi import APIRouter, HTTPException, Depends | ||
from sqlalchemy.orm import Session | ||
from fastapi import APIRouter, HTTPException | ||
|
||
from fastapi_pagination import Page | ||
from fastapi_pagination import Page, paginate | ||
|
||
from models.agent_bot import AgentBotModel, AgentBotCreate, AgentBotUpdate | ||
from models.agent_config import AgentConfigModel, AgentConfigUpdate, AgentConfigCreate | ||
|
||
from db import get_db | ||
|
||
from .crud import AgentBotHelper, AgentConfigHelper | ||
|
||
from services.agent import AgentConfigService, AgentService | ||
|
||
router = APIRouter() | ||
|
||
agent_router = router | ||
|
||
|
||
@router.post("/bots", response_model=AgentBotModel) | ||
def create_agent_bot(user_id: int, bot: AgentBotCreate, session: Session = Depends(get_db)): | ||
model = AgentBotHelper.create(session, user_id, bot) | ||
return AgentBotModel.model_validate(model) | ||
def create_agent_bot(user_id: int, bot: AgentBotCreate): | ||
model = AgentService.create(user_id, bot) | ||
return model | ||
|
||
|
||
@router.get("/bots", response_model=Page[AgentBotModel]) | ||
def get_agent_bots(user_id: int, session: Session = Depends(get_db)): | ||
data = AgentBotHelper.get_all(session, user_id) | ||
return data | ||
def get_agent_bots(user_id: int): | ||
data = AgentService.get_by_user(user_id) | ||
res = paginate(data) | ||
return res | ||
|
||
|
||
@router.get("/bots/{bot_id}", response_model=AgentBotModel) | ||
async def get_agent_bot(bot_id, user_id: int, with_draft=False, session: Session = Depends(get_db)): | ||
model = AgentBotHelper.get(session, bot_id) | ||
async def get_agent_bot(bot_id, user_id: int, with_draft=False): | ||
model = AgentService.get_by_id(bot_id) | ||
if model is None: | ||
raise HTTPException(404) | ||
bot = AgentBotModel.model_validate(model) | ||
if with_draft: | ||
draft = AgentConfigHelper.get_or_create_bot_draft( | ||
session, user_id, bot.id) | ||
bot.draft = draft | ||
return bot | ||
draft = AgentConfigService.get_or_create_bot_draft(user_id, bot_id) | ||
model.draft = draft | ||
return model | ||
|
||
|
||
@router.get("/bots/{bot_id}/draft", response_model=AgentConfigModel) | ||
async def get_or_create_agent_bot_draft_config(user_id: int, bot_id, session: Session = Depends(get_db)): | ||
model = AgentConfigHelper.get_or_create_bot_draft(session, user_id, bot_id) | ||
async def get_or_create_agent_bot_draft_config(user_id: int, bot_id): | ||
model = AgentConfigService.get_or_create_bot_draft(user_id, bot_id) | ||
if model is None: | ||
raise HTTPException(404) | ||
return AgentConfigModel.model_validate(model) | ||
return model | ||
|
||
|
||
@router.put("/bots/{bot_id}") | ||
async def update_agent_bot(user_id: int, bot: AgentBotUpdate, db: Session = Depends(get_db)): | ||
success = AgentBotHelper.update(db, user_id, bot) | ||
async def update_agent_bot(user_id: int, bot: AgentBotUpdate): | ||
success = AgentService.update(user_id, bot) | ||
return success | ||
|
||
|
||
@router.get("/configs/{config_id}", response_model=AgentConfigModel) | ||
async def get_agent_config(config_id, session: Session = Depends(get_db)): | ||
model = AgentConfigHelper.get(session, config_id) | ||
async def get_agent_config(config_id): | ||
model = AgentConfigService.get_by_id(config_id) | ||
if model is None: | ||
raise HTTPException(404) | ||
return AgentConfigModel.model_validate(model) | ||
return model | ||
|
||
|
||
@router.put("/configs/{bot_id}") | ||
async def update_agent_config(user_id: int, config: AgentConfigUpdate, db: Session = Depends(get_db)): | ||
success = AgentConfigHelper.update(db, user_id, config) | ||
async def update_agent_config(user_id: int, config: AgentConfigUpdate): | ||
success = AgentConfigService.update(user_id, config) | ||
return success | ||
|
||
|
||
@router.post("/configs", response_model=AgentConfigModel) | ||
async def create_agent_config(user_id: int, config: AgentConfigCreate, session: Session = Depends(get_db)): | ||
model = AgentConfigHelper.create(session, user_id, config) | ||
return AgentConfigModel.model_validate(model) | ||
async def create_agent_config(user_id: int, config: AgentConfigCreate): | ||
model = AgentConfigService.create(user_id, config) | ||
return model |
Oops, something went wrong.