Skip to content

Commit

Permalink
add base api for konciv integration
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Jan 8, 2025
1 parent a9c2582 commit fca14e7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/config/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
SpectacularSwaggerView,
)
from genlab_bestilling.api.views import (
AnalysisTypeViewset,
ExtractionOrderViewset,
LocationViewset,
MarkerViewset,
Expand All @@ -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")

Expand Down
5 changes: 5 additions & 0 deletions src/genlab_bestilling/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions src/genlab_bestilling/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/genlab_bestilling/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,29 @@ 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)

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)
Expand Down

0 comments on commit fca14e7

Please sign in to comment.