diff --git a/backend/user/urls.py b/backend/user/urls.py index 1e8c1af..67e36e3 100644 --- a/backend/user/urls.py +++ b/backend/user/urls.py @@ -2,13 +2,9 @@ from django.urls import include, path from .views import ( - AdminDetailApiView, - AdminListApiView, - BidderBlacklistApiView, - BidderDetailApiView, - BidderListApiView, - BidderVerifyApiView, -) + AdminDetailApiView, AdminListApiView, BidderBlacklistApiView, + BidderDetailApiView, BidderListApiView, BidderVerifyApiView, + ListBlacklisted, ListUnverified, ListVerified) urlpatterns = [ path("bidders/", BidderListApiView.as_view(), name="bidder-list"), @@ -27,4 +23,7 @@ ), path("admins/", AdminListApiView.as_view(), name="admin-list"), path("admins//", AdminDetailApiView.as_view(), name="admin-detail"), + path("bidders/unverified", ListUnverified.as_view(), name="unverified-list"), + path("bidders/blacklisted", ListBlacklisted.as_view(), name="blacklisted-list"), + path("bidders/verified", ListVerified.as_view(), name="verified-list"), ] diff --git a/backend/user/views.py b/backend/user/views.py index f87ce90..faa4934 100644 --- a/backend/user/views.py +++ b/backend/user/views.py @@ -5,11 +5,8 @@ from .models import Admin, Bidder from .serializers import ( - AdminSerializer, - BidderBlacklistedSerializer, - BidderSerializer, - BidderVerifiedSerializer, -) + AdminSerializer, BidderBlacklistedSerializer, BidderSerializer, + BidderVerifiedSerializer) class BidderListApiView(APIView): @@ -151,3 +148,36 @@ def delete(self, request, admin_id): admin = get_object_or_404(Admin, id=admin_id) admin.delete() return Response(status=status.HTTP_204_NO_CONTENT) + + +class ListUnverified(APIView): + def get(self, request): + bidders = Bidder.objects.all() + unverifiedBidders = [] + for index in range(len(bidders)): + if bidders[index].is_verified is False: + unverifiedBidders.append(bidders[index]) + serializer = BidderSerializer(unverifiedBidders, many=True) + return Response(serializer.data, status=status.HTTP_200_OK) + + +class ListBlacklisted(APIView): + def get(self, request): + bidders = Bidder.objects.all() + blacklistedBidders = [] + for index in range(len(bidders)): + if bidders[index].is_blacklisted is True: + blacklistedBidders.append(bidders[index]) + serializer = BidderSerializer(blacklistedBidders, many=True) + return Response(serializer.data, status=status.HTTP_200_OK) + + +class ListVerified(APIView): + def get(self, request): + bidders = Bidder.objects.all() + verifiedBidders = [] + for index in range(len(bidders)): + if bidders[index].is_verified is True: + verifiedBidders.append(bidders[index]) + serializer = BidderSerializer(verifiedBidders, many=True) + return Response(serializer.data, status=status.HTTP_200_OK) diff --git a/backend/vehicle/admin.py b/backend/vehicle/admin.py index 1d8d12b..d23ecd7 100644 --- a/backend/vehicle/admin.py +++ b/backend/vehicle/admin.py @@ -2,15 +2,7 @@ from django.contrib.contenttypes.models import ContentType from .models import ( - Brand, - Equipment, - SavedUnits, - Supplier, - Trailer, - Type, - UnitImage, - Vehicle, -) + Brand, Equipment, SavedUnits, Supplier, Trailer, Type, UnitImage, Vehicle) class BrandAdmin(admin.ModelAdmin): diff --git a/backend/vehicle/helpers.py b/backend/vehicle/helpers.py index ec1037b..64d0ba1 100644 --- a/backend/vehicle/helpers.py +++ b/backend/vehicle/helpers.py @@ -1,4 +1,5 @@ -from .models import Brand, Equipment, Supplier, Trailer, Type, UnitImage, Vehicle +from .models import ( + Brand, Equipment, Supplier, Trailer, Type, UnitImage, Vehicle) def infinite_filter(request): diff --git a/backend/vehicle/serializers.py b/backend/vehicle/serializers.py index e80e7c3..750ca4b 100644 --- a/backend/vehicle/serializers.py +++ b/backend/vehicle/serializers.py @@ -1,6 +1,7 @@ from rest_framework import serializers -from .models import Brand, Equipment, Supplier, Trailer, Type, UnitImage, Vehicle +from .models import ( + Brand, Equipment, Supplier, Trailer, Type, UnitImage, Vehicle) class BrandSerializer(serializers.ModelSerializer): diff --git a/backend/vehicle/urls.py b/backend/vehicle/urls.py index ff830c1..b2e57c7 100644 --- a/backend/vehicle/urls.py +++ b/backend/vehicle/urls.py @@ -1,11 +1,17 @@ from django.contrib import admin from django.urls import include, path -from .views import VehicleDetailApiView, VehicleFilterList, VehicleListApiView, VehiclePriceApiView +from .views import ( + VehicleDetailApiView, VehicleFilterList, VehicleListApiView, + VehiclePriceApiView) urlpatterns = [ path("", VehicleListApiView.as_view(), name="vehicle"), path("filter/", VehicleFilterList.as_view(), name="vehicle-list"), path("/", VehicleDetailApiView.as_view(), name="vehicle_detail"), - path("/minimum_price/", VehiclePriceApiView.as_view(), name="vehicle_price"), + path( + "/minimum_price/", + VehiclePriceApiView.as_view(), + name="vehicle_price", + ), ] diff --git a/backend/vehicle/views.py b/backend/vehicle/views.py index a566e7f..9a71b34 100644 --- a/backend/vehicle/views.py +++ b/backend/vehicle/views.py @@ -6,16 +6,11 @@ from rest_framework.views import APIView from .helpers import has_more_data, infinite_filter -from .models import Brand, Equipment, Supplier, Trailer, Type, UnitImage, Vehicle +from .models import ( + Brand, Equipment, Supplier, Trailer, Type, UnitImage, Vehicle) from .serializers import ( - BrandSerializer, - EquipmentSerializer, - SupplierSerializer, - TrailerSerializer, - TypeSerializer, - UnitImageSerializer, - VehicleSerializer, -) + BrandSerializer, EquipmentSerializer, SupplierSerializer, + TrailerSerializer, TypeSerializer, UnitImageSerializer, VehicleSerializer) # Create your views here. @@ -41,8 +36,7 @@ def post(self, request, *args, **kwargs): brand = get_object_or_404(Brand, id=brand_id) if brand_id else None vehicle_type = get_object_or_404(Type, id=type_id) if type_id else None - vehicle = Vehicle.objects.create( - brand=brand, vehicle_type=vehicle_type, **data) + vehicle = Vehicle.objects.create(brand=brand, vehicle_type=vehicle_type, **data) # Use the serializer class's data directly serialized_data = self.serializer_class(vehicle) return Response(serialized_data.data, status=status.HTTP_201_CREATED) @@ -71,8 +65,7 @@ def put(self, request, vehicle_id, format=None): """ vehicle = get_object_or_404(Vehicle, id=vehicle_id) - serializer = VehicleSerializer( - vehicle, data=request.data) + serializer = VehicleSerializer(vehicle, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) @@ -105,8 +98,7 @@ def get(self, request): serialized_data = VehicleSerializer(vehicles, many=True) return Response( - {"vehicles": serialized_data.data, - "more_data": has_more_data(request)} + {"vehicles": serialized_data.data, "more_data": has_more_data(request)} ) return Response(VehicleSerializer(Vehicle.objects.all()[:10], many=True).data) @@ -116,6 +108,7 @@ class VehiclePriceApiView(APIView): """ Update a vehicle's minimum price """ + serializer_class = VehicleSerializer def put(self, request, vehicle_id, format=None): @@ -126,12 +119,14 @@ def put(self, request, vehicle_id, format=None): new_price = request.data.get("minimum_price") if new_price is None: - return Response({"error": "Must provide minimum price"}, - status=status.HTTP_400_BAD_REQUEST) + return Response( + {"error": "Must provide minimum price"}, + status=status.HTTP_400_BAD_REQUEST, + ) - serializer = VehicleSerializer(vehicle, - data={'minimum_price': new_price}, - partial=True) + serializer = VehicleSerializer( + vehicle, data={"minimum_price": new_price}, partial=True + ) if serializer.is_valid(): serializer.save() return Response(serializer.data)