Skip to content

Commit

Permalink
chore: migrate case list to TanStack Query (#1924) (#1925)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Aug 24, 2024
1 parent a4655c2 commit d056d46
Show file tree
Hide file tree
Showing 27 changed files with 6,029 additions and 4,079 deletions.
7 changes: 7 additions & 0 deletions backend/cases/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ class Meta:
read_only_fields = fields


class RecordCountSerializer(serializers.Serializer):
"""Serializer for the record count."""

#: Number of cases.
count = serializers.IntegerField()


class CaseSerializerNg(CoreCaseSerializerMixin, SODARProjectModelSerializer):
"""Serializer for the ``Case`` model.
Expand Down
5 changes: 5 additions & 0 deletions backend/cases/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
]

api_urlpatterns = [
url(
regex=r"^api/case/count/(?P<project>[0-9a-f-]+)/?$",
view=views_api.CaseCountApiView.as_view(),
name="api-case-count",
),
url(
regex=r"^api/case/list/(?P<project>[0-9a-f-]+)/?$",
view=views_api.CaseListApiView.as_view(),
Expand Down
43 changes: 43 additions & 0 deletions backend/cases/views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from rest_framework.pagination import PageNumberPagination
from rest_framework.permissions import BasePermission
from rest_framework.response import Response

from cases.models import ExtraAnnoFieldInfo, GlobalSettings, UserAndGlobalSettings, UserSettings
from cases.serializers import (
Expand All @@ -29,6 +30,7 @@
CaseGeneAnnotationSerializer,
CaseSerializerNg,
PedigreeRelatednessSerializer,
RecordCountSerializer,
SampleVariantStatisticsSerializer,
UserAndGlobalSettingsSerializer,
)
Expand Down Expand Up @@ -61,6 +63,47 @@ class CasePagination(PageNumberPagination):
max_page_size = 1000


@extend_schema_view(
get=extend_schema(
parameters=[
OpenApiParameter(name="q", type=str),
],
responses=RecordCountSerializer,
)
)
class CaseCountApiView(SODARAPIBaseProjectMixin, RetrieveAPIView):
"""Return the number of cases, potentially filtered."""

permission_classes = [SODARAPIProjectPermission]

renderer_classes = [VarfishApiRenderer]
versioning_class = VarfishApiVersioning
serializer_class = RecordCountSerializer

def get(self, request, *args, **kwargs):
return Response({"count": self.get_queryset().count()})

def get_queryset(self):
# Use ``select_related()`` so we do not have to explicitely fetch projects and preset sets for serializing as
# projects.sodar_uuid and presetset.sodar_uuid.
qs = Case.objects.filter(project__sodar_uuid=self.kwargs["project"])
if self.request.GET.get("q"):
qs = qs.filter(name__icontains=self.request.GET.get("q"))
order_by_str = self.request.query_params.get("order_by", "")
if order_by_str:
order_dir = self.request.query_params.get("order_dir", "asc")
order_by = order_by_str.split(",")
if order_dir == "desc":
qs = qs.order_by(*[f"-{value}" for value in order_by])
else:
qs = qs.order_by(*order_by)
qs = qs.select_related("project", "presetset")
return qs

def get_permission_required(self):
return "cases.view_data"


@extend_schema_view(
get=extend_schema(
parameters=[
Expand Down
36 changes: 36 additions & 0 deletions backend/varfish/tests/drf_openapi_schema/varfish_api_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,34 @@ paths:
responses:
'204':
description: No response body
/cases/api/case/count/{project}/:
get:
operationId: cases_api_case_count_retrieve
description: Return the number of cases, potentially filtered.
parameters:
- in: path
name: project
schema:
type: string
pattern: ^[0-9a-f-]+$
required: true
- in: query
name: q
schema:
type: string
tags:
- cases
security:
- basicAuth: []
- cookieAuth: []
- knoxApiToken: []
responses:
'200':
content:
application/vnd.bihealth.varfish+json:
schema:
$ref: '#/components/schemas/RecordCount'
description: ''
/cases/api/case/list/{project}/:
get:
operationId: cases_api_case_list_list
Expand Down Expand Up @@ -8833,6 +8861,14 @@ components:
* `comphet_recessive` - comphet_recessive
* `homozygous_recessive` - homozygous_recessive
* `recessive` - recessive
RecordCount:
type: object
description: Serializer for the record count.
properties:
count:
type: integer
required:
- count
RegionCoverageStats:
description: Per-region QC stats for alignment.
properties:
Expand Down
3,027 changes: 3,027 additions & 0 deletions frontend/ext/varfish-api/src/lib/@tanstack/vue-query.gen.ts

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions frontend/ext/varfish-api/src/lib/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4472,6 +4472,17 @@ export const $RecessiveModeEnum = {
* \`recessive\` - recessive`
} as const;

export const $RecordCount = {
type: 'object',
description: 'Serializer for the record count.',
properties: {
count: {
type: 'integer'
}
},
required: ['count']
} as const;

export const $RegionCoverageStats = {
description: 'Per-region QC stats for alignment.',
properties: {
Expand Down
3,654 changes: 1,668 additions & 1,986 deletions frontend/ext/varfish-api/src/lib/services.gen.ts

Large diffs are not rendered by default.

Loading

0 comments on commit d056d46

Please sign in to comment.