init: added template

This commit is contained in:
ITQ
2026-02-12 11:36:43 +03:00
parent 030e49edb9
commit 514393e3f8
96 changed files with 14594 additions and 183 deletions
+43
View File
@@ -0,0 +1,43 @@
from functools import partial
from typing import Any, override
import orjson
from django.http import HttpRequest
from ninja import NinjaAPI, Schema
from ninja.renderers import BaseRenderer
from api.v1 import handlers
class ORJSONRenderer(BaseRenderer):
media_type: str | None = "application/json"
@override
def render(
self, request: HttpRequest, data: Any, *, response_status: int
) -> Any:
return orjson.dumps(data, default=self.default)
def default(self, obj: Any) -> Any:
if isinstance(obj, Schema):
return obj.model_dump(by_alias=True)
raise TypeError
router = NinjaAPI(
title="Lotty API",
version="1",
description="API docs for Lotty A/B platform",
openapi_url="/docs/openapi.json",
renderer=ORJSONRenderer(),
)
# router.add_router(
# "health",
# health_router,
# )
for exception, handler in handlers.exception_handlers:
router.add_exception_handler(exception, partial(handler, router=router))