summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-11-03 14:24:30 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-11-03 14:24:30 -0300
commite987f732a7ad2d85a5760061a20873b841c10fac (patch)
treeae57c11fca1a461c5bbb19400d55ea9ecb74a82a
parent45463fd2d300feb56dbb5db0645e18fcaa1cc71e (diff)
optional installation date
-rw-r--r--api/routes/sensors.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/api/routes/sensors.py b/api/routes/sensors.py
index e9a2107..d1c4403 100644
--- a/api/routes/sensors.py
+++ b/api/routes/sensors.py
@@ -31,7 +31,7 @@ async def get_sensors():
class PostSensor(BaseModel):
name: str
- installation_date: int
+ installation_date: int | None = None
station_id: int
@router.post('/')
@@ -44,7 +44,10 @@ async def post_sensor(sensor: PostSensor):
status_code=404,
detail=f"Não existe estação com id {sensor.station_id}"
)
- installation_date = datetime.fromtimestamp(sensor.installation_date)
+ if not sensor.installation_date:
+ installation_date = station.installation_date
+ else:
+ installation_date = datetime.fromtimestamp(sensor.installation_date)
session.add(SensorDevice(name=sensor.name, installation_date=installation_date, station_id=sensor.station_id, is_active=True))
session.commit()