diff --git a/src/business/repositories.py b/src/business/repositories.py index 155a18e..72dcfd8 100644 --- a/src/business/repositories.py +++ b/src/business/repositories.py @@ -47,3 +47,7 @@ class QRCodeUsingRepository(BaseRepository): start_date, end_date = cls.__get_dates_from_timestamp(timestamp) return cls.model.objects.filter(organization__pk=organization_id, used_dt__gte=start_date, used_dt__lt=end_date).count() + + @classmethod + def get_organizations(cls, user): + return cls.model.objects.filter(client=user) diff --git a/src/organizations/urls.py b/src/organizations/urls.py index 734ac50..f762497 100644 --- a/src/organizations/urls.py +++ b/src/organizations/urls.py @@ -13,5 +13,6 @@ urlpatterns = [ path('categories/', CategoryListAPIView.as_view()), path('map/', OrganizationMapFilterAPIView.as_view()), path('owner/', OwnerOrganizationListAPIView.as_view()), + path('visited/', VisitedOrganizationsListAPIView.as_view()) # path('upload/', UploadAPIView.as_view()) ] + router.urls diff --git a/src/organizations/views.py b/src/organizations/views.py index 0425f93..2139cf5 100644 --- a/src/organizations/views.py +++ b/src/organizations/views.py @@ -11,6 +11,7 @@ from rest_framework.views import APIView from rest_framework.viewsets import ModelViewSet from core.permissions import IsAuthorOrReadOnly +from business.repositories import QRCodeUsingRepository from .repositories import CategoryRepository, OrganizationRepository from .serializers import CategorySerializer, OrganizationListSerializer, OrganizationCreateSerializer from .services import parse_organizations_to_db @@ -113,6 +114,15 @@ class OwnerOrganizationListAPIView(ListAPIView): return OrganizationRepository.get_by_owner(self.request.user) +class VisitedOrganizationsListAPIView(ListAPIView): + serializer_class = OrganizationListSerializer + pagination_class = PageNumberPagination + permission_classes = [IsAuthenticated] + + def get_queryset(self): + return QRCodeUsingRepository.get_organizations(self.request.user) + + class UploadAPIView(APIView): def post(self, request):