-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
14 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
from django.urls import path | ||
from .views import DownloadPage | ||
from .views import Initialize, Generate, Download, Session | ||
|
||
urlpatterns = [ | ||
path("download", DownloadPage.as_view(), name="download-page"), | ||
path("initialize", Initialize.as_view(), name="initialize"), | ||
path("generate", Generate.as_view(), name="generate"), | ||
path("download", Download.as_view(), name="download"), | ||
path("session", Session.as_view(), name="session"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,49 @@ | ||
from django.shortcuts import render | ||
from rest_framework import generics, status | ||
from .serializers import VideoSerializer | ||
from .models import Video | ||
from rest_framework.views import APIView | ||
from rest_framework.response import Response | ||
|
||
|
||
class DownloadPage(generics.ListAPIView): | ||
def get(self, request, *args, **kwargs): | ||
session_id = self. | ||
video_id = self.kwargs.get("video_id") | ||
video = Video.objects.get(id=video_id) | ||
serializer = VideoSerializer(video) | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
|
||
class Initialize(generics.ListAPIView): | ||
http_method_names = ["post"] | ||
|
||
def post(self, request, *args, **kwargs): | ||
video_id = self.kwargs.get("video_id") | ||
session_id = request.session.session_key | ||
video = Video.objects.get(id=video_id, sesh_id = request.session.session_key) | ||
video = Video.objects.get(id=video_id, session_id=request.session.session_key) | ||
serializer = VideoSerializer(video, data=request.data) | ||
if serializer.is_valid(raise_exception=True): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
|
||
class Generate(generics.ListAPIView): | ||
http_method_names = ["put"] | ||
|
||
def put(self, request, *args, **kwargs): | ||
video_id = self.kwargs.get("video_id") | ||
video = Video.objects.get(id=video_id, session_id=request.session.session_key) | ||
serializer = VideoSerializer(video, data=request.data) | ||
if serializer.is_valid(raise_exception=True): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
|
||
class Download(generics.ListAPIView): | ||
http_method_names = ["get"] | ||
|
||
def get(self, request, *args, **kwargs): | ||
video_id = self.kwargs.get("video_id") | ||
video = Video.objects.get(id=video_id, session_id=request.session.session_key) | ||
serializer = VideoSerializer(video) | ||
return Response(serializer.data) | ||
|
||
|
||
class Session(generics.ListAPIView): | ||
http_method_names = ["get"] | ||
|
||
def get(self, request, *args, **kwargs): | ||
video = Video.objects.get(session_id=request.session.session_key) | ||
serializer = VideoSerializer(video) | ||
return Response(serializer.data) |