11"""
22Views served by the Agreements app
33"""
4- from os import times
54
5+ import edx_api_doc_tools as apidocs
66from django .conf import settings
77from django import forms
8+ from drf_yasg import openapi
89from rest_framework import status
910from rest_framework .views import APIView
1011from rest_framework .response import Response
1112from rest_framework .permissions import IsAuthenticated
1213from opaque_keys .edx .keys import CourseKey
1314
15+
1416from common .djangoapps .student import auth
1517from common .djangoapps .student .roles import CourseStaffRole
1618from openedx .core .djangoapps .agreements .api import (
@@ -165,11 +167,42 @@ def post(self, request, course_id):
165167
166168
167169class UserAgreementsView (AuthenticatedAPIView ):
170+ """
171+ Endpoint for the user agreements API.
172+ """
168173
169174 class QueryFilterForm (forms .Form ):
175+ """
176+ Query parameters for the GET method.
177+ """
170178 after = forms .DateTimeField (required = False )
171179
180+ @apidocs .schema (
181+ parameters = [
182+ apidocs .string_parameter (
183+ 'agreement_type' ,
184+ apidocs .ParameterLocation .PATH ,
185+ description = "Agreement ID/Type" ,
186+ ),
187+ openapi .Parameter (
188+ 'after' ,
189+ apidocs .ParameterLocation .QUERY ,
190+ required = False ,
191+ type = openapi .TYPE_STRING ,
192+ format = openapi .FORMAT_DATETIME ,
193+ description = "Return records after this date/time" ,
194+ ),
195+ ],
196+ responses = {
197+ 200 : UserAgreementsSerializer ,
198+ 400 : "Bad Request" ,
199+ 404 : "Not Found" ,
200+ },
201+ )
172202 def get (self , request , agreement_type ):
203+ """
204+ Get a user's acknowledgement record for this agreement type.
205+ """
173206 params = UserAgreementsView .QueryFilterForm (request .query_params )
174207 if not params .is_valid ():
175208 return Response (status = status .HTTP_400_BAD_REQUEST )
@@ -179,7 +212,23 @@ def get(self, request, agreement_type):
179212 serializer = UserAgreementsSerializer (record )
180213 return Response (serializer .data )
181214
215+ @apidocs .schema (
216+ parameters = [
217+ apidocs .string_parameter (
218+ 'agreement_type' ,
219+ apidocs .ParameterLocation .PATH ,
220+ description = "Agreement ID/Type" ,
221+ ),
222+ ],
223+ responses = {
224+ 200 : UserAgreementsSerializer ,
225+ 400 : "Bad Request" ,
226+ },
227+ )
182228 def post (self , request , agreement_type ):
229+ """
230+ Marks a user's acknowledgement of this agreement type.
231+ """
183232 record = create_user_agreement_record (request .user , agreement_type )
184233 serializer = UserAgreementsSerializer (record )
185234 return Response (serializer .data , status = status .HTTP_201_CREATED )
0 commit comments