Compare commits
1 Commits
main
...
sql-to-api
| Author | SHA1 | Date | |
|---|---|---|---|
| b5c84635cf |
+37
-9
@@ -139,10 +139,13 @@ def get_client_uuid_by_name(client_name, user_id):
|
|||||||
query = ("select uuid from oc_timemanager_client where name=\""+client_name+"\" AND user_id=\""+user_id+"\"")
|
query = ("select uuid from oc_timemanager_client where name=\""+client_name+"\" AND user_id=\""+user_id+"\"")
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
|
||||||
client_uuid = cursor.fetchone()[0]
|
row = cursor.fetchone()
|
||||||
save_db()
|
save_db()
|
||||||
|
|
||||||
return client_uuid.decode('utf-8')
|
if not row:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return row[0].decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
def get_project_uuid_by_name(project_name, client_uuid, user_id):
|
def get_project_uuid_by_name(project_name, client_uuid, user_id):
|
||||||
@@ -311,15 +314,28 @@ def create_client(name):
|
|||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post(url, data=json.dumps(req_data), headers=headers)
|
response = requests.post(url, data=json.dumps(req_data), headers=headers)
|
||||||
|
|
||||||
# Vérification de la réponse
|
# Vérification de la réponse
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
pass
|
try:
|
||||||
#print("Client créé avec succès.")
|
resp = response.json()
|
||||||
#print(json.dumps(response.json(), indent=1))
|
# Tenter d'extraire l'UUID renvoyé par l'API (structure attendue)
|
||||||
|
client_uuid = None
|
||||||
|
if isinstance(resp, dict):
|
||||||
|
client_created = resp.get('data', {}).get('clients', {}).get('created', [])
|
||||||
|
if client_created and isinstance(client_created, list):
|
||||||
|
client_uuid = client_created[0].get('uuid')
|
||||||
|
|
||||||
|
if client_uuid:
|
||||||
|
return client_uuid
|
||||||
|
# si pas d'uuid dans la réponse, retourner None (le caller gérera)
|
||||||
|
return None
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
print("Erreur de création client")
|
print("Erreur de création client")
|
||||||
print(response.reason)
|
print(response.reason)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def insert_task_time(name, project_name, client_name, task_uuid, user_id, dstart, hstart, dend, hend):
|
def insert_task_time(name, project_name, client_name, task_uuid, user_id, dstart, hstart, dend, hend):
|
||||||
@@ -422,11 +438,23 @@ for user_info in config['calendars']:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Description => Client
|
# Description => Client
|
||||||
|
client_uuid = None
|
||||||
if not client_exist_by_name(client_name, user_id):
|
if not client_exist_by_name(client_name, user_id):
|
||||||
print("Création du client {}".format(client_name))
|
print("Création du client {}".format(client_name))
|
||||||
create_client(client_name)
|
created_uuid = create_client(client_name)
|
||||||
|
if created_uuid:
|
||||||
client_uuid = get_client_uuid_by_name(client_name, user_id)
|
client_uuid = created_uuid
|
||||||
|
else:
|
||||||
|
# tentative de récupération depuis la base au cas où l'API a créé l'entrée
|
||||||
|
client_uuid = get_client_uuid_by_name(client_name, user_id)
|
||||||
|
if not client_uuid:
|
||||||
|
print("Erreur: impossible d'obtenir l'UUID du client '{}' après création, saut.".format(client_name))
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
client_uuid = get_client_uuid_by_name(client_name, user_id)
|
||||||
|
if not client_uuid:
|
||||||
|
print("Erreur: le client '{}' existe mais son UUID est introuvable, saut.".format(client_name))
|
||||||
|
continue
|
||||||
|
|
||||||
# Categories => Project
|
# Categories => Project
|
||||||
if not project_exist_by_name(project_name, client_uuid, user_id):
|
if not project_exist_by_name(project_name, client_uuid, user_id):
|
||||||
|
|||||||
Reference in New Issue
Block a user