From d3bdc0b349b7b48e8af1a14dbecf08d9c3219c24 Mon Sep 17 00:00:00 2001 From: _Kevin_Zhang_ <49049813+Dragollax@users.noreply.github.com> Date: Fri, 12 Apr 2024 21:11:12 -0700 Subject: [PATCH 1/2] initial commit --- backend/auction/serializers.py | 13 +++++++ .../src/components/modals/BiddingModal.jsx | 35 +++++++++++++++++-- frontend/src/pages/VehicleDetailsPage.jsx | 14 +++++--- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/backend/auction/serializers.py b/backend/auction/serializers.py index a5fa1a0..4ca8d76 100644 --- a/backend/auction/serializers.py +++ b/backend/auction/serializers.py @@ -1,9 +1,16 @@ from rest_framework import serializers from .models import Auction, AuctionItem, AuctionVerifiedUser +from datetime import date + + +from rest_framework import serializers +from .models import Auction, AuctionDay class AuctionSerializer(serializers.ModelSerializer): + auctionday_id = serializers.SerializerMethodField() + class Meta: model = Auction fields = [ @@ -15,8 +22,14 @@ class Meta: "end_time", "cover_image", "is_published", + "auctionday_id", # Add auctionday_id to the fields ] + def get_auctionday_id(self, obj): + current_date = date.today() + auction_day = obj.days.filter(date=current_date).first() + return auction_day.id if auction_day else None + class AuctionItemSerializer(serializers.ModelSerializer): class Meta: diff --git a/frontend/src/components/modals/BiddingModal.jsx b/frontend/src/components/modals/BiddingModal.jsx index 07da419..18eb288 100644 --- a/frontend/src/components/modals/BiddingModal.jsx +++ b/frontend/src/components/modals/BiddingModal.jsx @@ -3,15 +3,18 @@ import DoNotDisturbOnOutlinedIcon from '@mui/icons-material/DoNotDisturbOnOutlin import AddCircleOutlineOutlinedIcon from '@mui/icons-material/AddCircleOutlineOutlined'; import BidNowButton from '../buttons/BidNowButton'; import CancelButton from '../buttons/CancelButton'; +import useAxios from '../../hooks/useAxios'; export default function BiddingModal({ isOpen, onClose, - handleBidNow, + auction, + vehicle, minimumBid, + onPriceUpdate }) { if (!isOpen) return null; - + const { fetchData } = useAxios(); const increments = minimumBid > 100000 ? 5000 : 1000; const [bidAmount, setBidAmount] = useState(minimumBid + increments); @@ -37,6 +40,34 @@ export default function BiddingModal({ } }; + const handleBidNow = async () => { + const bidderId = 1; + + try { + const response = await fetchData({ + method: 'POST', + endpoint: '/v1/bids/', + data: JSON.stringify({ + amount: bidAmount, + bidder_id: bidderId, + auction_id: auction.id, + auction_day_id: auction.auctionday_id, + object_id: vehicle.id, + }), + headers: { + 'Content-Type': 'application/json', + }, + }); + if (response.status === 201) { + onClose(); + onPriceUpdate(bidAmount); + } + + } catch (error) { + console.error('Error creating bid:', error); + } + }; + useEffect(() => { window.addEventListener('click', handleOutsideClick); return () => { diff --git a/frontend/src/pages/VehicleDetailsPage.jsx b/frontend/src/pages/VehicleDetailsPage.jsx index 2fedaff..dcdd909 100644 --- a/frontend/src/pages/VehicleDetailsPage.jsx +++ b/frontend/src/pages/VehicleDetailsPage.jsx @@ -37,7 +37,6 @@ export default function VehicleDetailsPage() { endpoint: '/v1/auctions/current', method: 'GET', }); - setAuction(response.data); }; fetchAuction(); @@ -63,7 +62,12 @@ export default function VehicleDetailsPage() { startTime.setDate(startTime.getDate() + 1); endTime.setDate(endTime.getDate() + 1); } - + const handlePriceUpdate = (newPrice) => { + setVehicle(prevVehicle => ({ + ...prevVehicle, + current_price: newPrice + })); + }; return (
@@ -187,10 +191,12 @@ export default function VehicleDetailsPage() {
{bidModalOpen && ( setBidModalOpen(false)} - handleBidNow={() => {}} - minimumBid={210000} + minimumBid={vehicle.current_price} + onPriceUpdate={handlePriceUpdate} /> )} From 3bf9743f9e43539b5506240dde9ea440c3a41585 Mon Sep 17 00:00:00 2001 From: Lance Tan Date: Fri, 12 Apr 2024 21:45:26 -0700 Subject: [PATCH 2/2] Fix pipeline --- backend/auction/serializers.py | 7 +-- .../src/components/modals/BiddingModal.jsx | 46 +++++++++---------- frontend/src/pages/VehicleDetailsPage.jsx | 8 ++-- 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/backend/auction/serializers.py b/backend/auction/serializers.py index 4ca8d76..a91246f 100644 --- a/backend/auction/serializers.py +++ b/backend/auction/serializers.py @@ -1,11 +1,8 @@ -from rest_framework import serializers - -from .models import Auction, AuctionItem, AuctionVerifiedUser from datetime import date - from rest_framework import serializers -from .models import Auction, AuctionDay + +from .models import Auction, AuctionItem, AuctionVerifiedUser class AuctionSerializer(serializers.ModelSerializer): diff --git a/frontend/src/components/modals/BiddingModal.jsx b/frontend/src/components/modals/BiddingModal.jsx index 18eb288..009e012 100644 --- a/frontend/src/components/modals/BiddingModal.jsx +++ b/frontend/src/components/modals/BiddingModal.jsx @@ -11,7 +11,7 @@ export default function BiddingModal({ auction, vehicle, minimumBid, - onPriceUpdate + onPriceUpdate, }) { if (!isOpen) return null; const { fetchData } = useAxios(); @@ -41,33 +41,29 @@ export default function BiddingModal({ }; const handleBidNow = async () => { - const bidderId = 1; - - try { - const response = await fetchData({ - method: 'POST', - endpoint: '/v1/bids/', - data: JSON.stringify({ - amount: bidAmount, - bidder_id: bidderId, - auction_id: auction.id, - auction_day_id: auction.auctionday_id, - object_id: vehicle.id, - }), - headers: { - 'Content-Type': 'application/json', - }, - }); - if (response.status === 201) { - onClose(); - onPriceUpdate(bidAmount); - } + const bidderId = 1; + try { + const response = await fetchData({ + method: 'POST', + endpoint: '/v1/bids/', + data: { + amount: bidAmount, + bidder_id: bidderId, + auction_id: auction.id, + auction_day_id: auction.auctionday_id, + object_id: vehicle.id, + }, + }); + if (response.status === 201) { + onClose(); + onPriceUpdate(bidAmount); + } } catch (error) { - console.error('Error creating bid:', error); + /* empty */ } - }; - + }; + useEffect(() => { window.addEventListener('click', handleOutsideClick); return () => { diff --git a/frontend/src/pages/VehicleDetailsPage.jsx b/frontend/src/pages/VehicleDetailsPage.jsx index 79b3f22..5346a24 100644 --- a/frontend/src/pages/VehicleDetailsPage.jsx +++ b/frontend/src/pages/VehicleDetailsPage.jsx @@ -63,11 +63,11 @@ export default function VehicleDetailsPage() { endTime.setDate(endTime.getDate() + 1); } const handlePriceUpdate = (newPrice) => { - setVehicle(prevVehicle => ({ - ...prevVehicle, - current_price: newPrice + setVehicle((prevVehicle) => ({ + ...prevVehicle, + current_price: newPrice, })); - }; + }; return (