From 04c7d68a44ac7daaaeba7e450e36f5a8cc1c56f2 Mon Sep 17 00:00:00 2001 From: MarcEricMartel <74071476+MarcEricMartel@users.noreply.github.com> Date: Wed, 26 Oct 2022 11:29:57 -0700 Subject: [PATCH] SearchBar presque fonctionnelle, Featured qui va fetcher dans la bd --- .../Controllers/InventoryController.cs | 3 ++ .../Controllers/SearchController.cs | 4 +- .../src/components/FeaturedList.js | 7 ++-- .../src/components/ResearchBar.js | 12 +++--- .../grosses-mitaines-ui/src/pages/Home.js | 37 +++++++------------ 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs b/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs index c802bd7..0bc9694 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs @@ -62,6 +62,9 @@ public class InventoryController : Controller { case "isDiscontinued": ret = ret.Where(x => x.Status == Product.States.Discontinued); break; + case "isPromoted": + ret = ret.Where(x => x.Status == Product.States.Clearance || x.Status == Product.States.Promotion); + break; default: break; } switch (order) { diff --git a/GrossesMitaines/GrossesMitainesAPI/Controllers/SearchController.cs b/GrossesMitaines/GrossesMitainesAPI/Controllers/SearchController.cs index 108a13d..38a7243 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Controllers/SearchController.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Controllers/SearchController.cs @@ -26,8 +26,8 @@ public class SearchController : Controller { _searchCache = _cache.GetCacheCopy(); } - [EnableCors("_myAllowSpecificOrigins"), HttpPost(Name = "Search")] - public IEnumerable Post(string query, bool? preview, bool? deep) { + [EnableCors("_myAllowSpecificOrigins"), HttpGet(Name = "Search")] + public IEnumerable Get(string query, bool? preview, bool? deep) { if (_searchCache is not null) return SearchCached(query, preview, deep); else return Search(query, preview, deep); diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/FeaturedList.js b/GrossesMitaines/grosses-mitaines-ui/src/components/FeaturedList.js index 2ca3dfc..86380ff 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/components/FeaturedList.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/components/FeaturedList.js @@ -1,19 +1,20 @@ import { Carousel } from "react-bootstrap"; const FeaturedList = ({ products }) => { - + if (products === null) + return (<>); return ( {products.map((product) => (

{product.title}

{product.description}

Seulement
-

{product.price} $ CA

+

{product.promoPrice} $ CA

))} diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/ResearchBar.js b/GrossesMitaines/grosses-mitaines-ui/src/components/ResearchBar.js index 8bd1773..e46aece 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/components/ResearchBar.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/components/ResearchBar.js @@ -1,18 +1,18 @@ import { useState } from 'react'; +import { Navigate } from 'react-router-dom'; async function fetchData(query, preview) { const response = await fetch(`https://localhost:7292/api/Search?query=${query}&preview=${preview}&deep=true`); const json = await response.json(); - // if (json.length > 0) - // setProducts([...json]); - + return { json }; } function useInput(defaultValue) { const [value, setValue] = useState(defaultValue); function onChange(e) { setValue(e.target.value); - fetchData(value, true); + if (value.length > 1) + fetchData(value, true); } return { value, @@ -25,8 +25,8 @@ const ResearchBar = () => { return (
-
); diff --git a/GrossesMitaines/grosses-mitaines-ui/src/pages/Home.js b/GrossesMitaines/grosses-mitaines-ui/src/pages/Home.js index 92afb71..723057e 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/pages/Home.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/pages/Home.js @@ -1,33 +1,24 @@ import React from "react"; import { useEffect } from "react"; +import { useState } from "react"; import ResearchBar from "../components/ResearchBar"; -import FeatuerdList from "../components/FeaturedList"; +import FeaturedList from "../components/FeaturedList"; const Home = () => { - - const products = [ - { - "title": "Ceinture flèchée", - "description": "Pour faire votre propre bonhomme de 1837, comme dans le bon vieux temps.", - "price": "85,86", - "imageUrl": "/images/ceintureflechee.jpg" - }, - { - "title": "Pantoufles du Canadien en Phentex", - "description": "Parce que ça sent la coupe!", - "price": "15,64", - "imageUrl": "/images/pantouflesCH.jpg" - }, - { - "title": "Jean-Luc Mongrain", - "description": "On ne lui ferait pas mal, en tout cas!!", - "price": "1453,12", - "imageUrl": "/images/jeanlucmongrain.jpg" - } - ]; + const [products, setProducts] = useState([]); + const [loaded, setLoad] = useState(false); useEffect(() => { document.title = 'Maison'; + async function FetchPromo() { + const response = await fetch(`https://localhost:7292/api/Inventory?filterState=isPromoted&all=true`); + const products = await response.json(); + setProducts([...products]) + } + if (loaded === false) { + FetchPromo(); + setLoad(true); + } }); return ( @@ -40,7 +31,7 @@ const Home = () => {

Des produits bien commodes faits par des aînées d'expérience.

-