change get peers endpoint

This commit is contained in:
afazio1
2024-04-22 10:32:38 -04:00
parent d0c43ee6fe
commit 2bcbf73ea3
3 changed files with 10 additions and 18 deletions

View File

@@ -247,7 +247,6 @@ class FileFilterView(APIView):
professor_id = request.query_params.get("professor") professor_id = request.query_params.get("professor")
course_id = request.query_params.get("course") course_id = request.query_params.get("course")
semester_id = request.query_params.get("semester") semester_id = request.query_params.get("semester")
peer_id = request.query_params.get("peer_id")
# Check if provided filter IDs exist # Check if provided filter IDs exist
if topic_id and not Topic.objects.filter(id=topic_id).exists(): 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"}, {"error": f"Semester with id {semester_id} does not exist"},
status=status.HTTP_400_BAD_REQUEST, 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 # Start with the base queryset
queryset = File.objects.all() queryset = File.objects.all()
@@ -295,14 +289,10 @@ class FileFilterView(APIView):
).order_by(F("downvote_count") - F("upvote_count")) ).order_by(F("downvote_count") - F("upvote_count"))
# Filter files based on active peers in the past hour # Filter files based on active peers in the past hour
if peer_id: active_peer_ids = PeerUser.objects.filter(
queryset = queryset.filter(peer_users__in=peer_id) last_poll__gte=timezone.now() - timedelta(hours=1)
else: ).values_list("id", flat=True)
# active_peer_ids = PeerUser.objects.filter( queryset = queryset.filter(peer_users__in=active_peer_ids).distinct()
# last_poll__gte=timezone.now() - timedelta(hours=1)
# ).values_list("id", flat=True)
# queryset = queryset.filter(peer_users__in=active_peer_ids).distinct()
pass
serializer = FileSerializer(queryset, many=True) serializer = FileSerializer(queryset, many=True)
# Loop through each serialized file to sort its peer_users # Loop through each serialized file to sort its peer_users

View File

@@ -17,7 +17,9 @@ export default function RegisterFile() {
}) })
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
const files: string[] = data.files const files: string[] = data.files.map((file: string) => {
return file.replace(/\s/g, "_");
})
setRegisteredFiles( setRegisteredFiles(
serverFiles.map((file) => { serverFiles.map((file) => {
if (files.includes(file.filename)) { if (files.includes(file.filename)) {
@@ -32,12 +34,12 @@ export default function RegisterFile() {
}, [serverFiles]) }, [serverFiles])
const fetchServerFiles = () => { const fetchServerFiles = () => {
fetch(`http://localhost:8000/api/files/filter?peer_id=1`, { fetch(`http://localhost:8000/api/get-peer-files/`, {
method: 'GET', method: 'GET',
headers: getAuthHeaders() headers: getAuthHeaders()
}) })
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
setServerFiles(data) setServerFiles(data)
}) })
.catch(error => console.error(error)); .catch(error => console.error(error));

View File

@@ -28,7 +28,7 @@ nav div {
align-items: center; align-items: center;
justify-content: center; /* If you're centering the content */ justify-content: center; /* If you're centering the content */
height: 100vh; /* Full height */ height: 100vh; /* Full height */
margin-top: -100px; /* Move up */ margin-top: 100px; /* Move up */
width: 100%; width: 100%;
} }