Skip to content

Commit

Permalink
Merge branch 'main' into Mae/groupsvoteroute
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloj2001 authored Nov 22, 2023
2 parents 6bcf6a5 + 96159b3 commit 8c70ce9
Show file tree
Hide file tree
Showing 18 changed files with 1,181 additions and 49 deletions.
11 changes: 11 additions & 0 deletions api/optimeet/groups/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ class Recommendations(models.Model):
place_name = models.CharField(max_length=50)
place_url = models.CharField(max_length=100)
times = models.JSONField()

class Preferences(models.Model):
group_id = models.ForeignKey(Group, on_delete=models.CASCADE, default="")
user_id = models.CharField(max_length=64, blank=True)

category = models.JSONField()
subcategory = models.JSONField()
time = models.JSONField()

loc_lat = models.FloatField()
loc_long = models.FloatField()

class Votes(models.Model):
rec_id = models.ForeignKey(Recommendations, on_delete=models.DO_NOTHING)
group_id = models.ForeignKey(Group, on_delete=models.DO_NOTHING, default="")
Expand Down
13 changes: 12 additions & 1 deletion api/optimeet/groups/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def create(self, validated_data):
return super(GroupSerializer, self).create(validated_data)



class UserGroupSerializer(serializers.ModelSerializer):
class Meta:
model = UserGroup
Expand All @@ -29,6 +28,18 @@ class RecSerializer(serializers.ModelSerializer):
class Meta:
model = models.Recommendations
fields = '__all__'


class PreferencesSerializer(serializers.ModelSerializer):
class Meta:
model = models.Preferences
fields = '__all__'

def create(self, validated_data):
validated_data['group_id'] = self.context['group_id']
validated_data['user_id'] = self.context['user_id']

return super(PreferencesSerializer, self).create(validated_data)

class VotesSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
4 changes: 2 additions & 2 deletions api/optimeet/groups/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

path("<str:group_id>/", views.group_detail),
path('<str:group_id>/users/', views.add_users_to_group, name='add_users_to_group'),
path('<str:group_id>/users/<str:user_id>/prefs/', views.add_preference_to_group),
#path('usergroups/', views.UserGroupListAPIView.as_view(), name='usergroup-list'),#get all usergroup
#path('usergroups/<str:user_id>/', views.UserGroupListAPIView.as_view(), name='usergroup-byuser'),#get usergroup by user_id
path("<str:group_id>/recs/", views.get_recommendation),
path("<str:group_id>/votes/", views.votes, name='votes'),
path("<str:group_id>/votes/", views.create_vote, name='create_vote'),

path("<str:group_id>/votes/", views.create_vote, name='create_vote')
]
33 changes: 29 additions & 4 deletions api/optimeet/groups/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,37 @@ def add_users_to_group(request, group_id):

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

@csrf_exempt
@api_view(['POST'])
def add_preference_to_group(request, group_id, user_id, format=None):
# Check if the user group exists
try:
group = models.Group.objects.get(group_id=group_id)

user_group = models.UserGroup.objects.get(group_id=group_id, user_id=user_id)

except models.UserGroup.DoesNotExist:
raise Http404

except models.Group.DoesNotExist:
raise Http404

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

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

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

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

@csrf_exempt
@api_view(['GET'])
def votes(request, group_id):
votes = models.Votes.objects.filter(group_id=group_id)
serializer = serializers.VotesSerializer(votes, many=True)
return Response(serializer.data)
votes = models.Votes.objects.filter(group_id=group_id)
serializer = serializers.VotesSerializer(votes, many=True)
return Response(serializer.data)

@csrf_exempt
@api_view(['POST'])
Expand All @@ -85,7 +110,7 @@ def create_vote(request, group_id):
return Response(status=status.HTTP_201_CREATED)

return Response(status=status.HTTP_400_BAD_REQUEST)

# #for testing
# class UserGroupListAPIView(APIView):
# def get(request, self):
Expand Down
5 changes: 4 additions & 1 deletion api/optimeet/optimeet/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
]

ROOT_URLCONF = 'optimeet.urls'
Expand Down Expand Up @@ -146,7 +148,8 @@

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


if (DEBUG == True):
CORS_ALLOWED_ORIGINS = [
'http://localhost:5173'
]
]
1 change: 1 addition & 0 deletions web/meetup-facilitator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
1. Install dependencies with `npm i`.
2. Create `.env` file in base directory with the `VITE_CLIENT_ID` variable.


## Run
Run `npm run dev` to start the server.
Loading

0 comments on commit 8c70ce9

Please sign in to comment.