blitz_api/app/routers/apps.py
Stefan Stammberger 6ca9b97b87
fix: problems with included external packages
* Add proper licensing information
* Move sse_starlette to the externals folder
2021-11-18 11:30:48 +01:00

42 lines
1.2 KiB
Python

import app.repositories.apps as repo
import app.routers.apps_docs as docs
from app.auth.auth_bearer import JWTBearer
from app.external.sse_startlette import EventSourceResponse
from fastapi import APIRouter, HTTPException, status
from fastapi.params import Depends
_PREFIX = "apps"
router = APIRouter(prefix=f"/{_PREFIX}", tags=["Apps"])
@router.get(
"/status",
name=f"{_PREFIX}/status",
summary="Get the status of currently installed apps.",
response_description=docs.get_app_status_response_docs,
dependencies=[Depends(JWTBearer())],
)
def get_status():
try:
return repo.get_app_status()
except:
return HTTPException(
status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Unknown error"
)
@router.get(
"/status-sub",
name=f"{_PREFIX}/status-sub",
summary="Subscribe to status changes of currently installed apps.",
response_description=docs.get_app_status_sub_response_docs,
dependencies=[Depends(JWTBearer())],
)
async def get_status():
try:
return EventSourceResponse(repo.get_app_status_sub())
except:
return HTTPException(
status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Unknown error"
)