Spaces:
Running
Running
Update db_helper.py
Browse files- db_helper.py +13 -1
db_helper.py
CHANGED
|
@@ -62,7 +62,19 @@ class DB:
|
|
| 62 |
.order("created_at", desc=True)\
|
| 63 |
.execute()
|
| 64 |
return result.data
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
# ==================== JOURNEYS ====================
|
| 67 |
|
| 68 |
def create_journey(self, user_id: str, category: str) -> dict:
|
|
|
|
| 62 |
.order("created_at", desc=True)\
|
| 63 |
.execute()
|
| 64 |
return result.data
|
| 65 |
+
def get_user_messages(self, user_id: str, limit: int = 5) -> List[Dict]:
|
| 66 |
+
"""Get recent chat messages for a user (used in /journey endpoint)"""
|
| 67 |
+
try:
|
| 68 |
+
result = self.client.table("chat_history")\
|
| 69 |
+
.select("*")\
|
| 70 |
+
.eq("user_id", user_id)\
|
| 71 |
+
.order("happened_at", desc=True)\
|
| 72 |
+
.limit(limit)\
|
| 73 |
+
.execute()
|
| 74 |
+
return result.data
|
| 75 |
+
except Exception as e:
|
| 76 |
+
print(f"Error fetching user messages: {str(e)}")
|
| 77 |
+
return [] # Graceful fallback so endpoint doesn't crash
|
| 78 |
# ==================== JOURNEYS ====================
|
| 79 |
|
| 80 |
def create_journey(self, user_id: str, category: str) -> dict:
|