WIP
This commit is contained in:
@@ -16,13 +16,20 @@ from django.shortcuts import get_object_or_404
|
||||
from datetime import datetime
|
||||
import json
|
||||
import os
|
||||
from django.core.cache import cache
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def all_workouts(request):
|
||||
if 'all_workouts' in cache:
|
||||
data = cache.get('all_workouts')
|
||||
return Response(data=data, status=status.HTTP_200_OK)
|
||||
|
||||
users = Workout.objects.all()
|
||||
serializer = WorkoutSerializer(users, many=True)
|
||||
return Response(data=serializer.data, status=status.HTTP_200_OK)
|
||||
data = serializer.data
|
||||
cache.set('all_workouts', data)
|
||||
return Response(data=data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@@ -121,6 +128,8 @@ def add_workout(request):
|
||||
workout.estimated_time = workout_total_time
|
||||
workout.save()
|
||||
|
||||
cache.delete('all_workouts')
|
||||
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
|
||||
@@ -229,5 +238,7 @@ def add_from_files(request):
|
||||
|
||||
workout_obj.estimated_time = workout_total_time
|
||||
workout_obj.save()
|
||||
|
||||
|
||||
cache.delete('all_workouts')
|
||||
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
Reference in New Issue
Block a user