Commit 3f738b25 authored by Victoria Ahmadi's avatar Victoria Ahmadi
Browse files

Merge branch 'integration_test_uc2' into 'master'

Integration test uc2

See merge request !6
parents e86c0be8 5b00fb33
Pipeline #114750 passed with stage
in 45 seconds
......@@ -2,7 +2,7 @@ from rest_framework import serializers
from .models import SuggestedWorkout
from users.models import User
from workouts.serializers import WorkoutFileSerializer, ExerciseInstanceSerializer
from workouts.models import ExerciseInstance, WorkoutFile
from workouts.models import ExerciseInstance, WorkoutFile, Exercise
class SuggestedWorkoutSerializer(serializers.ModelSerializer):
......@@ -30,7 +30,7 @@ class SuggestedWorkoutSerializer(serializers.ModelSerializer):
Workout: A newly created Workout
"""
exercise_instances_data = validated_data.pop(
"suggested_exercise_instances")
'suggested_exercise_instances')
files_data = []
if "suggested_workout_files" in validated_data:
files_data = validated_data.pop("suggested_workout_files")
......@@ -70,7 +70,8 @@ class SuggestedWorkoutSerializer(serializers.ModelSerializer):
for exercise_instance, exercise_instance_data in zip(
exercise_instances.all(), exercise_instances_data):
exercise_instance.exercise = exercise_instance_data.get(
"exercise", exercise_instance.exercise)
"exercise", exercise_instance.exercise
)
exercise_instance.number = exercise_instance_data.get(
"number", exercise_instance.number
)
......
This diff is collapsed.
......@@ -4,7 +4,7 @@ from rest_framework.urlpatterns import format_suffix_patterns
urlpatterns = [
path("api/suggested-workouts/create/", views.createSuggestedWorkouts,
name="suggested_workouts"),
name="suggested_workouts_create"),
path("api/suggested-workouts/athlete-list/",
views.listAthleteSuggestedWorkouts, name="suggested_workouts_for_athlete"),
path("api/suggested-workouts/coach-list/",
......
......@@ -23,13 +23,12 @@ def createSuggestedWorkouts(request):
chosen_athlete_id = request.data['athlete']
chosen_athlete = User.objects.get(id=chosen_athlete_id)
if(request.user != chosen_athlete.coach):
return Response({"message": "You can not assign the workout to someone who is not your athlete."}, status=status.HTTP_400_BAD_REQUEST)
# new_suggested_workout = SuggestedWorkout.objects.create(
# coach=request.user, **serializer.validated_data)
return Response({"message": "You can not assign the workout to someone who is not your athlete."}, status=status.HTTP_401_UNAUTHORIZED)
serializer.create(
validated_data=serializer.validated_data, coach=request.user)
return Response({"message": "Suggested workout successfully created!"}, status=status.HTTP_201_CREATED)
return Response({"message": "Something went wrong.", "error": serializer.errors})
return Response({"message": "Something went wrong.", "error": serializer.errors}, status=status.HTTP_400_BAD_REQUEST)
@api_view(['GET'])
......@@ -40,7 +39,7 @@ def listAthleteSuggestedWorkouts(request):
return Response({"message": "You have to log in to see this information."}, status=status.HTTP_401_UNAUTHORIZED)
serializer = SuggestedWorkoutSerializer(
suggested_workouts, many=True, context={'request': request})
return Response(data=serializer.data, status=status.HTTP_200_OK)
return Response(data=serializer.data, status=status.HTTP_201_CREATED)
@api_view(['GET'])
......
Supports Markdown
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