From 42940e966a9ea0f8aedcb995919015692a7c5311 Mon Sep 17 00:00:00 2001 From: Jose <100301878+Gallardo7761@users.noreply.github.com> Date: Tue, 11 Mar 2025 19:28:17 +0100 Subject: [PATCH] Delete backend/fastapi directory --- backend/fastapi/.env | 4 -- backend/fastapi/config.py | 1 - backend/fastapi/db.py | 7 -- .../__pycache__/sensors.cpython-312.pyc | Bin 4668 -> 0 bytes backend/fastapi/endpoints/sensors.py | 67 ------------------ backend/fastapi/main.py | 36 ---------- backend/fastapi/models/schemas/SensorModel.py | 12 ---- .../__pycache__/SensorModel.cpython-312.pyc | Bin 675 -> 0 bytes backend/fastapi/models/sql/Sensor.py | 14 ---- .../sql/__pycache__/Sensor.cpython-312.pyc | Bin 796 -> 0 bytes backend/fastapi/requirements.txt | 8 --- backend/fastapi/run.py | 14 ---- 12 files changed, 163 deletions(-) delete mode 100644 backend/fastapi/.env delete mode 100644 backend/fastapi/config.py delete mode 100644 backend/fastapi/db.py delete mode 100644 backend/fastapi/endpoints/__pycache__/sensors.cpython-312.pyc delete mode 100644 backend/fastapi/endpoints/sensors.py delete mode 100644 backend/fastapi/main.py delete mode 100644 backend/fastapi/models/schemas/SensorModel.py delete mode 100644 backend/fastapi/models/schemas/__pycache__/SensorModel.cpython-312.pyc delete mode 100644 backend/fastapi/models/sql/Sensor.py delete mode 100644 backend/fastapi/models/sql/__pycache__/Sensor.cpython-312.pyc delete mode 100644 backend/fastapi/requirements.txt delete mode 100644 backend/fastapi/run.py diff --git a/backend/fastapi/.env b/backend/fastapi/.env deleted file mode 100644 index 0822967..0000000 --- a/backend/fastapi/.env +++ /dev/null @@ -1,4 +0,0 @@ -# esto esta aqui porque es un entorno local -# y además un usuario y contraseña bastante -# genéricos -DB_URL = "mysql+aiomysql://root:root@localhost:3306/DAD" \ No newline at end of file diff --git a/backend/fastapi/config.py b/backend/fastapi/config.py deleted file mode 100644 index 815f7df..0000000 --- a/backend/fastapi/config.py +++ /dev/null @@ -1 +0,0 @@ -API_PREFIX = "/api/v1" \ No newline at end of file diff --git a/backend/fastapi/db.py b/backend/fastapi/db.py deleted file mode 100644 index e8df993..0000000 --- a/backend/fastapi/db.py +++ /dev/null @@ -1,7 +0,0 @@ -from databases import Database -import os -from dotenv import load_dotenv - -load_dotenv() -DB_URL = os.getenv("DB_URL") -database = Database(DB_URL) \ No newline at end of file diff --git a/backend/fastapi/endpoints/__pycache__/sensors.cpython-312.pyc b/backend/fastapi/endpoints/__pycache__/sensors.cpython-312.pyc deleted file mode 100644 index f5f448c967b94074c288a63263ac38b9288cfd7a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4668 zcmcgvUu+Y}8K2$t{&8$4w)4kH>?97(KSK^US_%|OdohpzC3huo(pk~D8_y;= zT?jQjuBon|_5q}}@X!Y;^??db;t}%8T z;YtzeSUdiG-+c3%Z)az|Z{|~vrvX99d;c`^sSBaMQNb?F>)`207NHvmBh08sW8#d) z##xPvbDAUWV7^Yzs=Ow|1F(;an~&bQtl*c8#jH_-xv(T`z%f5YD3KH_gP^InOfaJ@AA{zj&4~~C@)f-u9h$@U+s&1d-62wQGN1QMpq_hQpRK~lQv{6 zl|DT&IVC60Drr0k&s-*zHuTBze$}_nl|7@Qkv?E+gh&4~RR2KFE~9_Bk*E1r2aE14 zmk&P{-77BNwRivG3a+$t+!((;{`)<54=!)pU)Z+){^?>Qwj3ENM8=AdW5t%^R}Zf} z*QVHV=n61-R=lk@T-RMUj}*O;EBxP^0?SR2LQ|yJ)c+-7_&1->>aT&G# zKz~u(QJzbaP2r1eM-M>^QNv{w1dyq$o|K8{Dk~Dk{G4*J@l*=J9)z0pj!yVUi66;o zR>{(j{I0A*MAQ~PPM0H+&1O0^`NDJT?8sHIlPI5|XmeS5)Hnq|A+nJr5Y8-8*_0^L z3oIy|Y`Q7OnXHz=DPulM_v=_zQ?QIH9B#_-0t<^HxiLmnBI63|=a-0#QVxAMoRgj# z4=ZtWRsg?h%JU;5jjwiWxFqG6SLC)1b(;swS+RQqH~Wg*G+xw{9D8C)D^YzD90wv)_h&4M4LkHPZ*;*XF=# z&$jxWIm!N}bve-aUvr@If6jr>V?z#P#-r{H*^fVeMj;C60xwBFtp=bnc`MXG&Z`6_ z#gyzoV&y~9Lyf~wK{Bm$B=o>WU?U?ErPWqiZKKsNt$Jy-1uC8HQY$N36^VdodLaEm z8cxi~MAme&3v^Vk{~C^G9`1?z} ziL$Ui|NZHu-kHrpxc?Tuw>5t(u@wH{qfJ6z^mgC9bpB*=sSiKeC_M4?fUA=CTJu#; zi37am>$n-Y-c{lOgR9>5oBY)eN+OjcTXIsV0W}4#Wv^yRE-JZg$wQ?^)EvCI`}&Sj W6P3K{(ie0r`oe)HEFdxh-{U{G025pQ diff --git a/backend/fastapi/endpoints/sensors.py b/backend/fastapi/endpoints/sensors.py deleted file mode 100644 index 4cb809f..0000000 --- a/backend/fastapi/endpoints/sensors.py +++ /dev/null @@ -1,67 +0,0 @@ -from fastapi import APIRouter, Body, HTTPException, Query -from fastapi import APIRouter, Body, HTTPException, Query -from typing import Optional -from pydantic import BaseModel -from sqlalchemy import select, insert -from sqlalchemy.ext.asyncio import AsyncSession -from sqlalchemy.future import select -from models.sql.Sensor import sensor_mq_data -from db import database -from models.schemas.SensorModel import SensorModel - -router = APIRouter() - -@router.get("") -async def get_all( - _sort: Optional[str] = Query(None, alias="_sort", description="Campo por el cual ordenar los resultados"), - _order: Optional[str] = Query("asc", description="Orden de los resultados, 'asc' o 'desc'"), - _limit: Optional[int] = Query(100, ge=1, description="Número máximo de resultados a mostrar"), -): - query = select(sensor_mq_data) - - if _sort: - if _order == "desc": - query = query.order_by(getattr(sensor_mq_data.c, _sort).desc()) - else: - query = query.order_by(getattr(sensor_mq_data.c, _sort)) - - if _limit: - query = query.limit(_limit) - - async with database.transaction(): - result = await database.fetch_all(query) - return result - -@router.get("/sensor") -async def get_by_params( - id: Optional[int] = Query(None, alias="id", description="ID del sensor a buscar"), - sensor_type: Optional[str] = Query(None, alias="sensor_type", description="Tipo de sensor"), - min_value: Optional[float] = Query(None, alias="min_value", description="Valor mínimo del sensor"), - max_value: Optional[float] = Query(None, alias="max_value", description="Valor máximo del sensor"), - min_temp: Optional[float] = Query(None, alias="min_temp", description="Temperatura mínima"), - max_temp: Optional[float] = Query(None, alias="max_temp", description="Temperatura máxima"), - min_humidity: Optional[float] = Query(None, alias="min_humidity", description="Humedad mínima"), - max_humidity: Optional[float] = Query(None, alias="max_humidity", description="Humedad máxima"), -): - query = select(sensor_mq_data) - - if id is not None: - query = query.where(sensor_mq_data.c.id == id) - if sensor_type is not None: - query = query.where(sensor_mq_data.c.sensor_type == sensor_type) - if min_value is not None: - query = query.where(sensor_mq_data.c.value >= min_value) - if max_value is not None: - query = query.where(sensor_mq_data.c.value <= max_value) - if min_temp is not None: - query = query.where(sensor_mq_data.c.temperature >= min_temp) - if max_temp is not None: - query = query.where(sensor_mq_data.c.temperature <= max_temp) - if min_humidity is not None: - query = query.where(sensor_mq_data.c.humidity >= min_humidity) - if max_humidity is not None: - query = query.where(sensor_mq_data.c.humidity <= max_humidity) - - async with database.transaction(): - result = await database.fetch_all(query) - return result \ No newline at end of file diff --git a/backend/fastapi/main.py b/backend/fastapi/main.py deleted file mode 100644 index 6ef4fb4..0000000 --- a/backend/fastapi/main.py +++ /dev/null @@ -1,36 +0,0 @@ -from fastapi import FastAPI -from contextlib import asynccontextmanager -from fastapi.middleware.cors import CORSMiddleware - -from fastapi.responses import JSONResponse -from config import API_PREFIX -from fastapi.openapi.utils import get_openapi -from endpoints import sensors -from db import database - -@asynccontextmanager -async def lifespan(app: FastAPI): - await database.connect() # Conecta la base de datos al iniciar - yield - await database.disconnect() # Desconecta al finalizar - -app = FastAPI( - title="Mi API de Calidad del Aire", - description="API para obtener mediciones de calidad del aire en Sevilla", - version="1.0.0", - docs_url=f"{API_PREFIX}/swagger", # Cambia la URL de Swagger UI - lifespan=lifespan, - openapi_url="/dad/openapi.json" -) - -app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"]) - -@app.get(f"{API_PREFIX}/") -async def root(): - return {"message": "Has llegado a la raíz de la API"} - -@app.get(f"{API_PREFIX}/openapi.json", include_in_schema=False) -async def get_openapi_json(): - return JSONResponse(content=get_openapi(title="Mi API de Calidad del Aire", version="1.0.0", routes=app.routes)) - -app.include_router(sensors.router, prefix=f"{API_PREFIX}/sensors", tags=["sensors"]) \ No newline at end of file diff --git a/backend/fastapi/models/schemas/SensorModel.py b/backend/fastapi/models/schemas/SensorModel.py deleted file mode 100644 index 81d7659..0000000 --- a/backend/fastapi/models/schemas/SensorModel.py +++ /dev/null @@ -1,12 +0,0 @@ - -from pydantic import BaseModel -from datetime import datetime -from typing import Optional - -class SensorModel(BaseModel): - id: Optional[int] # pq el modelo se usará también para INSERT - sensor_type: str - lat: float - lon: float - value: float - timestamp: Optional[datetime] = None \ No newline at end of file diff --git a/backend/fastapi/models/schemas/__pycache__/SensorModel.cpython-312.pyc b/backend/fastapi/models/schemas/__pycache__/SensorModel.cpython-312.pyc deleted file mode 100644 index 1a77f30bf1cd3e35c191978e153ca679522c9065..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 675 zcmYk4J!=#}7{{O4x7)k(%!!Gjq99mg8?myGkRmC>ps@(oEDOVUGoFjHv+K^Bc%2Xh z?b5}sAbtsZ8zmOUKq|4Y6Hc2{KC^oX4(xw^&&)h;Gy7#Q=mCze!_Sku1mK4=PDi+e z#U{cbaNtBjK~h2-d(tbs)N9z6ei5Vr0T1p258eO|1^MK+{%JUilFlz@B*b>Nm==#p zE+iT;XGWO35RM;LCNC9})oNTx`Lh>5wAo*t$ zoKfhAM`?_{-KB5Gtzmt!?e7Vt%epDedO5d!-7HWutAzC>Gbp99;Y%i`V%K(E-P*9C zN_sY?RIx%(YI~FxC7(*i=O}$KWwPC=-E~?&SH`YT%9JV%a}8@e=xbBk@Tn}BsRwwh z4p2VA0u@fSw(n&lEoz+b4wl Wgd4|j{TQzO2_ljlB!2;?#`ho5t*m|k diff --git a/backend/fastapi/models/sql/Sensor.py b/backend/fastapi/models/sql/Sensor.py deleted file mode 100644 index 15e3e14..0000000 --- a/backend/fastapi/models/sql/Sensor.py +++ /dev/null @@ -1,14 +0,0 @@ -from sqlalchemy import Column, Integer, String, Float, TIMESTAMP, Table, MetaData, func - -metadata = MetaData() - -sensor_mq_data = Table( - "sensor_mq_data", - metadata, - Column("id", Integer, primary_key=True, autoincrement=True), - Column("sensor_type", String(50), nullable=False), # Tipo de sensor (MQ-135, etc.) - Column("lat", Float, nullable=False), # Latitud - Column("lon", Float, nullable=False), # Longitud - Column("value", Float, nullable=False), # Valor leído del sensor - Column("timestamp", TIMESTAMP, server_default=func.current_timestamp()) # Fecha automática -) \ No newline at end of file diff --git a/backend/fastapi/models/sql/__pycache__/Sensor.cpython-312.pyc b/backend/fastapi/models/sql/__pycache__/Sensor.cpython-312.pyc deleted file mode 100644 index d19f96a7c4b637d7dcd72831b1fed55aabcfb215..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 796 zcmZuvJ8Tm%81~)yE_ZqLK?MV1YZ2+d5K$q@ODLpDi-M4nD$?ns=o-7>sC}3E?kZ&h zHYAp8fLJnul7W$tou#OeTD+i&savINov`yj71YD$|Ns2k-)H;(p2;ME82hu|n%gP> zzhyEVGm~I=DuQ6COMNEg@DA==ZSSc!cEM$QHhx6H@Ut>0ypATb-i4yR3DX}alPtp z5zNgpj@-v?yzRy$dYVh~ zWVlOQ(s+((o5{Cj@&lMI!H|%UAg|9X39>1;NyRlrhUXeFW5QPbuL?_viqBvu5S-m9 ztU8-QGjukB5IapTateVj%y|B0#o2NjJJ?4K4G<=wBaAqe(R zkISFp0bG&!N@uCNG=Mk$jc<2~-QoZ)OaAVAYd>H5vUr#;{m7RN@*4yAWH@KdtFN={ Hs_^g!G<(=a diff --git a/backend/fastapi/requirements.txt b/backend/fastapi/requirements.txt deleted file mode 100644 index d318c19..0000000 --- a/backend/fastapi/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -uvicorn -fastapi -contextlib2 -dotenv -pydantic -sqlalchemy -databases -aiomysql diff --git a/backend/fastapi/run.py b/backend/fastapi/run.py deleted file mode 100644 index 3245e0a..0000000 --- a/backend/fastapi/run.py +++ /dev/null @@ -1,14 +0,0 @@ -import subprocess - -def run_api(): - try: - subprocess.run( - ['uvicorn', 'main:app', '--reload', '--port', '9091'], - check=True, - cwd='./' - ) - except subprocess.CalledProcessError as e: - print(f"Error al iniciar API DAD: {e.stderr}") - -if __name__ == "__main__": - run_api()