Skip to content

Commit

Permalink
add see-all-products from database
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinuy committed Nov 12, 2024
1 parent e6e1551 commit 6096d4e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 9 deletions.
1 change: 1 addition & 0 deletions frontend/src/Category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Category = "Fruit" | "Sweet" | "Vegetables" | "Meat" | "Fish" | "Drink"
8 changes: 8 additions & 0 deletions frontend/src/Product.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {Category} from "./Category.ts";

export type Product = {
id: number,
name: string,
category: Category,
price:number
}
1 change: 1 addition & 0 deletions frontend/src/Status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Status = "available" | "not_available"
26 changes: 21 additions & 5 deletions frontend/src/components/ProductCard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import "./ProductCard.css"
import {Product} from "../Product.ts";

export default function ProductCard() {
type Props = {
product: Product;
/* id: number,
name: string,
category: Category,
status: Status,
price: number*/
}

export default function ProductCard(props : Props) {
return (
<>
<p>product</p>
</>
);
<div>
<p>product</p>

<p>"Id: "{props.product.id}</p>
<p>"Name: "{props.product.name}</p>
<p>"Category: "{props.product.category}</p>
<p>"Price: "{props.product.price}</p>

</div>
)
}
29 changes: 25 additions & 4 deletions frontend/src/components/ProductView.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import "./ProductView.css"
import ProductCard from "./ProductCard.tsx";
import axios from "axios";
import {useEffect, useState} from "react";
import {Product} from "../Product.ts";

export default function ProductView() {

const [products,setProducts] = useState<Product[]>([])

function fetchAllProducts(){
axios({
method:"GET",
url:"api/store",

})
.then((response)=>{setProducts(response.data)})
}

useEffect(() => {
fetchAllProducts();
}, []);

return (
<>
<p>products:</p>
<ProductCard/>
</>
<div>
<p>Products : </p>
{
products.map((product)=>{return <ProductCard product={product} key={product.id}/>})
}
</div>
);
};
6 changes: 6 additions & 0 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
server:{
proxy:{
'/api': {
target: 'http://localhost:8080'
}
}}
})

0 comments on commit 6096d4e

Please sign in to comment.