Spaces:
Sleeping
Sleeping
Update database_connection.py
Browse files- database_connection.py +29 -9
database_connection.py
CHANGED
|
@@ -40,15 +40,35 @@ class DatabaseConnection:
|
|
| 40 |
def add_feedback(self, course: str, stanine: int, gwa: float, strand: str,
|
| 41 |
rating: str, hobbies: str) -> bool:
|
| 42 |
"""Add new feedback to the database"""
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
def update_feedback_count(self, feedback_id: int, count: int) -> bool:
|
| 54 |
"""Update the count for existing feedback"""
|
|
|
|
| 40 |
def add_feedback(self, course: str, stanine: int, gwa: float, strand: str,
|
| 41 |
rating: str, hobbies: str) -> bool:
|
| 42 |
"""Add new feedback to the database"""
|
| 43 |
+
try:
|
| 44 |
+
url = f"{self.base_url}/student_feedback_counts"
|
| 45 |
+
data = {
|
| 46 |
+
'course': course,
|
| 47 |
+
'stanine': stanine,
|
| 48 |
+
'gwa': gwa,
|
| 49 |
+
'strand': strand,
|
| 50 |
+
'rating': rating,
|
| 51 |
+
'hobbies': hobbies,
|
| 52 |
+
'count': 1
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
print(f"Attempting to add feedback: {course}, rating: {rating}")
|
| 56 |
+
response = self.session.post(url, json=data, timeout=10)
|
| 57 |
+
response.raise_for_status()
|
| 58 |
+
|
| 59 |
+
result = response.json()
|
| 60 |
+
print(f"✅ Feedback added successfully: {result}")
|
| 61 |
+
return True
|
| 62 |
+
|
| 63 |
+
except requests.exceptions.Timeout:
|
| 64 |
+
print("⚠️ Database request timed out")
|
| 65 |
+
return False
|
| 66 |
+
except requests.exceptions.ConnectionError:
|
| 67 |
+
print("⚠️ Could not connect to database")
|
| 68 |
+
return False
|
| 69 |
+
except Exception as e:
|
| 70 |
+
print(f"❌ Error adding feedback: {e}")
|
| 71 |
+
return False
|
| 72 |
|
| 73 |
def update_feedback_count(self, feedback_id: int, count: int) -> bool:
|
| 74 |
"""Update the count for existing feedback"""
|