feat: add API endpoint to get devices list
This commit is contained in:
parent
0cb5706ed7
commit
f4b7daabd3
9 changed files with 66 additions and 1 deletions
10
server/backend/adapters/http/_devices_schemas.py
Normal file
10
server/backend/adapters/http/_devices_schemas.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from pydantic import BaseModel
|
||||
|
||||
from domain.entities import Device
|
||||
|
||||
class DeviceResponseSchema(BaseModel):
|
||||
device_eui: str
|
||||
|
||||
@classmethod
|
||||
def from_domain(cls, device: Device) -> "DeviceResponseSchema":
|
||||
return cls(device_eui=device.device_eui)
|
||||
12
server/backend/adapters/http/devices.py
Normal file
12
server/backend/adapters/http/devices.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from fastapi import APIRouter, Depends
|
||||
|
||||
from services.devices_service import DeviceService
|
||||
from dependencies import get_device_service
|
||||
from ._devices_schemas import DeviceResponseSchema
|
||||
|
||||
devices_router = APIRouter(prefix="/devices", tags=["devices"])
|
||||
|
||||
|
||||
@devices_router.get("", response_model=list[DeviceResponseSchema])
|
||||
def list_devices(service: DeviceService = Depends(get_device_service)):
|
||||
return [DeviceResponseSchema.from_domain(d) for d in service.get_all_devices()]
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from .readings import readings_router
|
||||
from .devices import devices_router
|
||||
|
||||
app = FastAPI(title="SimuGazAPI", version="1.0.0")
|
||||
|
||||
|
|
@ -12,6 +13,7 @@ app.add_middleware(
|
|||
)
|
||||
|
||||
app.include_router(readings_router)
|
||||
app.include_router(devices_router)
|
||||
|
||||
@app.get("/health")
|
||||
def health():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue