New REST services for all entities
This commit is contained in:
0
api/__init__.py
Normal file
0
api/__init__.py
Normal file
3
api/admin.py
Normal file
3
api/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
api/apps.py
Normal file
6
api/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ApiConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'api'
|
0
api/migrations/__init__.py
Normal file
0
api/migrations/__init__.py
Normal file
3
api/models.py
Normal file
3
api/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
31
api/serializers.py
Normal file
31
api/serializers.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from container.models import Container, ContainerType
|
||||
from asset.models import Asset, GtinProduct
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class ContainerSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Container
|
||||
fields = ['url', 'id', 'named_id', 'container_type', 'color', 'description']
|
||||
|
||||
|
||||
class ContainerTypeSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = ContainerType
|
||||
fields = ['url', 'id',
|
||||
'named_id', 'description', 'width', 'height', 'length',
|
||||
'inner_width', 'inner_height', 'inner_length',
|
||||
'has_cover', 'contains_container']
|
||||
|
||||
|
||||
class AssetSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Asset
|
||||
fields = ['url', 'id', 'named_id', 'description', 'quantity', 'description']
|
||||
|
||||
|
||||
class GtinProductSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = GtinProduct
|
||||
fields = ['url', 'id', 'gtin', 'api_request', 'api_response', 'name', 'brand']
|
||||
|
3
api/tests.py
Normal file
3
api/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
15
api/urls.py
Normal file
15
api/urls.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.urls import include, path
|
||||
from rest_framework import routers
|
||||
from .views import ContainerViewSet, ContainerTypeViewSet, AssetViewSet, GtinProductViewSet
|
||||
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'containers', ContainerViewSet)
|
||||
router.register(r'container_types', ContainerTypeViewSet)
|
||||
router.register(r'assets', AssetViewSet)
|
||||
router.register(r'products', GtinProductViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
|
||||
]
|
42
api/views.py
Normal file
42
api/views.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework import viewsets
|
||||
from rest_framework import permissions
|
||||
from api.serializers import ContainerSerializer, ContainerTypeSerializer, AssetSerializer, GtinProductSerializer
|
||||
from container.models import Container, ContainerType
|
||||
from asset.models import Asset, GtinProduct
|
||||
|
||||
|
||||
class ContainerViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows containers to be viewed or edited.
|
||||
"""
|
||||
queryset = Container.objects.all().order_by('named_id')
|
||||
serializer_class = ContainerSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
|
||||
class ContainerTypeViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows container-types to be viewed or edited.
|
||||
"""
|
||||
queryset = ContainerType.objects.all()
|
||||
serializer_class = ContainerTypeSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
|
||||
class AssetViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows containers to be viewed or edited.
|
||||
"""
|
||||
queryset = Asset.objects.all().order_by('named_id')
|
||||
serializer_class = AssetSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
|
||||
class GtinProductViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows containers to be viewed or edited.
|
||||
"""
|
||||
queryset = GtinProduct.objects.all().order_by('gtin')
|
||||
serializer_class = GtinProductSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
Reference in New Issue
Block a user