Skip to content

Commit

Permalink
Addition of pin router
Browse files Browse the repository at this point in the history
  • Loading branch information
Xithrius committed Sep 27, 2023
1 parent 162d839 commit 0551114
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
9 changes: 2 additions & 7 deletions api/app/database/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -15,4 +9,5 @@
"DeepRockGalacticBuild",
"WebMap",
"Trusted",
"Pin",
)
2 changes: 2 additions & 0 deletions api/app/routers/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
44 changes: 44 additions & 0 deletions api/app/routers/v1/pins.py
Original file line number Diff line number Diff line change
@@ -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.",
)

0 comments on commit 0551114

Please sign in to comment.