felicity-lims/felicity/lims/boot.py

50 lines
1.2 KiB
Python
Raw Normal View History

2023-08-14 02:08:08 +08:00
from typing import Any
2023-09-11 13:02:05 +08:00
2023-08-26 04:53:40 +08:00
from sanic import Sanic, json
2023-08-14 02:08:08 +08:00
from sanic.request import Request
2023-09-11 13:02:05 +08:00
from sanic_ext import Extend
2023-08-14 02:08:08 +08:00
from strawberry.sanic.views import GraphQLView
2023-09-11 13:02:05 +08:00
from api.deps import models, get_auth_user, get_auth_context
2023-08-14 02:08:08 +08:00
from api.gql.schema import schema
from api.rest.api_v1 import api
2023-08-26 04:40:56 +08:00
from apps.job.sched import felicity_workforce_init
2023-08-14 02:08:08 +08:00
from core import settings
def register_configs(app: Sanic):
app.config.update(settings.__dict__)
Extend(app)
2023-09-11 13:02:05 +08:00
2023-08-26 04:53:40 +08:00
2023-08-14 02:08:08 +08:00
def register_dependencies(app: Sanic):
app.ext.add_dependency(models.User, get_auth_user)
2023-08-26 04:53:40 +08:00
2023-08-14 02:08:08 +08:00
def register_blueprints(app: Sanic):
2023-08-26 04:53:40 +08:00
@app.get("/health")
async def get_health(request):
return json({"up": True})
2023-09-11 13:02:05 +08:00
2023-08-14 02:08:08 +08:00
app.blueprint(api)
2023-09-11 13:02:05 +08:00
2023-08-14 02:08:08 +08:00
def register_graphql(app: Sanic):
class FelicityGraphQLView(GraphQLView):
async def get_context(self, request: Request, response) -> Any:
return await get_auth_context(request)
app.add_route(
FelicityGraphQLView.as_view(schema=schema, graphiql=True),
"/felicity-gql",
)
def register_felicity(app: Sanic):
register_configs(app)
register_dependencies(app)
register_blueprints(app)
register_graphql(app)
2023-09-11 13:02:05 +08:00
2023-08-26 04:53:40 +08:00
app.add_task(felicity_workforce_init)