karl/app/api/v1.py
2025-10-22 23:58:15 +02:00

34 lines
999 B
Python

from automapper import mapper
from fastapi import APIRouter, Depends
from fastapi_utils.cbv import cbv
from starlette.responses import JSONResponse, Response
from app.api.models import Request
from app.core.core import WebhookProcessor
from app.core.injects import AutowireSupport
from app.model.webhook import WebhookEvent
router = APIRouter()
@router.get("/", summary="Main API")
async def root():
return {"message": "Witaj w API v1"}
@cbv(router)
class APIv1:
webhook_service: WebhookProcessor = Depends(AutowireSupport.webhook_processor)
logger = __import__('logging').getLogger(__name__)
def __init__(self):
mapper.add(Request, WebhookEvent)
@router.get("/health", summary="Health check")
async def health(self) -> JSONResponse:
return JSONResponse({"status": self.webhook_service.health})
@router.post("/ci", summary="CI Webhook")
async def ci(self, request: Request):
self.webhook_service.enqueue(mapper.map(request))
return Response(status_code=201)