Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sensors): endpoints for sensors #52

Merged
merged 4 commits into from
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/api/v1/endpoints/sensors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from fastapi import APIRouter, HTTPException, Query, Request, status, Depends
from injector import Injector, inject
from src.service.file_service import MAX_FILE_SIZE, FileService
from sqlmodel import Session, select
from src.domain.entities.sensor_history import SensorHistory
from src.core.db.connection import get_session

router = APIRouter()

Expand Down Expand Up @@ -33,3 +36,16 @@
status_code=400, detail=f"Evento {event} no implementado")

return status.HTTP_200_OK


@router.get("/sensors", response_model=list[SensorHistory])
def get_sensors(skip: int = 0, limit: int = 10, session: Session = Depends(get_session)):
return session.exec(select(SensorHistory).offset(skip).limit(limit)).all()

Check warning on line 43 in src/api/v1/endpoints/sensors.py

View check run for this annotation

Codecov / codecov/patch

src/api/v1/endpoints/sensors.py#L43

Added line #L43 was not covered by tests


@router.get("/sensors/{sensor_id}", response_model=SensorHistory)
def get_sensor(sensor_id: int, session: Session = Depends(get_session)):
sensor = session.get(SensorHistory, sensor_id)
if not sensor:
raise HTTPException(status_code=404, detail="Sensor not found")
return sensor

Check warning on line 51 in src/api/v1/endpoints/sensors.py

View check run for this annotation

Codecov / codecov/patch

src/api/v1/endpoints/sensors.py#L48-L51

Added lines #L48 - L51 were not covered by tests