Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion socat/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
The web API to access the socat database.
"""

from socat.database.session import SessionDependency

from .app import app
from .async_ses import SessionDependency
from .routers.fixed_sources import (
create_source,
create_source_name,
Expand Down
26 changes: 12 additions & 14 deletions socat/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@
The web API to access the socat database.
"""

from contextlib import asynccontextmanager

from fastapi import FastAPI
from sqlalchemy.ext.asyncio import create_async_engine

from ..database import (
ALL_TABLES,
)
from ..settings import settings
from ..database.session import initialize_database_schema_async
from ..settings import Settings
from .routers import fixed_sources, moving_sources, services, sso

async_engine = create_async_engine(settings.database_url, echo=True, future=True)


async def lifespan(f: FastAPI): # pragma: no cover
# Use SQLModel to create the tables.
print("Creating tables")
for table in ALL_TABLES:
print("Creating table", table)
async with async_engine.begin() as conn:
await conn.run_sync(table.metadata.create_all)
yield
@asynccontextmanager
async def lifespan(_app: FastAPI): # pragma: no cover
async_engine = create_async_engine(Settings().database_url, echo=True, future=True)
await initialize_database_schema_async(async_engine)
try:
yield
finally:
await async_engine.dispose()


app = FastAPI(lifespan=lifespan)
Expand Down
17 changes: 0 additions & 17 deletions socat/api/async_ses.py

This file was deleted.

2 changes: 1 addition & 1 deletion socat/api/routers/fixed_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import socat.astroquery as soaq
from socat import core
from socat.astroquery import AstroqueryReturn
from socat.database.session import SessionDependency

from ...database.sources import RegisteredFixedSource
from ..async_ses import SessionDependency
from .services import get_service_name

router = APIRouter(prefix="/api/v1")
Expand Down
2 changes: 1 addition & 1 deletion socat/api/routers/moving_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from pydantic import BaseModel, ValidationError

from socat import core
from socat.database.session import SessionDependency

from ...database import RegisteredMovingSource
from ..async_ses import SessionDependency

router = APIRouter(prefix="/api/v1")

Expand Down
2 changes: 1 addition & 1 deletion socat/api/routers/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from pydantic import BaseModel, ValidationError

from socat import core
from socat.database.session import SessionDependency

from ...database.services import AstroqueryService
from ..async_ses import SessionDependency

router = APIRouter(prefix="/api/v1")

Expand Down
2 changes: 1 addition & 1 deletion socat/api/routers/sso.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from pydantic import BaseModel, ValidationError

from socat import core
from socat.database.session import SessionDependency

from ...database import SolarSystemObject
from ..async_ses import SessionDependency

router = APIRouter(prefix="/api/v1")

Expand Down
24 changes: 24 additions & 0 deletions socat/client/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ def delete_source(self, *, source_id: int) -> None:
"""
return # pragma: no cover

@property
@abstractmethod
def astroquery(self) -> "AstroqueryClientBase":
"""
Access the astroquery-service client.
"""
return # pragma: no cover

@property
@abstractmethod
def sso(self) -> "SolarSystemClientBase":
"""
Access the solar-system-object client.
"""
return # pragma: no cover

@property
@abstractmethod
def ephem(self) -> "EphemClientBase":
"""
Access the ephemeris client.
"""
return # pragma: no cover


class AstroqueryClientBase(ABC):
@abstractmethod
Expand Down
Loading
Loading