From e987f732a7ad2d85a5760061a20873b841c10fac Mon Sep 17 00:00:00 2001 From: Matheus Date: Mon, 3 Nov 2025 14:24:30 -0300 Subject: optional installation date --- api/routes/sensors.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'api') 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() -- cgit v1.2.3