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)