AIdeaText commited on
Commit
6da18da
1 Parent(s): 0e1ed6b

Update modules/database.py

Browse files
Files changed (1) hide show
  1. modules/database.py +15 -3
modules/database.py CHANGED
@@ -39,22 +39,30 @@ def initialize_database_connections():
39
  #####################################################################################33
40
  def initialize_cosmos_sql_connection():
41
  global cosmos_client, user_database, user_container, application_requests_container
 
42
  try:
43
  cosmos_endpoint = os.environ.get("COSMOS_ENDPOINT")
44
  cosmos_key = os.environ.get("COSMOS_KEY")
 
 
45
 
46
  print(f"Cosmos Endpoint: {cosmos_endpoint}")
47
  print(f"Cosmos Key: {'*' * len(cosmos_key) if cosmos_key else 'Not set'}")
48
 
49
- if not cosmos_endpoint or not cosmos_key:
 
50
  raise ValueError("Las variables de entorno COSMOS_ENDPOINT y COSMOS_KEY deben estar configuradas")
51
 
52
  cosmos_client = CosmosClient(cosmos_endpoint, cosmos_key)
53
  user_database = cosmos_client.get_database_client("user_database")
54
  user_container = user_database.get_container_client("users")
55
  application_requests_container = user_database.get_container_client("application_requests")
 
 
 
56
 
57
  print(f"user_container initialized: {user_container is not None}")
 
58
  logger.info("Conexión a Cosmos DB SQL API exitosa")
59
  return True
60
  except Exception as e:
@@ -145,11 +153,14 @@ def get_user(username):
145
  #######################################################################################################
146
  def store_application_request(name, email, institution, role, reason):
147
  global application_requests_container
 
148
  try:
 
149
  if application_requests_container is None:
150
  logger.error("application_requests_container is not initialized")
151
  return False
152
-
 
153
  application_request = {
154
  "id": str(uuid.uuid4()),
155
  "name": name,
@@ -159,7 +170,8 @@ def store_application_request(name, email, institution, role, reason):
159
  "reason": reason,
160
  "requestDate": datetime.utcnow().isoformat()
161
  }
162
-
 
163
  application_requests_container.create_item(body=application_request)
164
  logger.info(f"Application request stored for email: {email}")
165
  return True
 
39
  #####################################################################################33
40
  def initialize_cosmos_sql_connection():
41
  global cosmos_client, user_database, user_container, application_requests_container
42
+ logger.info("Initializing Cosmos DB SQL API connection")
43
  try:
44
  cosmos_endpoint = os.environ.get("COSMOS_ENDPOINT")
45
  cosmos_key = os.environ.get("COSMOS_KEY")
46
+ logger.info(f"Cosmos Endpoint: {cosmos_endpoint}")
47
+ logger.info(f"Cosmos Key: {'*' * len(cosmos_key) if cosmos_key else 'Not set'}")
48
 
49
  print(f"Cosmos Endpoint: {cosmos_endpoint}")
50
  print(f"Cosmos Key: {'*' * len(cosmos_key) if cosmos_key else 'Not set'}")
51
 
52
+ if not cosmos_endpoint or not cosmos_key:logger.error("COSMOS_ENDPOINT or COSMOS_KEY environment variables are not set")
53
+ logger.error("COSMOS_ENDPOINT or COSMOS_KEY environment variables are not set")
54
  raise ValueError("Las variables de entorno COSMOS_ENDPOINT y COSMOS_KEY deben estar configuradas")
55
 
56
  cosmos_client = CosmosClient(cosmos_endpoint, cosmos_key)
57
  user_database = cosmos_client.get_database_client("user_database")
58
  user_container = user_database.get_container_client("users")
59
  application_requests_container = user_database.get_container_client("application_requests")
60
+
61
+ logger.info(f"user_container initialized: {user_container is not None}")
62
+ logger.info(f"application_requests_container initialized: {application_requests_container is not None}")
63
 
64
  print(f"user_container initialized: {user_container is not None}")
65
+
66
  logger.info("Conexión a Cosmos DB SQL API exitosa")
67
  return True
68
  except Exception as e:
 
153
  #######################################################################################################
154
  def store_application_request(name, email, institution, role, reason):
155
  global application_requests_container
156
+ logger.info("Entering store_application_request function")
157
  try:
158
+ logger.info("Checking application_requests_container")
159
  if application_requests_container is None:
160
  logger.error("application_requests_container is not initialized")
161
  return False
162
+
163
+ logger.info("Creating application request document")
164
  application_request = {
165
  "id": str(uuid.uuid4()),
166
  "name": name,
 
170
  "reason": reason,
171
  "requestDate": datetime.utcnow().isoformat()
172
  }
173
+
174
+ logger.info(f"Attempting to store document: {application_request}")
175
  application_requests_container.create_item(body=application_request)
176
  logger.info(f"Application request stored for email: {email}")
177
  return True