diff --git a/core/api/urls.py b/core/api/urls.py index b6be1a4a..b876fa93 100644 --- a/core/api/urls.py +++ b/core/api/urls.py @@ -16,36 +16,37 @@ path("notifications/new", NotificationsNew.as_view(), name="api_notification_new"), path("announcements", announcement, name="api_all_announcements"), path("announcements/feed", announcementFeed, name="api_announcement_feed"), - path("organizations", apiOrganizationList, name="api_organization_list"), + path("organizations", ApiOrganizationList.as_view(), name="api_organization_list"), path( "organization/", - organizationDetail, + OrganizationDetail.as_view(), name="api_organization_detail", ), - path("user/", userDetail, name="api_user_detail"), - path("me", userMe, name="api_me"), - path("me/internal", userMeInternal, name="api_me_internal"), - path("me/schedule", userMeSchedule, name="api_me_schedule"), - path("me/schedule/week", userMeScheduleWeek, name="api_me_schedule_week"), - path("me/timetable", userMeTimetable, name="api_me_timetable"), + path("user/", UserDetail.as_view(), name="api_user_detail"), + path("me", UserMe.as_view(), name="api_me"), + path("me/internal", UserMeInternal.as_view(), name="api_me_internal"), + path("me/schedule", UserMeSchedule.as_view(), name="api_me_schedule"), + path("me/schedule/week", UserMeScheduleWeek.as_view(), name="api_me_schedule_week"), + path("me/timetable", UserMeTimetable.as_view(), name="api_me_timetable"), path("events", event, name="api_event_list"), - path("timetables", timetableList, name="api_timetable_list"), + #path("events", EventsList.as_view(), name="api_event_list"), + path("timetables", TimetableList.as_view(), name="api_timetable_list"), path( "timetable//schedule", - timetableSchedule, + TimetableSchedule.as_view(), name="api_timetable_schedule", ), - path("timetable/", timetableDetails, name="api_timetable_detail"), - path("terms", termList, name="api_term_list"), - path("term/", termDetail, name="api_term_detail"), - path("term/current", termCurrent, name="api_term_current"), - path("term//schedule", termSchedule, name="api_term_schedule"), + path("timetable/", TimetableDetails.as_view(), name="api_timetable_detail"), + path("terms", TermList.as_view(), name="api_term_list"), + path("term/", TermDetail.as_view(), name="api_term_detail"), + path("term/current", TermCurrent.as_view(), name="api_term_current"), + path("term//schedule", TermSchedule.as_view(), name="api_term_schedule"), path( - "term/current/schedule", termCurrentSchedule, name="api_term_schedule" + "term/current/schedule", TermCurrentSchedule.as_view(), name="api_term_schedule" ), path( "term//schedule/week", - termScheduleWeek, + TermScheduleWeek.as_view(), name="api_term_schedule_week", ), path("v3/staff", staff, name="api_staff3"), diff --git a/core/api/views/organization.py b/core/api/views/organization.py index 1954f2cc..6485ba47 100644 --- a/core/api/views/organization.py +++ b/core/api/views/organization.py @@ -27,7 +27,7 @@ ], ) @api_view(["GET"]) -def apiOrganizationList(request, year=None): +class ApiOrganizationList(ListAPIViewWithFallback): queryset = ( models.Organization.objects.filter(is_active=True) .annotate(num_members=Count("member")) @@ -39,6 +39,6 @@ def apiOrganizationList(request, year=None): responses={200: OrganizationSerializer(many=True)}, ) @api_view(["GET"]) -def organizationDetail(request, year=None): +class OrganizationDetail(ListAPIViewWithFallback): queryset = models.Organization.objects.filter(is_active=True) serializer_class = serializers.OrganizationSerializer diff --git a/core/api/views/term.py b/core/api/views/term.py index 7b41ca70..48bd5c97 100644 --- a/core/api/views/term.py +++ b/core/api/views/term.py @@ -21,7 +21,7 @@ responses={200: TermSerializer(many=True)}, ) @api_view(["GET"]) -def termList(request, year=None): +class TermList(GenericAPIViewWithLastModified, ListAPIViewWithFallback): queryset = models.Term.objects.filter( end_date__gte=(timezone.now() - settings.TERM_GRACE_PERIOD) ) @@ -41,7 +41,7 @@ def get_last_modified(self): responses={200: TermSerializer(many=True)}, ) @api_view(["GET"]) -def termDetail(request, year=None): +class TermDetail(generics.RetrieveAPIView): queryset = models.Term.objects.filter( end_date__gte=(timezone.now() - settings.TERM_GRACE_PERIOD) ) @@ -51,7 +51,7 @@ def termDetail(request, year=None): responses={200: TermSerializer(many=True)}, ) @api_view(["GET"]) -def termSchedule(request, year=None): +class TermSchedule(APIView): def get(self, request, pk, format=None): term = get_object_or_404(models.Term, pk=pk) date = utils.parse_date_query_param(request) @@ -62,7 +62,7 @@ def get(self, request, pk, format=None): responses={200: TermSerializer(many=True)}, ) @api_view(["GET"]) -def termScheduleWeek(request, year=None): +class TermScheduleWeek(APIView): def get(self, request, pk, format=None): term = get_object_or_404(models.Term, pk=pk) date = utils.parse_date_query_param(request) @@ -80,7 +80,7 @@ def get(self, request, pk, format=None): responses={200: TermSerializer(many=True)}, ) @api_view(["GET"]) -def termCurrent(request, year=None): +class TermCurrent(APIView): def get(self, request, format=None): term = models.Term.get_current() @@ -94,7 +94,7 @@ def get(self, request, format=None): responses={200: TermSerializer(many=True)}, ) @api_view(["GET"]) -def termCurrentSchedule(request, year=None): +class TermCurrentSchedule(APIView): def get(self, request, format=None): term = models.Term.get_current() date = utils.parse_date_query_param(request) diff --git a/core/api/views/timetable.py b/core/api/views/timetable.py index 45feafc0..0ed2114a 100644 --- a/core/api/views/timetable.py +++ b/core/api/views/timetable.py @@ -21,23 +21,9 @@ def has_object_permission(self, request, view, obj): @extend_schema( responses={200: TimetableSerializer(many=True)}, - parameters=[ - OpenApiParameter( - "limit", - int, - OpenApiParameter.QUERY, - description="Number of results to return per page.", - ), - OpenApiParameter( - "offset", - int, - OpenApiParameter.QUERY, - description="The initial index from which to return the results.", - ), - ], ) @api_view(["GET"]) -def timetableList(request, year=None): +class TimetableList(ListAPIViewWithFallback): permission_classes = [permissions.IsAuthenticated | TokenHasScope] required_scopes = ["me_timetable"] serializer_class = serializers.TimetableSerializer @@ -52,7 +38,7 @@ def get_queryset(self): responses={200: TimetableSerializer(many=True)}, ) @api_view(["GET"]) -def timetableSchedule(request, year=None): +class TimetableSchedule(APIView): permissions_classes = [permissions.IsAuthenticated | TokenHasScope] required_scopes = ["me_timetable", "me_schedule"] @@ -70,7 +56,7 @@ def get(self, request, pk): responses={200: TimetableSerializer(many=True)}, ) @api_view(["GET"]) -def timetableDetails(request, year=None): +class TimetableDetails(generics.RetrieveAPIView): permission_classes = [IsOwner] queryset = models.Timetable.objects.filter( term__end_date__gte=(timezone.now() - settings.TERM_GRACE_PERIOD) diff --git a/core/api/views/user.py b/core/api/views/user.py index 427d6af5..9d2de89d 100644 --- a/core/api/views/user.py +++ b/core/api/views/user.py @@ -17,7 +17,7 @@ responses={200: UserSerializer(many=True)}, ) @api_view(["GET"]) -def userDetail(request, year=None): +def UserDetail(APIView): queryset = models.User.objects.all() serializer_class = serializers.UserSerializer lookup_field = "username__iexact" @@ -28,7 +28,7 @@ def userDetail(request, year=None): responses={200: UserSerializer(many=True)}, ) @api_view(["GET"]) -def userMe(request, year=None): +def UserMe(APIView): permission_classes = [permissions.IsAuthenticated | TokenHasScope] required_scopes = ["me_meta"] @@ -40,7 +40,7 @@ def get(self, request, format=None): responses={200: UserSerializer(many=True)}, ) @api_view(["GET"]) -def userMeInternal(request, year=None): +def UserMeInternal(APIView): permission_classes = [TokenHasScope] required_scopes = ["me_meta", "internal"] @@ -52,7 +52,7 @@ def get(self, request, format=None): responses={200: UserSerializer(many=True)}, ) @api_view(["GET"]) -def userMeSchedule(request, year=None): +def UserMeSchedule(APIView): permission_classes = [permissions.IsAuthenticated | TokenHasScope] required_scopes = ["me_schedule"] @@ -65,7 +65,7 @@ def get(self, request, format=None): responses={200: UserSerializer(many=True)}, ) @api_view(["GET"]) -def userMeScheduleWeek(request, year=None): +def UserMeScheduleWeek(APIView): permission_classes = [permissions.IsAuthenticated | TokenHasScope] required_scopes = ["me_schedule"] @@ -85,7 +85,7 @@ def get(self, request, format=None): responses={200: UserSerializer(many=True)}, ) @api_view(["GET"]) -def userMeTimetable(request, year=None): +def UserMeTimetable(APIView): permission_classes = [permissions.IsAuthenticated | TokenHasScope] required_scopes = ["me_timetable"]