From 76f0ac2962b655c141811badc3160435993765f7 Mon Sep 17 00:00:00 2001 From: through-your-tears Date: Sun, 7 Apr 2024 05:19:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20QR=20=D0=BA=D0=BE=D0=B4=D1=8B=20=D0=B8=20=D1=83?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=BD=D0=B8=D0=BA=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/organizations/repositories.py | 4 ++++ src/organizations/urls.py | 5 +++-- src/organizations/views.py | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) 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):