Skip to content

Commit

Permalink
attempt to do issue 246
Browse files Browse the repository at this point in the history
  • Loading branch information
ohi-711 committed Feb 6, 2024
1 parent 524b0ae commit 1bbc931
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 48 deletions.
35 changes: 18 additions & 17 deletions core/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<int:pk>",
organizationDetail,
OrganizationDetail.as_view(),
name="api_organization_detail",
),
path("user/<str:username>", 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/<str:username>", 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/<int:pk>/schedule",
timetableSchedule,
TimetableSchedule.as_view(),
name="api_timetable_schedule",
),
path("timetable/<int:pk>", timetableDetails, name="api_timetable_detail"),
path("terms", termList, name="api_term_list"),
path("term/<int:pk>", termDetail, name="api_term_detail"),
path("term/current", termCurrent, name="api_term_current"),
path("term/<int:pk>/schedule", termSchedule, name="api_term_schedule"),
path("timetable/<int:pk>", TimetableDetails.as_view(), name="api_timetable_detail"),
path("terms", TermList.as_view(), name="api_term_list"),
path("term/<int:pk>", TermDetail.as_view(), name="api_term_detail"),
path("term/current", TermCurrent.as_view(), name="api_term_current"),
path("term/<int:pk>/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/<int:pk>/schedule/week",
termScheduleWeek,
TermScheduleWeek.as_view(),
name="api_term_schedule_week",
),
path("v3/staff", staff, name="api_staff3"),
Expand Down
4 changes: 2 additions & 2 deletions core/api/views/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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
12 changes: 6 additions & 6 deletions core/api/views/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand All @@ -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)
)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()

Expand All @@ -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)
Expand Down
20 changes: 3 additions & 17 deletions core/api/views/timetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]

Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions core/api/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]

Expand All @@ -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"]

Expand All @@ -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"]

Expand All @@ -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"]

Expand All @@ -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"]

Expand Down

0 comments on commit 1bbc931

Please sign in to comment.