Skip to content

Commit

Permalink
feat: add endpoint and update api
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonHBodine committed Sep 6, 2023
1 parent 12ba586 commit 61560a8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
45 changes: 45 additions & 0 deletions edxval/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,51 @@ def get_videos_for_course(course_id, sort_field=None, sort_dir=SortDirection.asc
)


def get_transcript_details_for_course(course_id):
"""
Returns an iterator of video transcript details given a course id.
Args:
course_id (String)
Returns:
(dict): Returns all the edx_video_id's and related transcript details for a course
{
'edx_video_id': {
'lang_code': {
'provider': 'What the provider is',
'content': 'Content of the transcript',
'file_format': 'file format',
'url': 'location of the file',
'name': 'name of the file',
'size': size of the file
}
}
"""
course_transcripts_data = {}

Check warning on line 757 in edxval/api.py

View check run for this annotation

Codecov / codecov/patch

edxval/api.py#L757

Added line #L757 was not covered by tests

course_videos = CourseVideo.objects.filter(course_id=course_id).select_related('video')

Check warning on line 759 in edxval/api.py

View check run for this annotation

Codecov / codecov/patch

edxval/api.py#L759

Added line #L759 was not covered by tests
for course_video in course_videos:

edx_video_id = course_video.video.edx_video_id
transcript_data = {}

Check warning on line 763 in edxval/api.py

View check run for this annotation

Codecov / codecov/patch

edxval/api.py#L762-L763

Added lines #L762 - L763 were not covered by tests

video_transcripts = VideoTranscript.objects.filter(video=course_video.video)

Check warning on line 765 in edxval/api.py

View check run for this annotation

Codecov / codecov/patch

edxval/api.py#L765

Added line #L765 was not covered by tests
for video_transcript in video_transcripts:
transcript_data[video_transcript.language_code] = {

Check warning on line 767 in edxval/api.py

View check run for this annotation

Codecov / codecov/patch

edxval/api.py#L767

Added line #L767 was not covered by tests
'provider': video_transcript.provider,
'content': video_transcript.transcript.file.read(),
'file_format': video_transcript.file_format,
'url': video_transcript.transcript.url,
'name': video_transcript.transcript.name,
'size': video_transcript.transcript.size,
}

course_transcripts_data[edx_video_id] = transcript_data

Check warning on line 776 in edxval/api.py

View check run for this annotation

Codecov / codecov/patch

edxval/api.py#L776

Added line #L776 was not covered by tests

return course_transcripts_data

Check warning on line 778 in edxval/api.py

View check run for this annotation

Codecov / codecov/patch

edxval/api.py#L778

Added line #L778 was not covered by tests


def remove_video_for_course(course_id, edx_video_id):
"""
Soft deletes video for particular course.
Expand Down
3 changes: 3 additions & 0 deletions edxval/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
path('videos/missing-hls/', views.HLSMissingVideoView.as_view(),
name='hls-missing-video'
),
path('videos/course-transcripts/<str:course_id>/', views.CourseTranscriptsDetailView.as_view(),
name='course-transcripts'
),
path('videos/video-transcripts/create/', views.VideoTranscriptView.as_view(),
name='create-video-transcript'
),
Expand Down
20 changes: 19 additions & 1 deletion edxval/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from edxval.api import create_or_update_video_transcript
from edxval.api import create_or_update_video_transcript, get_transcript_details_for_course
from edxval.models import (
LIST_MAX_ITEMS,
CourseVideo,
Expand Down Expand Up @@ -175,6 +175,24 @@ def post(self, request):
return response


class CourseTranscriptsDetailView(APIView):
"""
A view to get the details for all the course transcripts related to a course_id.
"""
authentication_classes = (JwtAuthentication, SessionAuthentication)

def get(self, _request, course_id):
"""
Returns all transcript data for a course when given a course_id.
"""
course_data = get_transcript_details_for_course(course_id)

Check warning on line 188 in edxval/views.py

View check run for this annotation

Codecov / codecov/patch

edxval/views.py#L188

Added line #L188 was not covered by tests

if not course_data:
return Response(status=status.HTTP_400_BAD_REQUEST, data={'message': 'course_id param required'})

Check warning on line 191 in edxval/views.py

View check run for this annotation

Codecov / codecov/patch

edxval/views.py#L191

Added line #L191 was not covered by tests

return Response(status=status.HTTP_200_OK, data=course_data)

Check warning on line 193 in edxval/views.py

View check run for this annotation

Codecov / codecov/patch

edxval/views.py#L193

Added line #L193 was not covered by tests


class VideoStatusView(APIView):
"""
A Video View to update the status of a video.
Expand Down

0 comments on commit 61560a8

Please sign in to comment.