From fca14e7cfc3c3dab93d350f6eb6e528d696fa4ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Cant=C3=B9?= Date: Wed, 8 Jan 2025 14:25:53 +0100 Subject: [PATCH] add base api for konciv integration --- src/config/routers.py | 2 ++ src/genlab_bestilling/api/serializers.py | 5 +++++ src/genlab_bestilling/api/views.py | 18 ++++++++++++++++-- src/genlab_bestilling/models.py | 16 ++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/config/routers.py b/src/config/routers.py index ebe1dd5..24beca5 100644 --- a/src/config/routers.py +++ b/src/config/routers.py @@ -5,6 +5,7 @@ SpectacularSwaggerView, ) from genlab_bestilling.api.views import ( + AnalysisTypeViewset, ExtractionOrderViewset, LocationViewset, MarkerViewset, @@ -20,6 +21,7 @@ router.register("species", SpeciesViewset, basename="species") router.register("markers", MarkerViewset, basename="markers") router.register("sample-types", SampleTypeViewset, basename="sample_types") +router.register("analysis-types", AnalysisTypeViewset, basename="analysis_types") router.register("locations", LocationViewset, basename="locations") router.register("extraction-order", ExtractionOrderViewset, basename="extraction-order") diff --git a/src/genlab_bestilling/api/serializers.py b/src/genlab_bestilling/api/serializers.py index c8447b8..7599686 100644 --- a/src/genlab_bestilling/api/serializers.py +++ b/src/genlab_bestilling/api/serializers.py @@ -21,6 +21,11 @@ class EnumSerializer(serializers.Serializer): name = serializers.CharField() +class KoncivSerializer(EnumSerializer): + type = serializers.CharField(source="konciv_type") + konciv_id = serializers.CharField() + + class MarkerSerializer(serializers.ModelSerializer): class Meta: model = Marker diff --git a/src/genlab_bestilling/api/views.py b/src/genlab_bestilling/api/views.py index 2f1f683..9be0bc4 100644 --- a/src/genlab_bestilling/api/views.py +++ b/src/genlab_bestilling/api/views.py @@ -15,10 +15,19 @@ SampleTypeFilter, SpeciesFilter, ) -from ..models import ExtractionOrder, Location, Marker, Sample, SampleType, Species +from ..models import ( + AnalysisType, + ExtractionOrder, + Location, + Marker, + Sample, + SampleType, + Species, +) from .serializers import ( EnumSerializer, ExtractionSerializer, + KoncivSerializer, LocationCreateSerializer, LocationSerializer, MarkerSerializer, @@ -160,10 +169,15 @@ def bulk_delete(self, request, pk): class SampleTypeViewset(mixins.ListModelMixin, GenericViewSet): queryset = SampleType.objects.all().order_by("name") - serializer_class = EnumSerializer + serializer_class = KoncivSerializer filterset_class = SampleTypeFilter +class AnalysisTypeViewset(mixins.ListModelMixin, GenericViewSet): + queryset = AnalysisType.objects.all().order_by("name") + serializer_class = KoncivSerializer + + class SpeciesViewset(mixins.ListModelMixin, GenericViewSet): queryset = Species.objects.all().order_by("name") serializer_class = EnumSerializer diff --git a/src/genlab_bestilling/models.py b/src/genlab_bestilling/models.py index 90a7122..24bb8be 100644 --- a/src/genlab_bestilling/models.py +++ b/src/genlab_bestilling/models.py @@ -64,6 +64,14 @@ class SampleType(models.Model): def __str__(self) -> str: return self.name + @property + def konciv_id(self): + return f"ST_{self.id}" + + @property + def konciv_type(self): + return "SAMPLE_TYPE" + class AnalysisType(models.Model): name = models.CharField(max_length=255, null=True, blank=True) @@ -71,6 +79,14 @@ class AnalysisType(models.Model): def __str__(self) -> str: return self.name + @property + def konciv_id(self): + return f"AT_{self.id}" + + @property + def konciv_type(self): + return "ANALYSIS_TYPE" + class LocationType(models.Model): name = models.CharField(max_length=250)