From 616f64531e0e1801e0c76c580f02e37ba9f7c4b2 Mon Sep 17 00:00:00 2001 From: Joonho Jonathan Oh <149014867+joonhoswe@users.noreply.github.com> Date: Sun, 15 Sep 2024 01:05:26 -0400 Subject: [PATCH 1/2] made delete fn --- backend/db.sqlite3 | Bin 139264 -> 139264 bytes src/components/BrowseItemDisplay.jsx | 6 +-- src/components/ItemCard.jsx | 58 +++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/backend/db.sqlite3 b/backend/db.sqlite3 index 5e35f8721486af63152c9686ee2c453239e56a3c..a3975f6cfbd81fd695d676c3abf329d184f38274 100644 GIT binary patch delta 61 zcmZoTz|nAkV}dlJ?nD`9M%~7QtqF`v{_`*hFfj0LhQO@?OdNbH3=E7frpxd##<85FY>l diff --git a/src/components/BrowseItemDisplay.jsx b/src/components/BrowseItemDisplay.jsx index d1997e9..f5a2046 100644 --- a/src/components/BrowseItemDisplay.jsx +++ b/src/components/BrowseItemDisplay.jsx @@ -2,15 +2,15 @@ import ItemCard from "./ItemCard"; import { Wrap, WrapItem } from "@chakra-ui/react"; export default function BrowseItemDisplay({ items }) { - if (!items) { - return
no items match your search
; + if (!items || items.length === 0) { + return
No items match your search.
; } return ( {items.map((item) => { return ( - + ); diff --git a/src/components/ItemCard.jsx b/src/components/ItemCard.jsx index 6c58dde..811b15b 100644 --- a/src/components/ItemCard.jsx +++ b/src/components/ItemCard.jsx @@ -8,6 +8,8 @@ import { Heading, Text, } from "@chakra-ui/react"; +import axios from "axios"; +import AWS from 'aws-sdk'; // item fields: // title, imageUrl, category, @@ -15,6 +17,59 @@ const ItemCard = ({ item }) => { const imageUrls = item.imageURLs.split(","); const firstImage = imageUrls[0]; + AWS.config.update({ + region: 'us-east-2', + credentials: new AWS.Credentials( + import.meta.env.VITE_AWS_ACCESS_KEY, + import.meta.env.VITE_AWS_SECRET_KEY + ), + }); + + const s3 = new AWS.S3(); + + const handleDelete = async (item) => { + // setLoading(true); + try { + // Find the listing to be deleted using the provided id + // const listing = allListings.find(listing => listing.id === id); + // if (!listing) { + // throw new Error("Listing not found"); + // } + + // Delete the listing from the database + await axios.delete(`http://127.0.0.1:8000/api/delete/${item.id}`); + + // Delete images from AWS S3 + for (const imageUrl of imageUrls) { + const imageKey = imageUrl.split('/').pop(); + if (imageKey.length !== 0) { + const information = { + Bucket: 'gradgoodsimages', + Key: imageKey, + }; + await s3.deleteObject(information).promise(); + } + } + + // // Update the local state to remove the deleted listing + // const updatedListings = allListings.filter(listing => listing.id !== id); + + // // Update the user's listings if called from Profile to re-render the listings joined by the user + // if (changeUserListing) { + // await changeUserListing(updatedListings); + // } + // else{ + // await refreshListing(updatedListings); + // } + + } catch (error) { + console.error('Error deleting listing:', error); + } finally { + // setLoading(false); + // setConfirm(false); + } +}; + return ( { ${item.price} + From 58de00e732a163d2a1c97443f2964740ab302190 Mon Sep 17 00:00:00 2001 From: Joonho Jonathan Oh <149014867+joonhoswe@users.noreply.github.com> Date: Sun, 15 Sep 2024 01:10:01 -0400 Subject: [PATCH 2/2] updating gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b89e42c..4d61660 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ __pycache__/ __pycache__/ +db.sqlite3 # Editor directories and files .vscode/*