You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.9 KiB
38 lines
1.9 KiB
from rest_framework.views import APIView
|
|
from rest_framework.response import Response
|
|
from rest_framework import status
|
|
from .models import Product, Employee, Contractor, ContractorContact
|
|
from .serializers import ProductSerializer, EmployeeSerializer, ContractorSerializer, ContractorContactSerializer
|
|
|
|
class ProductUploadView(APIView):
|
|
def post(self, request, *args, **kwargs):
|
|
serializer = ProductSerializer(data=request.data, many=True)
|
|
if serializer.is_valid():
|
|
serializer.save()
|
|
return Response({"message": "Products uploaded successfully"}, status=status.HTTP_201_CREATED)
|
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
class EmployeeUploadView(APIView):
|
|
def post(self, request, *args, **kwargs):
|
|
serializer = EmployeeSerializer(data=request.data, many=True)
|
|
if serializer.is_valid():
|
|
serializer.save()
|
|
return Response({"message": "Employees uploaded successfully"}, status=status.HTTP_201_CREATED)
|
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
class ContractorUploadView(APIView):
|
|
def post(self, request, *args, **kwargs):
|
|
serializer = ContractorSerializer(data=request.data, many=True)
|
|
if serializer.is_valid():
|
|
serializer.save()
|
|
return Response({"message": "Contractors uploaded successfully"}, status=status.HTTP_201_CREATED)
|
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
class ContractorContactUploadView(APIView):
|
|
def post(self, request, *args, **kwargs):
|
|
serializer = ContractorContactSerializer(data=request.data, many=True)
|
|
if serializer.is_valid():
|
|
serializer.save()
|
|
return Response({"message": "Contractor contacts uploaded successfully"}, status=status.HTTP_201_CREATED)
|
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|