Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into lauren/fetch-all-bidders
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenspark committed Jan 19, 2024
2 parents 9d8db12 + 41b6b82 commit 9837fcd
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions backend/vehicle/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ 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 All @@ -64,6 +65,19 @@ def get(self, request, vehicle_id, *args, **kwargs):
except vehicle.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)

def put(self, request, vehicle_id, format=None):
"""
Update specific vehicle
"""
vehicle = get_object_or_404(Vehicle, id=vehicle_id)
serializer = VehicleSerializer(
vehicle, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

def delete(self, request, vehicle_id, format=None):
"""
Delete specific vehicle
Expand Down Expand Up @@ -91,7 +105,8 @@ 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)

0 comments on commit 9837fcd

Please sign in to comment.