diff --git a/src/organizations/repositories.py b/src/organizations/repositories.py index a9d03ec..c5a8463 100644 --- a/src/organizations/repositories.py +++ b/src/organizations/repositories.py @@ -49,6 +49,10 @@ class OrganizationRepository(BaseRepository): rectangle = Polygon.from_bbox((*coords1, *coords2)) return cls.get_by_categories(categories).filter(location__coords__within=rectangle) + @classmethod + def get_by_owner(cls, owner): + return cls.model.objects.filter(owner=owner) + class OrganizationImagesRepository(BaseRepository): model = OrganizationImage diff --git a/src/organizations/urls.py b/src/organizations/urls.py index 26faf33..734ac50 100644 --- a/src/organizations/urls.py +++ b/src/organizations/urls.py @@ -1,7 +1,7 @@ from django.urls import path from rest_framework.routers import DefaultRouter -from .views import OrganizationViewSet, OrganizationSearchListAPIView, OrganizationByCategoryListAPIView, CategoryListAPIView, OrganizationMapFilterAPIView, UploadAPIView +from .views import * app_name = "organizations" @@ -11,6 +11,7 @@ urlpatterns = [ path('category//organizations/', OrganizationByCategoryListAPIView.as_view()), path('search//', OrganizationSearchListAPIView.as_view()), path('categories/', CategoryListAPIView.as_view()), - path('map/', OrganizationMapFilterAPIView.as_view()) + path('map/', OrganizationMapFilterAPIView.as_view()), + path('owner/', OwnerOrganizationListAPIView.as_view()), # path('upload/', UploadAPIView.as_view()) ] + router.urls diff --git a/src/organizations/views.py b/src/organizations/views.py index a225219..0425f93 100644 --- a/src/organizations/views.py +++ b/src/organizations/views.py @@ -5,6 +5,7 @@ from django.views.decorators.vary import vary_on_cookie from rest_framework import status from rest_framework.generics import ListAPIView from rest_framework.pagination import PageNumberPagination +from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from rest_framework.viewsets import ModelViewSet @@ -103,6 +104,15 @@ class OrganizationByCategoryListAPIView(ListAPIView): return OrganizationRepository.all() +class OwnerOrganizationListAPIView(ListAPIView): + permission_classes = [IsAuthenticated] + pagination_class = PageNumberPagination + serializer_class = OrganizationListSerializer + + def get_queryset(self): + return OrganizationRepository.get_by_owner(self.request.user) + + class UploadAPIView(APIView): def post(self, request):