41 lines
918 B
Python
41 lines
918 B
Python
# scopes.api.main
|
|
|
|
import sys
|
|
if '' not in sys.path:
|
|
sys.path = [''] + sys.path
|
|
|
|
import config
|
|
config.storageFactory = config.StorageFactory(config)
|
|
|
|
from scopes.storage import tracking
|
|
from scopes.storage.common import Storage
|
|
import transaction
|
|
|
|
from fastapi import Depends, FastAPI
|
|
from typing import Annotated
|
|
|
|
# dependencies
|
|
|
|
def storage():
|
|
return config.storageFactory(config.dbschema)
|
|
|
|
# app and routes
|
|
|
|
app = FastAPI()
|
|
|
|
@app.get('/')
|
|
async def read_root():
|
|
return {'Hello': 'World'}
|
|
|
|
@app.get('/persons/{name}')
|
|
async def read_person(name: str, q: str | None = None):
|
|
return {'name': name, 'query': q}
|
|
|
|
@app.get('/tracks')
|
|
async def get_tracks(storage: Annotated[Storage, Depends(storage)]):
|
|
#storage = config.storageFactory(config.dbschema)
|
|
tracks = storage.create(tracking.Container)
|
|
result = [tr.asDict() for tr in tracks.query()]
|
|
transaction.commit()
|
|
return result
|
|
|