Skip to content

Commit

Permalink
Merge pull request #51 from LaurierCS/Call-algo-from-preferences-view
Browse files Browse the repository at this point in the history
Call algo from prefs view and remove unused imports
  • Loading branch information
itsPedro231 authored Nov 30, 2023
2 parents de7c099 + 5e1536a commit dedb628
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions api/optimeet/groups/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse, Http404
from django.http import Http404
from rest_framework.response import Response
from rest_framework.decorators import api_view
from django.views.decorators.csrf import csrf_exempt
from rest_framework.parsers import JSONParser
from rest_framework import status
from rest_framework.views import APIView

import os
import dotenv
import requests

from . import models
from .models import UserGroup
from . import serializers
from .serializers import UserGroupSerializer


dotenv.load_dotenv()

@csrf_exempt
@api_view(['POST'])
Expand Down Expand Up @@ -78,12 +80,17 @@ def add_preference_to_group(request, group_id, user_id, format=None):
except models.Group.DoesNotExist:
raise Http404

url = os.getenv("ALGO_URL")

serializer = serializers.PreferencesSerializer(data=request.data, context={"group_id":group,"user_id":user_id})

if serializer.is_valid():
# Save the preferences
serializer.save()

requests.post(url, params={"group_id": group_id})


return Response(serializer.data, status=status.HTTP_201_CREATED)

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Expand All @@ -104,7 +111,7 @@ def votes(request, group_id):
serializer = serializers.VotesSerializer(data = request.data, context={'group_id': group})

if serializer.is_valid():
serializer.save()
serializer.save()
return Response(status=status.HTTP_201_CREATED)

return Response(status=status.HTTP_400_BAD_REQUEST)
Expand Down

0 comments on commit dedb628

Please sign in to comment.