markobinario commited on
Commit
b7162be
·
verified ·
1 Parent(s): 9894c09

Update database_connection.py

Browse files
Files changed (1) hide show
  1. 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
- print(f"Attempting to add feedback: {course}, rating: {rating}")
44
-
45
- # For now, let's simulate successful feedback addition
46
- # since the API endpoint seems to have issues
47
- print(f"[OK] Feedback simulated: {course} - {rating}")
48
- return True
49
-
50
- # TODO: Fix the actual API endpoint to accept the correct data structure
51
- # The current API expects different fields than what we're sending
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"""