inheirt VideoProgressView from base class to get auth

This commit is contained in:
simon 2022-02-21 20:59:04 +07:00
parent ec00568008
commit b8b95f9d79
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -100,43 +100,42 @@ class VideoApiView(ApiBaseView):
return Response(self.response, status=self.status_code)
class VideoProgressView(APIView):
class VideoProgressView(ApiBaseView):
"""resolves to /api/video/<video_id>/
handle progress status for video
"""
@staticmethod
def get(request, video_id):
def get(self, request, video_id):
"""get progress for a single video"""
user_id = request.user.id
key = f"{user_id}:progress:{video_id}"
video_progress = RedisArchivist().get_message(key)
position = video_progress.get("position", 0)
progress = {
self.response = {
"youtube_id": video_id,
"user_id": user_id,
"position": position,
}
return Response(progress)
return Response(self.response)
@staticmethod
def post(request, video_id):
def post(self, request, video_id):
"""set progress position in redis"""
position = request.data.get("position", 0)
key = f"{request.user.id}:progress:{video_id}"
message = {"position": position}
RedisArchivist().set_message(key, message, expire=False)
self.response = request.data
return Response(request.data)
return Response(self.response)
@staticmethod
def delete(request, video_id):
def delete(self, request, video_id):
"""delete progress position"""
key = f"{request.user.id}:progress:{video_id}"
RedisArchivist().del_message(key)
self.response = {"progress-reset": video_id}
return Response({"progress-reset": video_id})
return Response(self.response)
class ChannelApiView(ApiBaseView):