Skip to content

Commit

Permalink
feat: Added assignments in credits_available endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
IrfanUddinAhmad committed Oct 26, 2023
1 parent 9ad845b commit d181d26
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions enterprise_access/apps/api/serializers/subsidy_access_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from requests.exceptions import HTTPError
from rest_framework import serializers

from enterprise_access.apps.subsidy_access_policy.constants import AccessMethods
from enterprise_access.apps.subsidy_access_policy.constants import CENTS_PER_DOLLAR, PolicyTypes
from enterprise_access.apps.subsidy_access_policy.models import SubsidyAccessPolicy

Expand Down Expand Up @@ -522,6 +523,16 @@ class SubsidyAccessPolicyCreditsAvailableResponseSerializer(SubsidyAccessPolicyR
help_text='',
source='subsidy_expiration_datetime',
)
learner_content_assignments = serializers.SerializerMethodField('get_assignments_serializer')

def get_assignments_serializer(self, obj):
if obj.access_method == AccessMethods.ASSIGNED:
assignments = obj.assignment_configuration.assignments.all().filter(
lms_user_id=self.context.get('lms_user_id')
)
serializer = LearnerContentAssignmentResponseSerializer(assignments, many=True)
return serializer.data
return []

@extend_schema_field(serializers.IntegerField)
def get_remaining_balance_per_user(self, obj):
Expand Down

0 comments on commit d181d26

Please sign in to comment.