Skip to content

Commit

Permalink
Add endpoints for fetching verified/unverified/blacklisted bidders (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: Lance Tan <ltan0521@gmail.com>
  • Loading branch information
laurenspark and ltan02 authored Feb 4, 2024
1 parent 15847e3 commit d4261db
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 45 deletions.
13 changes: 6 additions & 7 deletions backend/user/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -27,4 +23,7 @@
),
path("admins/", AdminListApiView.as_view(), name="admin-list"),
path("admins/<uuid:admin_id>/", 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"),
]
40 changes: 35 additions & 5 deletions backend/user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@

from .models import Admin, Bidder
from .serializers import (
AdminSerializer,
BidderBlacklistedSerializer,
BidderSerializer,
BidderVerifiedSerializer,
)
AdminSerializer, BidderBlacklistedSerializer, BidderSerializer,
BidderVerifiedSerializer)


class BidderListApiView(APIView):
Expand Down Expand Up @@ -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)
10 changes: 1 addition & 9 deletions backend/vehicle/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion backend/vehicle/helpers.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
3 changes: 2 additions & 1 deletion backend/vehicle/serializers.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
10 changes: 8 additions & 2 deletions backend/vehicle/urls.py
Original file line number Diff line number Diff line change
@@ -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("<uuid:vehicle_id>/", VehicleDetailApiView.as_view(), name="vehicle_detail"),
path("<uuid:vehicle_id>/minimum_price/", VehiclePriceApiView.as_view(), name="vehicle_price"),
path(
"<uuid:vehicle_id>/minimum_price/",
VehiclePriceApiView.as_view(),
name="vehicle_price",
),
]
35 changes: 15 additions & 20 deletions backend/vehicle/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -116,6 +108,7 @@ class VehiclePriceApiView(APIView):
"""
Update a vehicle's minimum price
"""

serializer_class = VehicleSerializer

def put(self, request, vehicle_id, format=None):
Expand All @@ -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)
Expand Down

0 comments on commit d4261db

Please sign in to comment.