Fakultas Ilmu Komputer UI

[GREEN] Linked data with user if token provided

parent c76b657a
Pipeline #83004 passed with stages
in 14 minutes and 12 seconds
......@@ -12,9 +12,15 @@ class DietProfileViewSet(viewsets.ModelViewSet):
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
instance = self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
if not request.user.is_anonymous:
user = request.user
user.diet_profile = instance
user.save()
quiz_result = QuizResult.objects.get(diet_profile=instance)
response = serializer.data
response['quiz_result'] = QuizResultSerializer(quiz_result).data
......
......@@ -26,6 +26,10 @@ class CartViewSet(viewsets.ModelViewSet):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
if not request.user.is_anonymous:
serializer.save(user=request.user)
headers = self.get_success_headers(serializer.data)
program = DietelaProgram.objects.get(unique_code=program_unique_id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment