diff --git a/app/api/v1.py b/app/api/v1.py index fc52bd4..e628d1f 100644 --- a/app/api/v1.py +++ b/app/api/v1.py @@ -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() @@ -10,10 +14,14 @@ async def root(): return {"message": "Witaj w API v1"} -@router.get("/health", summary="Health check") -async def health(): - return {"status": "ok"} +@cbv(router) +class APIv1: + webhook_service: WebhookProcessor = Depends(AutowireSupport.webhook_processor) -@router.post("/ci", summary="CI Webhook") -async def ci(request: Request): - return Response(200) + @router.get("/health", summary="Health check") + async def health(self) -> JSONResponse: + return JSONResponse({"status": "ok"}) + + @router.post("/ci", summary="CI Webhook") + async def ci(self, request: Request): + return Response(status_code=201) diff --git a/app/core/injects.py b/app/core/injects.py new file mode 100644 index 0000000..3dfcc66 --- /dev/null +++ b/app/core/injects.py @@ -0,0 +1,10 @@ +from injectable import inject + +from app.core.core import WebhookProcessor + + +class AutowireSupport: + + @staticmethod + def webhook_processor(): + return inject(WebhookProcessor) diff --git a/app/model/webhook.py b/app/model/webhook.py new file mode 100644 index 0000000..70470b2 --- /dev/null +++ b/app/model/webhook.py @@ -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]