Skip to content

Commit a513e3f

Browse files
authored
remove id requirement from program enrollment listing view (#2862)
1 parent 2399942 commit a513e3f

File tree

4 files changed

+79
-24
lines changed

4 files changed

+79
-24
lines changed

courses/views/v1/__init__.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -475,21 +475,21 @@ def partial_update(self, request, *args, **kwargs): # noqa: ARG002
475475
raise NotImplementedError
476476

477477

478-
@extend_schema(
479-
responses={200: UserProgramEnrollmentDetailSerializer},
480-
parameters=[
481-
OpenApiParameter(
482-
name="id",
483-
type=OpenApiTypes.INT,
484-
location=OpenApiParameter.PATH,
485-
description="Program enrollment ID",
486-
required=True,
487-
)
488-
],
489-
)
490478
class UserProgramEnrollmentsViewSet(viewsets.ViewSet):
491479
permission_classes = [IsAuthenticated]
492480

481+
id_parameter = OpenApiParameter(
482+
name="id",
483+
type=OpenApiTypes.INT,
484+
location=OpenApiParameter.PATH,
485+
description="Program enrollment ID",
486+
required=True,
487+
)
488+
489+
@extend_schema(
490+
responses={200: UserProgramEnrollmentDetailSerializer},
491+
parameters=[],
492+
)
493493
def list(self, request):
494494
"""
495495
Returns a unified set of program and course enrollments for the current
@@ -528,6 +528,25 @@ def list(self, request):
528528
UserProgramEnrollmentDetailSerializer(program_list, many=True).data
529529
)
530530

531+
@extend_schema(
532+
responses={200: UserProgramEnrollmentDetailSerializer},
533+
parameters=[id_parameter],
534+
)
535+
def retrieve(self, request, pk=None):
536+
"""
537+
Retrieve a specific program enrollment.
538+
"""
539+
program = Program.objects.get(pk=pk)
540+
enrollment = ProgramEnrollment.objects.get(user=request.user, program=program)
541+
serializer = UserProgramEnrollmentDetailSerializer(
542+
enrollment, context={"request": request}
543+
)
544+
return Response(serializer.data)
545+
546+
@extend_schema(
547+
responses={200: UserProgramEnrollmentDetailSerializer},
548+
parameters=[id_parameter],
549+
)
531550
def destroy(self, request, pk=None):
532551
"""
533552
Unenroll the user from this program. This is simpler than the corresponding

openapi/specs/v0.yaml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,21 @@ paths:
702702
description: |-
703703
Returns a unified set of program and course enrollments for the current
704704
user.
705+
tags:
706+
- program_enrollments
707+
responses:
708+
'200':
709+
content:
710+
application/json:
711+
schema:
712+
type: array
713+
items:
714+
$ref: '#/components/schemas/UserProgramEnrollmentDetail'
715+
description: ''
716+
/api/v1/program_enrollments/{id}/:
717+
get:
718+
operationId: program_enrollments_retrieve
719+
description: Retrieve a specific program enrollment.
705720
parameters:
706721
- in: path
707722
name: id
@@ -716,11 +731,8 @@ paths:
716731
content:
717732
application/json:
718733
schema:
719-
type: array
720-
items:
721-
$ref: '#/components/schemas/UserProgramEnrollmentDetail'
734+
$ref: '#/components/schemas/UserProgramEnrollmentDetail'
722735
description: ''
723-
/api/v1/program_enrollments/{id}/:
724736
delete:
725737
operationId: program_enrollments_destroy
726738
description: |-

openapi/specs/v1.yaml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,21 @@ paths:
702702
description: |-
703703
Returns a unified set of program and course enrollments for the current
704704
user.
705+
tags:
706+
- program_enrollments
707+
responses:
708+
'200':
709+
content:
710+
application/json:
711+
schema:
712+
type: array
713+
items:
714+
$ref: '#/components/schemas/UserProgramEnrollmentDetail'
715+
description: ''
716+
/api/v1/program_enrollments/{id}/:
717+
get:
718+
operationId: program_enrollments_retrieve
719+
description: Retrieve a specific program enrollment.
705720
parameters:
706721
- in: path
707722
name: id
@@ -716,11 +731,8 @@ paths:
716731
content:
717732
application/json:
718733
schema:
719-
type: array
720-
items:
721-
$ref: '#/components/schemas/UserProgramEnrollmentDetail'
734+
$ref: '#/components/schemas/UserProgramEnrollmentDetail'
722735
description: ''
723-
/api/v1/program_enrollments/{id}/:
724736
delete:
725737
operationId: program_enrollments_destroy
726738
description: |-

openapi/specs/v2.yaml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,21 @@ paths:
702702
description: |-
703703
Returns a unified set of program and course enrollments for the current
704704
user.
705+
tags:
706+
- program_enrollments
707+
responses:
708+
'200':
709+
content:
710+
application/json:
711+
schema:
712+
type: array
713+
items:
714+
$ref: '#/components/schemas/UserProgramEnrollmentDetail'
715+
description: ''
716+
/api/v1/program_enrollments/{id}/:
717+
get:
718+
operationId: program_enrollments_retrieve
719+
description: Retrieve a specific program enrollment.
705720
parameters:
706721
- in: path
707722
name: id
@@ -716,11 +731,8 @@ paths:
716731
content:
717732
application/json:
718733
schema:
719-
type: array
720-
items:
721-
$ref: '#/components/schemas/UserProgramEnrollmentDetail'
734+
$ref: '#/components/schemas/UserProgramEnrollmentDetail'
722735
description: ''
723-
/api/v1/program_enrollments/{id}/:
724736
delete:
725737
operationId: program_enrollments_destroy
726738
description: |-

0 commit comments

Comments
 (0)