diff --git a/backend/api/views.py b/backend/api/views.py index d449c5b..89faec3 100644 --- a/backend/api/views.py +++ b/backend/api/views.py @@ -247,7 +247,6 @@ class FileFilterView(APIView): professor_id = request.query_params.get("professor") course_id = request.query_params.get("course") semester_id = request.query_params.get("semester") - peer_id = request.query_params.get("peer_id") # Check if provided filter IDs exist if topic_id and not Topic.objects.filter(id=topic_id).exists(): @@ -270,11 +269,6 @@ class FileFilterView(APIView): {"error": f"Semester with id {semester_id} does not exist"}, status=status.HTTP_400_BAD_REQUEST, ) - if peer_id and not PeerUser.objects.filter(id=peer_id).exists(): - return Response( - {"error": f"Peer with id {peer_id} does not exist"}, - status=status.HTTP_400_BAD_REQUEST, - ) # Start with the base queryset queryset = File.objects.all() @@ -295,14 +289,10 @@ class FileFilterView(APIView): ).order_by(F("downvote_count") - F("upvote_count")) # Filter files based on active peers in the past hour - if peer_id: - queryset = queryset.filter(peer_users__in=peer_id) - else: - # active_peer_ids = PeerUser.objects.filter( - # last_poll__gte=timezone.now() - timedelta(hours=1) - # ).values_list("id", flat=True) - # queryset = queryset.filter(peer_users__in=active_peer_ids).distinct() - pass + active_peer_ids = PeerUser.objects.filter( + last_poll__gte=timezone.now() - timedelta(hours=1) + ).values_list("id", flat=True) + queryset = queryset.filter(peer_users__in=active_peer_ids).distinct() serializer = FileSerializer(queryset, many=True) # Loop through each serialized file to sort its peer_users diff --git a/frontend/src/screens/RegisterFile.tsx b/frontend/src/screens/RegisterFile.tsx index f3b95b1..be04836 100644 --- a/frontend/src/screens/RegisterFile.tsx +++ b/frontend/src/screens/RegisterFile.tsx @@ -17,7 +17,9 @@ export default function RegisterFile() { }) .then(response => response.json()) .then(data => { - const files: string[] = data.files + const files: string[] = data.files.map((file: string) => { + return file.replace(/\s/g, "_"); + }) setRegisteredFiles( serverFiles.map((file) => { if (files.includes(file.filename)) { @@ -32,12 +34,12 @@ export default function RegisterFile() { }, [serverFiles]) const fetchServerFiles = () => { - fetch(`http://localhost:8000/api/files/filter?peer_id=1`, { + fetch(`http://localhost:8000/api/get-peer-files/`, { method: 'GET', headers: getAuthHeaders() }) .then(response => response.json()) - .then(data => { + .then(data => { setServerFiles(data) }) .catch(error => console.error(error)); diff --git a/frontend/src/styles/App.css b/frontend/src/styles/App.css index f7ca5de..80060a9 100644 --- a/frontend/src/styles/App.css +++ b/frontend/src/styles/App.css @@ -28,7 +28,7 @@ nav div { align-items: center; justify-content: center; /* If you're centering the content */ height: 100vh; /* Full height */ - margin-top: -100px; /* Move up */ + margin-top: 100px; /* Move up */ width: 100%; }