summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorLuiz Gustavo Monteiro <luizgu_mreis@hotmail.com>2025-10-28 20:25:17 -0300
committerLuiz Gustavo Monteiro <luizgu_mreis@hotmail.com>2025-10-28 20:25:17 -0300
commit6fed254c8033bf4c67b65328474df6807c3b7eb8 (patch)
treece57462722cdae066b706a78a06d586b5170951b /api
parent52a4fe2625b63683fcdcd74f704e49aa65cb0dd8 (diff)
refactor folders schema
Diffstat (limited to 'api')
-rw-r--r--api/Dockerfile0
-rw-r--r--api/__init__.py0
-rw-r--r--api/database.py10
-rw-r--r--api/main.py0
-rw-r--r--api/models.py81
-rw-r--r--api/requirements.txt0
-rw-r--r--api/routes/__init__.py0
-rw-r--r--api/routes/locations.py0
-rw-r--r--api/routes/measures.py0
-rw-r--r--api/routes/readings.py0
-rw-r--r--api/routes/sensors.py0
-rw-r--r--api/routes/stations.py0
-rw-r--r--api/schemas/__init__.py0
-rw-r--r--api/schemas/location.py0
-rw-r--r--api/schemas/measures.py0
-rw-r--r--api/schemas/reading.py0
-rw-r--r--api/schemas/sensor.py0
-rw-r--r--api/schemas/station.py0
-rw-r--r--api/services/__init__.py0
19 files changed, 91 insertions, 0 deletions
diff --git a/api/Dockerfile b/api/Dockerfile
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/Dockerfile
diff --git a/api/__init__.py b/api/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/__init__.py
diff --git a/api/database.py b/api/database.py
new file mode 100644
index 0000000..c0691a1
--- /dev/null
+++ b/api/database.py
@@ -0,0 +1,10 @@
+from sqlalchemy import create_engine
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.orm import sessionmaker
+import os
+
+DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://root:public@postgres:5432/control_station")
+
+engine = create_engine(DATABASE_URL)
+SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
+Base = declarative_base()
diff --git a/api/main.py b/api/main.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/main.py
diff --git a/api/models.py b/api/models.py
new file mode 100644
index 0000000..d6bd2ba
--- /dev/null
+++ b/api/models.py
@@ -0,0 +1,81 @@
+from sqlalchemy import Column, Integer, String, Float, DateTime, ForeignKey, Boolean
+from sqlalchemy.orm import relationship
+from sqlalchemy.sql import func
+from database import Base
+
+# ----------------------------
+# Location
+# ----------------------------
+class Location(Base):
+ __tablename__ = "locations"
+
+ id = Column(Integer, primary_key=True, index=True)
+ street = Column(String(200), nullable=True, index=True)
+ avenue = Column(String(200), nullable=True, index=True)
+ zip_code = Column(String(20), nullable=True, index=True)
+
+ # Relationship: One location to many stations
+ stations = relationship("Station", back_populates="location")
+
+
+# ----------------------------
+# Station
+# ----------------------------
+class Station(Base):
+ __tablename__ = "stations"
+
+ id = Column(Integer, primary_key=True, index=True)
+ name = Column(String(100), nullable=False, index=True)
+ location_id = Column(Integer, ForeignKey("locations.id"), nullable=True, index=True)
+ installation_date = Column(DateTime, server_default=func.now())
+ is_active = Column(Boolean, default=True)
+
+ # Relationships
+ location = relationship("Location", back_populates="stations")
+ sensor_devices = relationship("SensorDevice", back_populates="station")
+
+
+# ----------------------------
+# SensorDevice
+# ----------------------------
+class SensorDevice(Base):
+ __tablename__ = "sensor_devices"
+
+ id = Column(Integer, primary_key=True, index=True)
+ name = Column(String(100), nullable=True, index=True)
+ installation_date = Column(DateTime, server_default=func.now())
+ station_id = Column(Integer, ForeignKey("stations.id"), nullable=True, index=True)
+ is_active = Column(Boolean, default=True)
+
+ # Relationships
+ station = relationship("Station", back_populates="sensor_devices")
+ readings = relationship("Reading", back_populates="sensor_device")
+
+
+# ----------------------------
+# Measure
+# ----------------------------
+class Measure(Base):
+ __tablename__ = "measures"
+
+ id = Column(Integer, primary_key=True, index=True)
+ name = Column(String(50), nullable=True, index=True)
+
+ # Relationships
+ readings = relationship("Reading", back_populates="measure")
+
+
+# ----------------------------
+# Reading
+# ----------------------------
+class Reading(Base):
+ __tablename__ = "readings"
+
+ id = Column(Integer, primary_key=True, index=True)
+ sensor_device_id = Column(Integer, ForeignKey("sensor_devices.id"), nullable=True, index=True)
+ measure_id = Column(Integer, ForeignKey("measures.id"), nullable=True, index=True)
+ value = Column(Float, nullable=True)
+
+ # Relationships
+ sensor_device = relationship("SensorDevice", back_populates="readings")
+ measure = relationship("Measure", back_populates="readings")
diff --git a/api/requirements.txt b/api/requirements.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/requirements.txt
diff --git a/api/routes/__init__.py b/api/routes/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/routes/__init__.py
diff --git a/api/routes/locations.py b/api/routes/locations.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/routes/locations.py
diff --git a/api/routes/measures.py b/api/routes/measures.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/routes/measures.py
diff --git a/api/routes/readings.py b/api/routes/readings.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/routes/readings.py
diff --git a/api/routes/sensors.py b/api/routes/sensors.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/routes/sensors.py
diff --git a/api/routes/stations.py b/api/routes/stations.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/routes/stations.py
diff --git a/api/schemas/__init__.py b/api/schemas/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/schemas/__init__.py
diff --git a/api/schemas/location.py b/api/schemas/location.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/schemas/location.py
diff --git a/api/schemas/measures.py b/api/schemas/measures.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/schemas/measures.py
diff --git a/api/schemas/reading.py b/api/schemas/reading.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/schemas/reading.py
diff --git a/api/schemas/sensor.py b/api/schemas/sensor.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/schemas/sensor.py
diff --git a/api/schemas/station.py b/api/schemas/station.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/schemas/station.py
diff --git a/api/services/__init__.py b/api/services/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/api/services/__init__.py