From b8b95f9d79e3462d75c589c3c6735c396f1a62a2 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 21 Feb 2022 20:59:04 +0700 Subject: [PATCH] inheirt VideoProgressView from base class to get auth --- tubearchivist/api/views.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tubearchivist/api/views.py b/tubearchivist/api/views.py index 79932fa..5a71522 100644 --- a/tubearchivist/api/views.py +++ b/tubearchivist/api/views.py @@ -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// 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):