26 lines
827 B
Python
26 lines
827 B
Python
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")
|
|
ChainRepositoryDependency = Annotated[ChainRepository, Depends(get_chain_repository)]
|
|
|
|
|
|
@router.post("/")
|
|
async def chain_upsert_controller(
|
|
chain: Chain,
|
|
chain_repository: ChainRepositoryDependency,
|
|
):
|
|
try:
|
|
upserted_chain = await chain_repository.upsert(chain)
|
|
return upserted_chain
|
|
|
|
except Exception:
|
|
logger.exception(f"Error during chain upsert {chain.model_dump_json()}")
|
|
return HTTPException(status_code=500, detail="Error during chain upsert")
|