chain creation controller
This commit is contained in:
parent
21945376db
commit
0124fe9ec2
|
|
@ -1,6 +1,8 @@
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI, APIRouter
|
||||||
from .test import router as test_router
|
from .chain import router as chain_router
|
||||||
|
|
||||||
|
|
||||||
def setup_controllers(application: FastAPI):
|
def setup_controllers(application: FastAPI):
|
||||||
application.include_router(test_router)
|
router = APIRouter(prefix="/api")
|
||||||
|
router.include_router(chain_router)
|
||||||
|
application.include_router(router)
|
||||||
|
|
|
||||||
24
chain_service/controllers/chain.py
Normal file
24
chain_service/controllers/chain.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
from chain_service.database.models.chain import Chain
|
||||||
|
from chain_service.repositories.chain import ChainRepository
|
||||||
|
from chain_service.dependencies.chain import get_chain_repository
|
||||||
|
|
||||||
|
from typing import Annotated
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
|
||||||
|
router = APIRouter(prefix="/chain")
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/")
|
||||||
|
async def chain_create_controller(
|
||||||
|
chain: Chain,
|
||||||
|
chain_repository: Annotated[ChainRepository, Depends(get_chain_repository)],
|
||||||
|
):
|
||||||
|
try:
|
||||||
|
created_chain = await chain_repository.create(chain)
|
||||||
|
return created_chain
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
logger.exception(f"Error during chain creation {chain.model_dump_json()}")
|
||||||
|
return HTTPException(status_code=500, detail="Error during chain creation")
|
||||||
Loading…
Reference in New Issue
Block a user