Update modules/database/sql_db.py
Browse files- modules/database/sql_db.py +31 -8
modules/database/sql_db.py
CHANGED
@@ -269,8 +269,15 @@ def delete_student_user(username):
|
|
269 |
|
270 |
############################################
|
271 |
def store_application_request(name, lastname, email, institution, current_role, desired_role, reason):
|
272 |
-
|
273 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
application_request = {
|
275 |
"id": str(uuid.uuid4()),
|
276 |
"name": name,
|
@@ -280,19 +287,31 @@ def store_application_request(name, lastname, email, institution, current_role,
|
|
280 |
"current_role": current_role,
|
281 |
"desired_role": desired_role,
|
282 |
"reason": reason,
|
283 |
-
"requestDate": datetime.utcnow().isoformat()
|
|
|
|
|
284 |
}
|
285 |
-
|
286 |
-
|
|
|
|
|
287 |
return True
|
|
|
288 |
except Exception as e:
|
289 |
logger.error(f"Error al almacenar la solicitud de aplicaci贸n: {str(e)}")
|
290 |
return False
|
291 |
|
292 |
#########################################################
|
293 |
def store_student_feedback(username, name, email, feedback):
|
294 |
-
|
295 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
feedback_item = {
|
297 |
"id": str(uuid.uuid4()),
|
298 |
"username": username,
|
@@ -300,11 +319,15 @@ def store_student_feedback(username, name, email, feedback):
|
|
300 |
"email": email,
|
301 |
"feedback": feedback,
|
302 |
"role": "Estudiante",
|
303 |
-
|
|
|
304 |
}
|
305 |
-
|
306 |
-
|
|
|
|
|
307 |
return True
|
|
|
308 |
except Exception as e:
|
309 |
logger.error(f"Error al almacenar el feedback del estudiante {username}: {str(e)}")
|
310 |
return False
|
|
|
269 |
|
270 |
############################################
|
271 |
def store_application_request(name, lastname, email, institution, current_role, desired_role, reason):
|
272 |
+
"""Almacena una solicitud de aplicaci贸n"""
|
273 |
try:
|
274 |
+
# Obtener el contenedor usando get_container() que s铆 funciona
|
275 |
+
container = get_container("application_requests")
|
276 |
+
if not container:
|
277 |
+
logger.error("No se pudo obtener el contenedor de solicitudes")
|
278 |
+
return False
|
279 |
+
|
280 |
+
# Crear documento con la solicitud
|
281 |
application_request = {
|
282 |
"id": str(uuid.uuid4()),
|
283 |
"name": name,
|
|
|
287 |
"current_role": current_role,
|
288 |
"desired_role": desired_role,
|
289 |
"reason": reason,
|
290 |
+
"requestDate": datetime.utcnow().isoformat(),
|
291 |
+
"username": email, # Usamos el email como username
|
292 |
+
"partitionKey": email # Partition key necesario para CosmosDB
|
293 |
}
|
294 |
+
|
295 |
+
# Crear el item en el contenedor
|
296 |
+
container.create_item(body=application_request)
|
297 |
+
logger.info(f"Solicitud de aplicaci贸n almacenada para: {email}")
|
298 |
return True
|
299 |
+
|
300 |
except Exception as e:
|
301 |
logger.error(f"Error al almacenar la solicitud de aplicaci贸n: {str(e)}")
|
302 |
return False
|
303 |
|
304 |
#########################################################
|
305 |
def store_student_feedback(username, name, email, feedback):
|
306 |
+
"""Almacena el feedback de un estudiante"""
|
307 |
try:
|
308 |
+
# Obtener el contenedor usando get_container()
|
309 |
+
container = get_container("user_feedback")
|
310 |
+
if not container:
|
311 |
+
logger.error("No se pudo obtener el contenedor de feedback")
|
312 |
+
return False
|
313 |
+
|
314 |
+
# Crear documento de feedback
|
315 |
feedback_item = {
|
316 |
"id": str(uuid.uuid4()),
|
317 |
"username": username,
|
|
|
319 |
"email": email,
|
320 |
"feedback": feedback,
|
321 |
"role": "Estudiante",
|
322 |
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
323 |
+
"partitionKey": username # Partition key necesario para CosmosDB
|
324 |
}
|
325 |
+
|
326 |
+
# Crear el item en el contenedor
|
327 |
+
container.create_item(body=feedback_item)
|
328 |
+
logger.info(f"Feedback almacenado para el usuario: {username}")
|
329 |
return True
|
330 |
+
|
331 |
except Exception as e:
|
332 |
logger.error(f"Error al almacenar el feedback del estudiante {username}: {str(e)}")
|
333 |
return False
|