summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorLuiz Gustavo Monteiro <luizgu_mreis@hotmail.com>2025-11-03 23:39:34 -0300
committerLuiz Gustavo Monteiro <luizgu_mreis@hotmail.com>2025-11-03 23:39:34 -0300
commitf392c3edaf52ccfa496d2e85f96e18ec81d11a65 (patch)
tree17f15971a209936a774c9a313938452d986a89b5 /api
parente987f732a7ad2d85a5760061a20873b841c10fac (diff)
refactor Post methods in schema files
Diffstat (limited to 'api')
-rw-r--r--api/routes/locations.py7
-rw-r--r--api/routes/sensors.py7
-rw-r--r--api/routes/stations.py7
-rw-r--r--api/schemas/station.py6
4 files changed, 9 insertions, 18 deletions
diff --git a/api/routes/locations.py b/api/routes/locations.py
index 744fa7f..43578df 100644
--- a/api/routes/locations.py
+++ b/api/routes/locations.py
@@ -2,6 +2,7 @@ from fastapi import APIRouter
from sqlalchemy import select
from ..database import SessionLocal
from ..models import Location
+from ..schemas.location import PostLocation
from pydantic import BaseModel
@@ -28,12 +29,6 @@ async def get_locations():
session.close()
return dc
-
-class PostLocation(BaseModel):
- street: str
- avenue: str
- zip_code:str
-
@router.post('/')
async def create_location(location: PostLocation):
session = SessionLocal()
diff --git a/api/routes/sensors.py b/api/routes/sensors.py
index d1c4403..9c86309 100644
--- a/api/routes/sensors.py
+++ b/api/routes/sensors.py
@@ -2,7 +2,7 @@ from fastapi import APIRouter, HTTPException
from sqlalchemy import select
from ..database import SessionLocal
from ..models import SensorDevice, Station
-from pydantic import BaseModel
+from ..schemas.sensor import PostSensor
from datetime import datetime
router = APIRouter(
@@ -29,11 +29,6 @@ async def get_sensors():
session.close()
return dc
-class PostSensor(BaseModel):
- name: str
- installation_date: int | None = None
- station_id: int
-
@router.post('/')
async def post_sensor(sensor: PostSensor):
session = SessionLocal()
diff --git a/api/routes/stations.py b/api/routes/stations.py
index 0a753fe..c7cdf7c 100644
--- a/api/routes/stations.py
+++ b/api/routes/stations.py
@@ -2,7 +2,7 @@ from fastapi import APIRouter, HTTPException
from sqlalchemy import select
from ..database import SessionLocal
from ..models import Station, SensorDevice, Location
-from pydantic import BaseModel
+from ..schemas.station import PostStation
from datetime import datetime
router = APIRouter(
@@ -35,11 +35,6 @@ async def get_stations():
session.close()
return dc
-class PostStation(BaseModel):
- name: str
- installation_date: int
- location_id: int
-
@router.post('/')
async def post_station(station: PostStation):
session = SessionLocal()
diff --git a/api/schemas/station.py b/api/schemas/station.py
index e69de29..3e8dc10 100644
--- a/api/schemas/station.py
+++ b/api/schemas/station.py
@@ -0,0 +1,6 @@
+from pydantic import BaseModel
+
+class PostStation(BaseModel):
+ name: str
+ installation_date: int
+ location_id: int \ No newline at end of file