APIv1 cbv
This commit is contained in:
parent
de6184273a
commit
120e929469
3 changed files with 37 additions and 8 deletions
|
|
@ -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)
|
||||
|
|
|
|||
10
app/core/injects.py
Normal file
10
app/core/injects.py
Normal 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
11
app/model/webhook.py
Normal 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]
|
||||
Loading…
Add table
Add a link
Reference in a new issue