|
@@ -1,7 +1,7 @@
|
|
from fastapi import FastAPI, Depends, HTTPException, Request, Form, status
|
|
from fastapi import FastAPI, Depends, HTTPException, Request, Form, status
|
|
from fastapi.responses import RedirectResponse
|
|
from fastapi.responses import RedirectResponse
|
|
from fastapi.templating import Jinja2Templates
|
|
from fastapi.templating import Jinja2Templates
|
|
-from sqlalchemy import create_engine, Column, Integer, String, Date, Identity, Boolean, Text
|
|
|
|
|
|
+from sqlalchemy import create_engine, Column, Integer, String, Date, Identity, Boolean, Text , TIMESTAMP
|
|
from sqlalchemy.orm import sessionmaker, declarative_base, Session
|
|
from sqlalchemy.orm import sessionmaker, declarative_base, Session
|
|
from geoalchemy2 import Geometry, Geography
|
|
from geoalchemy2 import Geometry, Geography
|
|
#from keycloak import KeycloakOpenID
|
|
#from keycloak import KeycloakOpenID
|
|
@@ -18,8 +18,8 @@ from datetime import date, datetime
|
|
templates = Jinja2Templates(directory="templates")
|
|
templates = Jinja2Templates(directory="templates")
|
|
|
|
|
|
# Configurazione del database PostgreSQL
|
|
# Configurazione del database PostgreSQL
|
|
-# SQLALCHEMY_DATABASE_URL = "postgresql://postgres:postgres@165.22.75.145:15432/GenerationDAITA25"
|
|
|
|
-SQLALCHEMY_DATABASE_URL = "postgresql://postgres:postgres@165.22.75.145:15432/backend"
|
|
|
|
|
|
+SQLALCHEMY_DATABASE_URL = "postgresql://postgres:postgres@165.22.75.145:15432/GenerationDAITA25"
|
|
|
|
+#SQLALCHEMY_DATABASE_URL = "postgresql://postgres:postgres@165.22.75.145:15432/backend"
|
|
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
|
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
|
|
@@ -35,59 +35,71 @@ app = FastAPI()
|
|
|
|
|
|
Base = declarative_base()
|
|
Base = declarative_base()
|
|
|
|
|
|
-# Base.metadata.drop_all(engine)
|
|
|
|
|
|
+
|
|
class TabellaEdifici(Base):
|
|
class TabellaEdifici(Base):
|
|
- __tablename__ = 'tabella_edifici' # codice_catastale della tabella nel database
|
|
|
|
|
|
+ __tablename__ = 'edifici' # codice_catastale della tabella nel database
|
|
id_ = Column(Integer, primary_key=True, name='id_') # Identity() per autoincrement in PostgreSQL
|
|
id_ = Column(Integer, primary_key=True, name='id_') # Identity() per autoincrement in PostgreSQL
|
|
id_codice_fiscale = Column(String(16), name='id_codice_fiscale')
|
|
id_codice_fiscale = Column(String(16), name='id_codice_fiscale')
|
|
id_edificio_osm = Column(String(30), nullable=False, name='id_edificio')
|
|
id_edificio_osm = Column(String(30), nullable=False, name='id_edificio')
|
|
indirizzo = Column(String(100), nullable=False)
|
|
indirizzo = Column(String(100), nullable=False)
|
|
codice_catastale = Column(String(50), nullable=True)
|
|
codice_catastale = Column(String(50), nullable=True)
|
|
- #coordinate = Column(Geometry(geometry_type='POINT', srid=4326)) # SRID 4326 è lo standard per latitudine/longitudine
|
|
|
|
- #poligono = Column(Geometry(geometry_type='POLYGON', srid=4326)) # Poligono
|
|
|
|
|
|
+ coordinate = Column(Geometry(geometry_type='POINT', srid=4326)) # SRID 4326 è lo standard per latitudine/longitudine
|
|
|
|
+ poligono = Column(Geometry(geometry_type='POLYGON', srid=4326)) # Poligono
|
|
tipo_edificio = Column(String(100))
|
|
tipo_edificio = Column(String(100))
|
|
- stato = Column(Integer, default = 1)
|
|
|
|
|
|
+ stato = Column(Boolean, default=True)
|
|
data_installazione = Column(Date, nullable=False)
|
|
data_installazione = Column(Date, nullable=False)
|
|
data_cancellazione = Column(Date, nullable=True)
|
|
data_cancellazione = Column(Date, nullable=True)
|
|
|
|
|
|
|
|
|
|
class TabellaTFO(Base): # Puoi scegliere un nome più descrittivo per la tua tabella
|
|
class TabellaTFO(Base): # Puoi scegliere un nome più descrittivo per la tua tabella
|
|
- __tablename__ = 'tabella_TFO' # Scegli un nome per la tabella nel database
|
|
|
|
|
|
+ __tablename__ = 'tfo' # Scegli un nome per la tabella nel database
|
|
id_ = Column(Integer, primary_key=True, name='id_') # Chiave primaria, autoincrement
|
|
id_ = Column(Integer, primary_key=True, name='id_') # Chiave primaria, autoincrement
|
|
id_codice_fiscale = Column(String(16), name='id_codice_fiscale')
|
|
id_codice_fiscale = Column(String(16), name='id_codice_fiscale')
|
|
id_tfo = Column(String(30), nullable=False, name='id_tfo') # Not Null
|
|
id_tfo = Column(String(30), nullable=False, name='id_tfo') # Not Null
|
|
- ### codice_catastale = Column(String(50), nullable=True, name='codice_catastale') # Not Null
|
|
|
|
- operatore = Column(String(20))
|
|
|
|
|
|
+ codice_catastale = Column(String(50), nullable=True, name='codice_catastale') # Not Null
|
|
|
|
+ operatore = Column(String(255))
|
|
piano = Column(String(50))
|
|
piano = Column(String(50))
|
|
scala = Column(String(50))
|
|
scala = Column(String(50))
|
|
interno = Column(String(50))
|
|
interno = Column(String(50))
|
|
id_edificio = Column(String(30), nullable=False, name='id_edificio') # Not Null
|
|
id_edificio = Column(String(30), nullable=False, name='id_edificio') # Not Null
|
|
- data_installazione = Column(Date, name='data_installazione')
|
|
|
|
- data_cancellazione = Column(Date, name='data_cancellazione')
|
|
|
|
|
|
+ data_installazione = Column(Date, nullable=False, name='data_installazione')
|
|
|
|
+ data_cancellazione = Column(Date, nullable=True, name='data_cancellazione')
|
|
|
|
|
|
|
|
|
|
class TabellaUtenti(Base): # Nome descrittivo per la tabella
|
|
class TabellaUtenti(Base): # Nome descrittivo per la tabella
|
|
- __tablename__ = 'tabella_utenti' # Nome tabella nel database
|
|
|
|
|
|
+ __tablename__ = 'utenti' # Nome tabella nel database
|
|
id_ = Column(Integer, primary_key=True, name='id_') # Chiave primaria, autoincrement
|
|
id_ = Column(Integer, primary_key=True, name='id_') # Chiave primaria, autoincrement
|
|
codice_fiscale = Column(String(16), name='codice_fiscale')
|
|
codice_fiscale = Column(String(16), name='codice_fiscale')
|
|
- nome = Column(String(50), nullable=False) # Not Null
|
|
|
|
- cognome = Column(String(50), nullable=False) # Not Null
|
|
|
|
- email = Column(String(50), nullable=False) # Not Null
|
|
|
|
- ente = Column(String(50))
|
|
|
|
- ruolo = Column(String(50))
|
|
|
|
|
|
+ nome = Column(String(255), nullable=False) # Not Null
|
|
|
|
+ cognome = Column(String(255), nullable=False) # Not Null
|
|
|
|
+ email = Column(String(100), nullable=False) # Not Null
|
|
|
|
+ ente = Column(String(255))
|
|
|
|
+ ruolo = Column(String(255))
|
|
stato_utente = Column(Boolean)
|
|
stato_utente = Column(Boolean)
|
|
|
|
|
|
class TabellaLogEventi(Base): # Nome descrittivo per la tabella di log
|
|
class TabellaLogEventi(Base): # Nome descrittivo per la tabella di log
|
|
- __tablename__ = 'tabella_log_eventi' # Nome tabella nel database (scegli un nome appropriato)
|
|
|
|
|
|
+ __tablename__ = 'log_' # Nome tabella nel database (scegli un nome appropriato)
|
|
id_ = Column(Integer, primary_key=True, name='id_') # Chiave primaria, autoincrement
|
|
id_ = Column(Integer, primary_key=True, name='id_') # Chiave primaria, autoincrement
|
|
id_edificio = Column(Integer, name='id_edificio')
|
|
id_edificio = Column(Integer, name='id_edificio')
|
|
id_tfo = Column(String(30), name='id_tfo')
|
|
id_tfo = Column(String(30), name='id_tfo')
|
|
id_utente = Column(String(16), name='id_utente')
|
|
id_utente = Column(String(16), name='id_utente')
|
|
- data = Column(Date, nullable=False, name='data_log') # Timestamp senza timezone, Not Null, default CURRENT_TIMESTAMP
|
|
|
|
|
|
+ data = Column(TIMESTAMP, default =datetime.now(), name='data') # Timestamp senza timezone, Not Null, default CURRENT_TIMESTAMP
|
|
categoria_modifica = Column(String(255), name='categoria_modifica')
|
|
categoria_modifica = Column(String(255), name='categoria_modifica')
|
|
- descrizione_evento = Column(Text, name='descrizione_evento')
|
|
|
|
|
|
+ descrizione_evento = Column(String(4000), name='descrizione_evento')
|
|
|
|
+
|
|
|
|
+class Assistenza(Base):
|
|
|
|
+ __tablename__ = 'assistenza'
|
|
|
|
+
|
|
|
|
+ id_ticket = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
+ nome = Column(String(50))
|
|
|
|
+ cognome = Column(String(50))
|
|
|
|
+ email = Column(String(100), unique=True, nullable=False)
|
|
|
|
+ data_richiesta = Column(TIMESTAMP, default=func.current_timestamp())
|
|
|
|
+ descrizione_problema = Column(String(4000))
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
+# Base.metadata.drop_all(engine)
|
|
# Base.metadata.create_all(bind=engine)
|
|
# Base.metadata.create_all(bind=engine)
|
|
####
|
|
####
|
|
accesso_modifica = "Francesco"
|
|
accesso_modifica = "Francesco"
|
|
@@ -99,10 +111,6 @@ def get_buildings_by_user(db):
|
|
def get_specific_building(db, building_id):
|
|
def get_specific_building(db, building_id):
|
|
return db.query(TabellaEdifici).filter(TabellaEdifici.id_edificio_osm == building_id).first()
|
|
return db.query(TabellaEdifici).filter(TabellaEdifici.id_edificio_osm == building_id).first()
|
|
|
|
|
|
-# def get_specific_building_active(db, building_id):
|
|
|
|
-# query1 = db.query(TabellaEdifici).filter(TabellaEdifici.id_edificio_osm == building_id).all()
|
|
|
|
-# return db.query(query1).filter(query1.TabellaEdifici.data_cancellazione is null).first()
|
|
|
|
-
|
|
|
|
############Funzione per filtro ricerca
|
|
############Funzione per filtro ricerca
|
|
def filtro_ricerca_indirizzo(db, filtro):
|
|
def filtro_ricerca_indirizzo(db, filtro):
|
|
return db.query(TabellaEdifici).filter(TabellaEdifici.indirizzo.ilike(f"%{filtro}%")).all()
|
|
return db.query(TabellaEdifici).filter(TabellaEdifici.indirizzo.ilike(f"%{filtro}%")).all()
|
|
@@ -136,19 +144,6 @@ def filtro_ricerca_totale(db, filtro_indirizzo, filtro_data, filtro_id_edificio_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
@app.get("/")
|
|
@app.get("/")
|
|
async def home(request: Request):
|
|
async def home(request: Request):
|
|
return templates.TemplateResponse("login.html", {"request": request})
|
|
return templates.TemplateResponse("login.html", {"request": request})
|
|
@@ -244,19 +239,21 @@ async def ripristina(request: Request,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-# def aggiungi_prova():
|
|
|
|
-# with SessionLocal() as db:
|
|
|
|
-# edificio = TabellaEdifici(id_codice_fiscale="id_codix",
|
|
|
|
-# id_edificio_osm="ED006",
|
|
|
|
-# indirizzo=" corso italia 1",
|
|
|
|
-# codice_catastale="1244",
|
|
|
|
-# tipo_edificio="commerciale",
|
|
|
|
-# data_installazione=datetime.strptime("12/11/2021", "%d/%m/%Y").date(),
|
|
|
|
-# stato=1)
|
|
|
|
-# db.add(edificio)
|
|
|
|
-# db.commit()
|
|
|
|
|
|
+def aggiungi_prova():
|
|
|
|
+ with SessionLocal() as db:
|
|
|
|
+ edificio = TabellaEdifici(id_codice_fiscale="RSSMRA80A01H501Z",
|
|
|
|
+ id_edificio_osm="ED006",
|
|
|
|
+ indirizzo="corso italia 1",
|
|
|
|
+ codice_catastale="1244",
|
|
|
|
+ coordinate="POINT(12.496365 41.902782)",
|
|
|
|
+ poligono="POLYGON((12.496365 41.902782, 12.496365 41.902782, 12.496365 41.902782, 12.496365 41.902782, 12.496365 41.902782))",
|
|
|
|
+ tipo_edificio="commerciale",
|
|
|
|
+ data_installazione=datetime.strptime("12/11/2021", "%d/%m/%Y").date()
|
|
|
|
+ )
|
|
|
|
+ db.add(edificio)
|
|
|
|
+ db.commit()
|
|
|
|
|
|
-# aggiungi_prova()
|
|
|
|
|
|
+aggiungi_prova()
|
|
|
|
|
|
|
|
|
|
|
|
|