|
12 | 12 | CustomParameterSerializer, |
13 | 13 | InternalProjectSerializer, |
14 | 14 | CRMOrganizationSerializer, |
| 15 | + InternalProjectsListSerializer, |
15 | 16 | ) |
16 | 17 | from connect.api.v2.internals.filters import CRMOrganizationFilter |
| 18 | +from connect.api.v2.internals.permissions import ProjectsAPITokenPermission |
| 19 | +from connect.api.v2.internals.paginations import ProjectsPageNumberPagination |
17 | 20 | from connect.api.v1.internal.permissions import ModuleHasPermission |
18 | 21 | from connect.api.v1.organization.permissions import IsCRMUser |
19 | 22 | from connect.api.v2.paginations import CustomCursorPagination |
@@ -134,3 +137,31 @@ def list(self, request, *args, **kwargs): |
134 | 137 | def retrieve(self, request, *args, **kwargs): |
135 | 138 | """Retrieve a specific organization by UUID""" |
136 | 139 | return super().retrieve(request, *args, **kwargs) |
| 140 | + |
| 141 | + |
| 142 | +class InternalProjectsListView(views.APIView): |
| 143 | + """ |
| 144 | + Internal API endpoint to list all projects with pagination. |
| 145 | + Returns projects in format: {count, next, previous, results: [{uuid, timezone}]} |
| 146 | + Authentication: Bearer token via PROJECTS_API_TOKEN setting |
| 147 | + """ |
| 148 | + authentication_classes = [] |
| 149 | + permission_classes = [ProjectsAPITokenPermission] |
| 150 | + pagination_class = ProjectsPageNumberPagination |
| 151 | + |
| 152 | + def get(self, request, **kwargs): |
| 153 | + """ |
| 154 | + List all projects with pagination. |
| 155 | + Query params: page, page_size |
| 156 | + """ |
| 157 | + queryset = Project.objects.all().order_by('uuid') |
| 158 | + |
| 159 | + paginator = self.pagination_class() |
| 160 | + page = paginator.paginate_queryset(queryset, request) |
| 161 | + |
| 162 | + if page is not None: |
| 163 | + serializer = InternalProjectsListSerializer(page, many=True) |
| 164 | + return paginator.get_paginated_response(serializer.data) |
| 165 | + |
| 166 | + serializer = InternalProjectsListSerializer(queryset, many=True) |
| 167 | + return Response(serializer.data) |
0 commit comments