diff --git a/api/app/database/__init__.py b/api/app/database/__init__.py index ee4fba7..b1aeb58 100644 --- a/api/app/database/__init__.py +++ b/api/app/database/__init__.py @@ -1,11 +1,5 @@ from .db import database, metadata -from .models import ( - CommandMetric, - DeepRockGalacticBuild, - LinkMap, - Trusted, - WebMap, -) +from .models import CommandMetric, DeepRockGalacticBuild, LinkMap, Pin, Trusted, WebMap __all__ = ( "database", @@ -15,4 +9,5 @@ "DeepRockGalacticBuild", "WebMap", "Trusted", + "Pin", ) diff --git a/api/app/routers/v1/__init__.py b/api/app/routers/v1/__init__.py index 84c9db6..66ac5c8 100644 --- a/api/app/routers/v1/__init__.py +++ b/api/app/routers/v1/__init__.py @@ -5,6 +5,7 @@ from .drg import router as drg_router from .link_map import router as link_maps_router from .ping import router as ping_router +from .pins import router as pin_router from .trusted import router as trusted_router from .web_map import router as web_maps_router @@ -17,3 +18,4 @@ v1.include_router(trusted_router, prefix="/trusted") v1.include_router(web_maps_router, prefix="/web_maps") v1.include_router(docker_router, prefix="/docker") +v1.include_in_schema(pin_router, prefix="/pins") diff --git a/api/app/routers/v1/pins.py b/api/app/routers/v1/pins.py new file mode 100644 index 0000000..35358b2 --- /dev/null +++ b/api/app/routers/v1/pins.py @@ -0,0 +1,44 @@ +from fastapi import APIRouter, HTTPException, status +from ormar import NoMatch + +from app.database import Pin + +router = APIRouter() + + +@router.post( + "/", + response_model=Pin, + status_code=status.HTTP_201_CREATED, +) +async def create_pin(server_id: int, user_id: int, message: str) -> Pin: + return await Pin(server_id=server_id, user_id=user_id, message=message).save() + + +@router.get( + "/", + response_model=list[Pin], + status_code=status.HTTP_200_OK, +) +async def get_all_builds() -> list[Pin]: + return await Pin.objects.all() + + +@router.delete( + "/{id}", + response_model=Pin, + status_code=status.HTTP_200_OK, +) +async def remove_build(id: int) -> Pin: + try: + item = await Pin.objects.get(id=id) + + await Pin.objects.delete(id=id) + + return item + + except NoMatch: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail="Deep Rock Galactic build with id '{id}' not found.", + )