Skip to content

Commit

Permalink
backend for messenger
Browse files Browse the repository at this point in the history
gets chats.
  • Loading branch information
Taseen18 committed Mar 29, 2024
1 parent b45b653 commit 85e1fd4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@

urlpatterns = [
path('admin/', admin.site.urls),
path('to_do_list/', include('to_do_list.urls'))
path('to_do_list/', include('to_do_list.urls')),
path('chat/', include('chat.urls'))
]
10 changes: 10 additions & 0 deletions backend/chat/db_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ def fetch_chats(user_id):

if user_type == "employee":
response = client.table('chats').select('*').eq('user_id', user_id).execute()
return response
elif user_type == "mhp":
response = client.table('chats').select('*').eq('mhp_id', user_id).execute()
return response
else:
response = client.table('chats').select('*').eq('user_id', user_id).execute()
print("user type unknown")
return response
return None




Expand Down
6 changes: 6 additions & 0 deletions backend/chat/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from .views import GetChats

urlpatterns = [
path('getChats/', GetChats.as_view(), name='get-chats'),
]
17 changes: 14 additions & 3 deletions backend/chat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ def get(self, request):
chats = []

if response.data:
pass
for chat in response.data:
chats.append({
'chat_id': chat['chat_id'],
'created_at': chat['created_at'],
'user_id': chat['user_id'],
'mhp_id': chat['mhp_id'],
})

print(len(chats), "chats found")
return JsonResponse({'chats': chats}, safe=False)

except:
pass
except Exception as e:
print("Error fetching chats")
print(e)
return JsonResponse({'error': 'Failed to fetch chats'}, status=500)

0 comments on commit 85e1fd4

Please sign in to comment.