Update modules/database/sql_db.py
Browse files- modules/database/sql_db.py +49 -10
modules/database/sql_db.py
CHANGED
@@ -242,6 +242,7 @@ def update_student_user(username, new_info):
|
|
242 |
return False
|
243 |
|
244 |
|
|
|
245 |
def delete_student_user(username):
|
246 |
user_container, _, _ = get_sql_containers()
|
247 |
try:
|
@@ -257,9 +258,21 @@ def delete_student_user(username):
|
|
257 |
logger.error(f"Error al eliminar estudiante {username}: {str(e)}")
|
258 |
return False
|
259 |
|
|
|
|
|
|
|
|
|
260 |
def store_application_request(name, lastname, email, institution, current_role, desired_role, reason):
|
261 |
-
|
262 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
application_request = {
|
264 |
"id": str(uuid.uuid4()),
|
265 |
"name": name,
|
@@ -269,30 +282,56 @@ def store_application_request(name, lastname, email, institution, current_role,
|
|
269 |
"current_role": current_role,
|
270 |
"desired_role": desired_role,
|
271 |
"reason": reason,
|
272 |
-
"requestDate": datetime.utcnow().isoformat()
|
|
|
|
|
273 |
}
|
274 |
-
|
275 |
-
|
|
|
|
|
|
|
|
|
276 |
return True
|
|
|
277 |
except Exception as e:
|
278 |
logger.error(f"Error al almacenar la solicitud de aplicaci贸n: {str(e)}")
|
|
|
279 |
return False
|
280 |
|
|
|
281 |
def store_student_feedback(username, name, email, feedback):
|
282 |
-
|
283 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
feedback_item = {
|
285 |
"id": str(uuid.uuid4()),
|
286 |
-
"username": username,
|
287 |
"name": name,
|
288 |
"email": email,
|
289 |
"feedback": feedback,
|
290 |
"role": "Estudiante",
|
291 |
-
|
|
|
292 |
}
|
293 |
-
|
294 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
return True
|
|
|
296 |
except Exception as e:
|
297 |
-
logger.error(f"Error al almacenar el feedback del estudiante {username}
|
|
|
298 |
return False
|
|
|
242 |
return False
|
243 |
|
244 |
|
245 |
+
#########################################################
|
246 |
def delete_student_user(username):
|
247 |
user_container, _, _ = get_sql_containers()
|
248 |
try:
|
|
|
258 |
logger.error(f"Error al eliminar estudiante {username}: {str(e)}")
|
259 |
return False
|
260 |
|
261 |
+
|
262 |
+
|
263 |
+
#########################################################
|
264 |
+
|
265 |
def store_application_request(name, lastname, email, institution, current_role, desired_role, reason):
|
266 |
+
"""Almacena una solicitud de aplicaci贸n"""
|
267 |
try:
|
268 |
+
# Obtener el contenedor usando get_container() que s铆 funciona
|
269 |
+
container = get_container("application_requests")
|
270 |
+
if not container:
|
271 |
+
logger.error("No se pudo obtener el contenedor de solicitudes")
|
272 |
+
return False
|
273 |
+
|
274 |
+
# Crear documento con la solicitud
|
275 |
+
# N贸tese que incluimos email como partition key en el cuerpo del documento
|
276 |
application_request = {
|
277 |
"id": str(uuid.uuid4()),
|
278 |
"name": name,
|
|
|
282 |
"current_role": current_role,
|
283 |
"desired_role": desired_role,
|
284 |
"reason": reason,
|
285 |
+
"requestDate": datetime.utcnow().isoformat(),
|
286 |
+
# El campo para partition key debe estar en el documento
|
287 |
+
"partitionKey": email
|
288 |
}
|
289 |
+
|
290 |
+
# Crear el item en el contenedor - sin el par谩metro enable_cross_partition_query
|
291 |
+
container.create_item(
|
292 |
+
body=application_request # Solo pasamos el body
|
293 |
+
)
|
294 |
+
logger.info(f"Solicitud de aplicaci贸n almacenada para: {email}")
|
295 |
return True
|
296 |
+
|
297 |
except Exception as e:
|
298 |
logger.error(f"Error al almacenar la solicitud de aplicaci贸n: {str(e)}")
|
299 |
+
logger.error(f"Detalles del error: {str(e)}")
|
300 |
return False
|
301 |
|
302 |
+
############################################################
|
303 |
def store_student_feedback(username, name, email, feedback):
|
304 |
+
"""Almacena el feedback de un estudiante"""
|
305 |
try:
|
306 |
+
# Obtener el contenedor - verificar disponibilidad
|
307 |
+
logger.info(f"Intentando obtener contenedor user_feedback para usuario: {username}")
|
308 |
+
container = get_container("user_feedback")
|
309 |
+
if not container:
|
310 |
+
logger.error("No se pudo obtener el contenedor user_feedback")
|
311 |
+
return False
|
312 |
+
|
313 |
+
# Crear documento de feedback - asegurar que el username est茅 como partition key
|
314 |
feedback_item = {
|
315 |
"id": str(uuid.uuid4()),
|
316 |
+
"username": username, # Campo regular
|
317 |
"name": name,
|
318 |
"email": email,
|
319 |
"feedback": feedback,
|
320 |
"role": "Estudiante",
|
321 |
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
322 |
+
"partitionKey": username # Campo de partici贸n
|
323 |
}
|
324 |
+
|
325 |
+
# Crear el item - sin el par谩metro enable_cross_partition_query
|
326 |
+
logger.info(f"Intentando almacenar feedback para usuario: {username}")
|
327 |
+
result = container.create_item(
|
328 |
+
body=feedback_item # Solo el body, no par谩metros adicionales
|
329 |
+
)
|
330 |
+
|
331 |
+
logger.info(f"Feedback almacenado exitosamente para el usuario: {username}")
|
332 |
return True
|
333 |
+
|
334 |
except Exception as e:
|
335 |
+
logger.error(f"Error al almacenar el feedback del estudiante {username}")
|
336 |
+
logger.error(f"Detalles del error: {str(e)}")
|
337 |
return False
|