Skip to content

Commit

Permalink
EGCETSII#13-feat: Finished create voting endpoint
Browse files Browse the repository at this point in the history
Co-Authored-By: Beatriz María Beltrán Álvarez <[email protected]>
Co-Authored-By: José Luis Alonso Rocha <[email protected]>
  • Loading branch information
3 people committed Dec 31, 2021
1 parent 76089ba commit c02fae2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion decide/administration/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Meta:

class VotingSerializer(serializers.Serializer):
question = AdminQuestionSerializer(many=False)
auth = AuthSerializer(many=False)
auth = serializers.URLField()
name = serializers.CharField(max_length=200)
desc = serializers.CharField(max_length=1000, allow_blank=True, allow_null=True)
census = serializers.ListField()
2 changes: 1 addition & 1 deletion decide/administration/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
path('api/users/state', views.UpdateUserStateAPI.as_view()),
path('api/votings/question', views.QuestionsAPI.as_view()),
path('api/votings/question/<int:question_id>/', views.QuestionAPI.as_view()),
path('api/votings/voting', views.VotingAPI.as_view()),
path('api/votings', views.VotingAPI.as_view()),
# react-app
url('', views.index)
]
18 changes: 12 additions & 6 deletions decide/administration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@ def post(self, request):
try:
auth_object = Auth.objects.filter(url=auth_url).get()
except ObjectDoesNotExist:
auth_object = Auth.objects.save(Auth(name="Auth", url=auth_url, me=True))

auth_object = Auth(name="Auth", url=auth_url, me=True)
auth_object.save()
question = Question(desc=request.data.get('question').get("desc"))
question.save()
options = request.data.get('question').get("options")
for opt in options:
option = QuestionOption(question=question, option=opt.get("option"), number=opt.get("number"))
option.save()
voting = Voting(name=request.data.get("name"), desc=request.data.get("desc"),
question=request.data.get("question"))
question=question)
voting.save()
voting.auths.add(auth_object)
voting = voting.save()
voting_id = voting.get("id")
voting_id = voting.id
for voter_id in id_users:
census = Census(voting_id=voting_id, voter_id=voter_id)
census.save()
return Response({voting}, status=HTTP_200_OK)
return Response({"id": voting_id, "name": voting.name}, status=HTTP_200_OK)


class QuestionsAPI(APIView):
Expand Down

0 comments on commit c02fae2

Please sign in to comment.