Skip to content

Commit

Permalink
add /me/reports endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hasan7n committed Sep 22, 2023
1 parent 4be81b5 commit bb71e43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/utils/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
path("datasets/", views.DatasetList.as_view()),
path("mlcubes/", views.MlCubeList.as_view()),
path("results/", views.ModelResultList.as_view()),
path("reports/", views.ReportList.as_view()),
path("datasets/associations/", views.DatasetAssociationList.as_view()),
path("mlcubes/associations/", views.MlCubeAssociationList.as_view()),
]
22 changes: 22 additions & 0 deletions server/utils/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from benchmark.serializers import BenchmarkSerializer
from benchmarkdataset.serializers import BenchmarkDatasetListSerializer
from benchmarkmodel.serializers import BenchmarkModelListSerializer
from report.serializers import ReportSerializer
from benchmark.models import Benchmark
from dataset.models import Dataset
from mlcube.models import MlCube
from result.models import ModelResult
from benchmarkmodel.models import BenchmarkModel
from benchmarkdataset.models import BenchmarkDataset
from report.models import Report
from django.http import Http404
from django.conf import settings
from django.db.models import Q
Expand Down Expand Up @@ -114,6 +116,26 @@ def get(self, request, format=None):
return self.get_paginated_response(serializer.data)


class ReportList(GenericAPIView):
serializer_class = ReportSerializer
queryset = ""

def get_object(self, pk):
try:
return Report.objects.filter(owner__id=pk)
except Report.DoesNotExist:
raise Http404

def get(self, request, format=None):
"""
Retrieve all reports associated with the current user
"""
reports = self.get_object(request.user.id)
reports = self.paginate_queryset(reports)
serializer = ReportSerializer(reports, many=True)
return self.get_paginated_response(serializer.data)


class DatasetAssociationList(GenericAPIView):
serializer_class = BenchmarkDatasetListSerializer
queryset = ""
Expand Down

0 comments on commit bb71e43

Please sign in to comment.