mirror of
https://github.com/AmanTahiliani/PeerNotes.git
synced 2026-08-07 11:55:12 -04:00
change get peers endpoint
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,7 +34,7 @@ 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()
|
||||
})
|
||||
|
||||
@@ -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%;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user