2022-10-14 22:11:27 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from fastapi import FastAPI
|
2022-12-07 21:46:57 +01:00
|
|
|
from fastapi_pagination import add_pagination
|
2022-10-14 22:11:27 +02:00
|
|
|
|
|
|
|
from mobilizon_reshare.storage.db import init as init_db, get_db_url
|
2022-12-07 21:46:57 +01:00
|
|
|
from mobilizon_reshare.web.backend.events.endpoints import (
|
|
|
|
register_endpoints as register_event_endpoints,
|
|
|
|
)
|
|
|
|
from mobilizon_reshare.web.backend.publications.endpoints import (
|
|
|
|
register_endpoints as register_publication_endpoints,
|
|
|
|
)
|
2022-10-14 22:11:27 +02:00
|
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def check_database():
|
|
|
|
url = get_db_url()
|
|
|
|
if url.scheme == "sqlite":
|
|
|
|
logger.warning(
|
|
|
|
"Database is SQLite. This might create issues when running the web application. Please use a "
|
|
|
|
"PostgreSQL or MariaDB backend."
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def register_endpoints(app):
|
|
|
|
|
2022-12-07 21:46:57 +01:00
|
|
|
register_event_endpoints(app)
|
|
|
|
register_publication_endpoints(app)
|
|
|
|
|
|
|
|
|
|
|
|
def init_endpoints(app):
|
|
|
|
|
|
|
|
register_endpoints(app)
|
|
|
|
add_pagination(app)
|
2022-10-14 22:11:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
@app.on_event("startup")
|
|
|
|
async def init_app(init_logging=True):
|
|
|
|
check_database()
|
|
|
|
await init_db(init_logging=init_logging)
|
2022-12-07 21:46:57 +01:00
|
|
|
init_endpoints(app)
|
2022-10-14 22:11:27 +02:00
|
|
|
return app
|