MatteoScript commited on
Commit
712433f
·
verified ·
1 Parent(s): 91e849f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +30 -28
main.py CHANGED
@@ -59,42 +59,44 @@ def crea_database_azienda(database, azienda):
59
  async def receive_post(request: Request, azione: str, versione :str, database: str, azienda: str):
60
  data = await request.json()
61
  print(json.dumps(data, indent=3))
62
- conn = get_db_connection()
63
- cursor = conn.cursor()
64
- crea_database_azienda(database, azienda)
65
- insert_query = f"INSERT INTO [{database}].dbo.{azienda}transazioni (datreg, azione, id_transazione, JsonCompleto) VALUES (?, ?, ?, ?)"
66
- cursor.execute(insert_query, (datetime.now(), azione, data.get('transazione_id'), json.dumps(data)))
67
- conn.commit()
68
- cursor.close()
69
- conn.close()
70
  return JSONResponse(content={"message": "Received", "data": data})
71
 
72
  # ------------------------------------------------| GET |-----------------------------------------------------
73
  # Result/Status transazione (Questo endpoint viene chiamato da AdHoc per leggere il risultato della transazione) /dati-registri/v1.0/id_transazione/STATUS/Azienda
74
  @app.get("/{azione}/{versione}/{database}/{azienda}/{id_transazione}/{tipo}")
75
  async def get_status(azione: str, versione: str, id_transazione: str, tipo: str, database: str, azienda: str):
76
- conn = get_db_connection()
77
- cursor = conn.cursor()
78
- select_query = f"SELECT TOP 1 JsonCompleto FROM [{database}].dbo.{azienda}transazioni WHERE azione = ? AND id_transazione = ? order by id desc"
79
- cursor.execute(select_query, (azione, id_transazione))
80
- row = cursor.fetchone()
81
- cursor.close()
82
- conn.close()
 
 
83
  # STATUS: Restituisce 303 se esiste la riga della transazione (cioè se per il rentri è terminata)
84
- if tipo == "status":
85
- if not row:
86
- raise HTTPException(status_code=200, detail="Transazione non terminata")
87
- else:
88
- raise HTTPException(status_code=303, detail="Transazione terminata")
89
  # RESULT: Restituisce 303 se esiste la riga della transazione (cioè se per il rentri è terminata)
90
- elif tipo == "result":
91
- if not row:
92
- raise HTTPException(status_code=404, detail="Transazione non terminata")
93
- else:
94
- result = json.loads(row.JsonCompleto)
95
- return JSONResponse(content=result)
96
- else:
97
- raise HTTPException(status_code=404, detail="Endpoint non trovato")
98
 
99
  @app.get("/")
100
  def read_general():
 
59
  async def receive_post(request: Request, azione: str, versione :str, database: str, azienda: str):
60
  data = await request.json()
61
  print(json.dumps(data, indent=3))
62
+ #conn = get_db_connection()
63
+ #cursor = conn.cursor()
64
+ #crea_database_azienda(database, azienda)
65
+ #insert_query = f"INSERT INTO [{database}].dbo.{azienda}transazioni (datreg, azione, id_transazione, JsonCompleto) VALUES (?, ?, ?, ?)"
66
+ #cursor.execute(insert_query, (datetime.now(), azione, data.get('transazione_id'), json.dumps(data)))
67
+ #conn.commit()
68
+ #cursor.close()
69
+ #conn.close()
70
  return JSONResponse(content={"message": "Received", "data": data})
71
 
72
  # ------------------------------------------------| GET |-----------------------------------------------------
73
  # Result/Status transazione (Questo endpoint viene chiamato da AdHoc per leggere il risultato della transazione) /dati-registri/v1.0/id_transazione/STATUS/Azienda
74
  @app.get("/{azione}/{versione}/{database}/{azienda}/{id_transazione}/{tipo}")
75
  async def get_status(azione: str, versione: str, id_transazione: str, tipo: str, database: str, azienda: str):
76
+ print('{"message": "OK"}')
77
+ return '{"message": "OK"}'
78
+ #conn = get_db_connection()
79
+ #cursor = conn.cursor()
80
+ #select_query = f"SELECT TOP 1 JsonCompleto FROM [{database}].dbo.{azienda}transazioni WHERE azione = ? AND id_transazione = ? order by id desc"
81
+ #cursor.execute(select_query, (azione, id_transazione))
82
+ #row = cursor.fetchone()
83
+ #cursor.close()
84
+ #conn.close()
85
  # STATUS: Restituisce 303 se esiste la riga della transazione (cioè se per il rentri è terminata)
86
+ #if tipo == "status":
87
+ # if not row:
88
+ # raise HTTPException(status_code=200, detail="Transazione non terminata")
89
+ # else:
90
+ # raise HTTPException(status_code=303, detail="Transazione terminata")
91
  # RESULT: Restituisce 303 se esiste la riga della transazione (cioè se per il rentri è terminata)
92
+ #elif tipo == "result":
93
+ # if not row:
94
+ # raise HTTPException(status_code=404, detail="Transazione non terminata")
95
+ # else:
96
+ # result = json.loads(row.JsonCompleto)
97
+ # return JSONResponse(content=result)
98
+ #else:
99
+ # raise HTTPException(status_code=404, detail="Endpoint non trovato")
100
 
101
  @app.get("/")
102
  def read_general():