running chain
This commit is contained in:
parent
6aa6a11bd1
commit
36c36d2c89
9
chain_service/database/models/running_chain.py
Normal file
9
chain_service/database/models/running_chain.py
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
from .base import BaseConfig
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class RunningChain(BaseModel):
|
||||||
|
chain_id: str
|
||||||
|
|
||||||
|
class Config(BaseConfig):
|
||||||
|
pass
|
||||||
16
chain_service/dependencies/running_chain_repository.py
Normal file
16
chain_service/dependencies/running_chain_repository.py
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
from .database import DatabaseDependency
|
||||||
|
from chain_service.repositories.running_chain import RunningChainRepository
|
||||||
|
|
||||||
|
from fastapi import Depends
|
||||||
|
from typing import Annotated
|
||||||
|
|
||||||
|
|
||||||
|
def get_running_chain_repository(
|
||||||
|
database: DatabaseDependency,
|
||||||
|
) -> RunningChainRepository:
|
||||||
|
return RunningChainRepository(database=database)
|
||||||
|
|
||||||
|
|
||||||
|
RunningChainRepositoryDependency = Annotated[
|
||||||
|
RunningChainRepository, Depends(get_running_chain_repository)
|
||||||
|
]
|
||||||
23
chain_service/repositories/running_chain.py
Normal file
23
chain_service/repositories/running_chain.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
from chain_service.database.database import Database
|
||||||
|
from chain_service.database.models.running_chain import RunningChain
|
||||||
|
|
||||||
|
from uuid import UUID
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
|
||||||
|
class RunningChainRepository:
|
||||||
|
|
||||||
|
def __init__(self, database: Database):
|
||||||
|
self.collection = database.get_collection("running_chains")
|
||||||
|
|
||||||
|
async def add(self, chain_id: str):
|
||||||
|
query = payload = {"chainId": chain_id}
|
||||||
|
await self.collection.replace_one(query, payload, upsert=True)
|
||||||
|
|
||||||
|
async def exists(self, chain_id: str) -> bool:
|
||||||
|
query = {"chainId": chain_id}
|
||||||
|
return bool(await self.collection.find_one(query))
|
||||||
|
|
||||||
|
async def delete(self, chain_id: str):
|
||||||
|
query = {"chainId": chain_id}
|
||||||
|
await self.collection.delete_one(query)
|
||||||
Loading…
Reference in New Issue
Block a user