APIv1 cbv

This commit is contained in:
Piotr Dec 2025-10-21 17:41:41 +02:00
parent de6184273a
commit 120e929469
Signed by: stawros
GPG key ID: 74B18A3F0F1E99C0
3 changed files with 37 additions and 8 deletions

View file

@ -1,6 +1,10 @@
from fastapi import APIRouter from fastapi import APIRouter, Depends
from fastapi_utils.cbv import cbv
from starlette.responses import JSONResponse, Response
from app.api.models import Request, Response from app.api.models import Request
from app.core.core import WebhookProcessor
from app.core.injects import AutowireSupport
router = APIRouter() router = APIRouter()
@ -10,10 +14,14 @@ async def root():
return {"message": "Witaj w API v1"} return {"message": "Witaj w API v1"}
@cbv(router)
class APIv1:
webhook_service: WebhookProcessor = Depends(AutowireSupport.webhook_processor)
@router.get("/health", summary="Health check") @router.get("/health", summary="Health check")
async def health(): async def health(self) -> JSONResponse:
return {"status": "ok"} return JSONResponse({"status": "ok"})
@router.post("/ci", summary="CI Webhook") @router.post("/ci", summary="CI Webhook")
async def ci(request: Request): async def ci(self, request: Request):
return Response(200) return Response(status_code=201)

10
app/core/injects.py Normal file
View file

@ -0,0 +1,10 @@
from injectable import inject
from app.core.core import WebhookProcessor
class AutowireSupport:
@staticmethod
def webhook_processor():
return inject(WebhookProcessor)

11
app/model/webhook.py Normal file
View file

@ -0,0 +1,11 @@
from dataclasses import dataclass
from typing import List
@dataclass
class WebhookRequest:
_id: str
commit: str
message: str
started: str
files: List[str]