Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/get problem responses #35196

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lms/djangoapps/instructor/rest_api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from rest_framework import serializers



"""
Example usage
serializer = ProblemResponseRequestSerializer(data=request.data)
if serializer.is_valid():
# Access validated data with serializer.validated_data
else:
# Handle invalid data with serializer.errors

"""
class ProblemResponseRequestSerializer(serializers.Serializer):
problem_location = serializers.CharField(required=True)
problem_types_filter = serializers.CharField(required=False, allow_blank=True)

def validate_problem_location(self, value):
locations = value.split(',')
if not all(locations):
raise serializers.ValidationError("All problem locations must be valid non-empty strings.")
return locations

def validate_problem_types_filter(self, value):
if value:
types = value.split(',')
if not all(types):
raise serializers.ValidationError("All problem types must be valid non-empty strings.")
return types
return []
28 changes: 28 additions & 0 deletions lms/djangoapps/instructor/rest_api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from rest_framework import generics, status
from rest_framework.response import Response

from . import serializers


from .. import permissions

class GetProblemResponseViewset(generics.GenericAPIView):
serializer_class = serializers.ProblemResponseRequestSerializer
permission_classes = (
permissions.CAN_RESEARCH,
)
http_method_names = ["post"]

def post(self, request, *args, **kwargs):
course_id = kwargs.get('course_id')
if not course_id:
return Response({"error": "Course ID is required."}, status=status.HTTP_400_BAD_REQUEST)

serializer = self.get_serializer(data=request.data)
if serializer.is_valid():
validated_data = serializer.validated_data

# Access validated data with serializer.validated_data
return Response(status=status.HTTP_200_OK)
return Response(status=status.HTTP_400_BAD_REQUEST)