Jr ch6 #1

Merged
JMR-dev merged 2 commits from jr-ch6 into main 2021-11-23 21:37:39 +00:00
14 changed files with 65 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
lastPurchaseID integer
locationIDLastPurchasedFrom integer
mostPurchasedLocationID integer
productTypesLastPurchased integer
productsIDLastPurchased integer
productsMostPurchasedID integer
+3
View File
@@ -1,4 +1,5 @@
import { LocationsList } from "./locations/Locations"
import { ProductList } from "./products/Products"
export const KandyKorner = () => {
return(
@@ -6,6 +7,8 @@ export const KandyKorner = () => {
<h1>Kandy Korner</h1>
<h2>Locations</h2>
<LocationsList />
<h2>Products</h2>
<ProductList />
</>
)
}
View File
View File
View File
+27
View File
@@ -0,0 +1,27 @@
import React, {useEffect,useState} from "react";
export const LocationsList = () => {
const [locations, setLocationList] = useState([])
useEffect(
() => {
fetch("http://localhost:8088/locations")
.then(res => res.json())
.then(setLocationList)
},
[]
)
return (
<>
{
locations.map(
(locationObject) => {
return <p key={`locations--${locationObject.id}`}> {locationObject.name}</p>
}
)
}
</>
)
}
View File
View File
+29
View File
@@ -0,0 +1,29 @@
import React, {useEffect,useState} from "react";
export const ProductList = () => {
const [products, setProductList] = useState([])
const [totalProducts, totalProductAmounts] = useState("")
useEffect(
() => {
// table call must be singular in the fetch link in order to properly retrieve objects
fetch("http://localhost:8088/products?_expand=productType&_sort=productTypeId&_order=asc")
.then(res => res.json())
.then(setProductList)
},
[]
)
return (
<>
<div>{totalProducts}</div>
{
products.map(
(productObject) => {
return <p key={`products--${productObject.id}`}> {productObject.candyName} - Price - ${productObject.price} - Candy Type - {productObject.productType.candyType} </p>;
}
)
}
</>
)
}