Merge branch 'react-version' of https://github.com/MarcEricMartel/420-5DW-HY-TP into react-version
This commit is contained in:
commit
0bc53e7f87
@ -20,7 +20,7 @@ public class InventoryController : Controller {
|
|||||||
|
|
||||||
[EnableCors("_myAllowSpecificOrigins")]
|
[EnableCors("_myAllowSpecificOrigins")]
|
||||||
[HttpGet(Name = "Inventory")] // Pour faire des calls async par paquet de AMOUNT (5) (pour du loading en scrollant)
|
[HttpGet(Name = "Inventory")] // Pour faire des calls async par paquet de AMOUNT (5) (pour du loading en scrollant)
|
||||||
public IEnumerable<Product> Get(int? lastId, string? order, string? filterPrice, string? filterState) {
|
public IEnumerable<Product> Get(int? lastId, string? order, string? filterPrice, string? filterState, bool? all) {
|
||||||
const int AMOUNT = 5;
|
const int AMOUNT = 5;
|
||||||
|
|
||||||
var ret = _context.Products.AsQueryable();
|
var ret = _context.Products.AsQueryable();
|
||||||
@ -95,6 +95,8 @@ public class InventoryController : Controller {
|
|||||||
if (prod.Id == lastId)
|
if (prod.Id == lastId)
|
||||||
yup = true;
|
yup = true;
|
||||||
}
|
}
|
||||||
|
else if (all.HasValue && all == true)
|
||||||
|
lst = ret.ToList();
|
||||||
else lst = ret.Take(AMOUNT).ToList();
|
else lst = ret.Take(AMOUNT).ToList();
|
||||||
|
|
||||||
return lst;
|
return lst;
|
||||||
@ -116,7 +118,7 @@ public class InventoryController : Controller {
|
|||||||
if (prod.Quantity == 0)
|
if (prod.Quantity == 0)
|
||||||
prod.Status = prod.Status == Product.States.Clearance?
|
prod.Status = prod.Status == Product.States.Clearance?
|
||||||
Product.States.Discontinued:
|
Product.States.Discontinued:
|
||||||
Product.States.Unavailable;
|
Product.States.BackOrder;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_logger.LogError(8, "Vente de produit pas en stock.");
|
_logger.LogError(8, "Vente de produit pas en stock.");
|
||||||
|
@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
|
|
||||||
namespace GrossesMitainesAPI.Controllers;
|
namespace GrossesMitainesAPI.Controllers;
|
||||||
|
|
||||||
|
[EnableCors("_myAllowSpecificOrigins")]
|
||||||
[ApiController, Route("api/[controller]")]
|
[ApiController, Route("api/[controller]")]
|
||||||
public class ProductController : ControllerBase {
|
public class ProductController : ControllerBase {
|
||||||
private readonly ILogger<ProductController> _logger;
|
private readonly ILogger<ProductController> _logger;
|
||||||
|
@ -13,27 +13,60 @@ namespace GrossesMitainesAPI.Controllers;
|
|||||||
public class SearchController : Controller {
|
public class SearchController : Controller {
|
||||||
private readonly ILogger<SearchController> _logger;
|
private readonly ILogger<SearchController> _logger;
|
||||||
private readonly InventoryContext _context;
|
private readonly InventoryContext _context;
|
||||||
|
private static List<Product> _searchCache = new();
|
||||||
|
private static DateTime? _cacheDate;
|
||||||
|
|
||||||
public SearchController(ILogger<SearchController> logger, InventoryContext context) {
|
public SearchController(ILogger<SearchController> logger, InventoryContext context) {
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_context = context;
|
_context = context;
|
||||||
|
if (_searchCache.Count == 0 || _cacheDate.HasValue && _cacheDate.Value.AddMinutes(5) < DateTime.Now) {
|
||||||
|
_searchCache = _context.Products.ToList();
|
||||||
|
_cacheDate = DateTime.Now;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[EnableCors("_myAllowSpecificOrigins")]
|
[EnableCors("_myAllowSpecificOrigins")]
|
||||||
[HttpPost(Name = "Search")]
|
[HttpPost(Name = "Search")]
|
||||||
public IEnumerable<Product> Post(string query, bool? preview) {
|
public IEnumerable<Product> Post(string query, bool? preview, bool? deep) {
|
||||||
const int PREVIEW = 3;
|
const int PREVIEW = 4;
|
||||||
HashSet<Product> products = new();
|
List<Product> products = new();
|
||||||
|
|
||||||
query = query.Trim();
|
query = query.Trim();
|
||||||
|
|
||||||
try { // Pour faire une liste priorisée.
|
try { // Pour faire une liste priorisée.
|
||||||
if (preview.HasValue && preview == true)
|
if (preview.HasValue && preview == true)
|
||||||
products = _context.Products.Where(x => x.Title.Contains(query)).Take(PREVIEW).ToHashSet();
|
products = _searchCache.Where(x => x.Title.Contains(query)).Take(PREVIEW).ToList();
|
||||||
else {
|
else {
|
||||||
products.Concat(_context.Products.Where(x => x.Title.Contains(query)).ToHashSet());
|
if (deep.HasValue && deep == true) {
|
||||||
products.Concat(_context.Products.Where(x => x.Category.Contains(query)).ToHashSet());
|
List<Product> title = new(), desc = new(), cat = new();
|
||||||
products.Concat(_context.Products.Where(x => x.Description.Contains(query)).ToHashSet());
|
query = query.ToLower();
|
||||||
|
|
||||||
|
foreach (Product prod in _searchCache) {
|
||||||
|
string sTitle = prod.Title.Replace(".", " ").Replace(",", " ").ToLower(),
|
||||||
|
sCat = prod.Category.Replace(".", " ").Replace(",", " ").ToLower(),
|
||||||
|
sDesc = prod.Description.Replace(".", " ").Replace(",", " ").ToLower();
|
||||||
|
|
||||||
|
if (sTitle.StartsWith(query))
|
||||||
|
products.Add(prod);
|
||||||
|
else if (sTitle.Contains(" " + query + " "))
|
||||||
|
title.Add(prod);
|
||||||
|
else if (sDesc.Contains(" " + query + " "))
|
||||||
|
desc.Add(prod);
|
||||||
|
else if (sCat.Contains(" " + query + " "))
|
||||||
|
cat.Add(prod);
|
||||||
|
}
|
||||||
|
products.AddRange(title);
|
||||||
|
products.AddRange(desc);
|
||||||
|
products.AddRange(cat);
|
||||||
|
} else {
|
||||||
|
products = _searchCache.Where(x => x.Title.Contains(query)).ToList();
|
||||||
|
foreach (Product prod in _searchCache.Where(x => x.Description.Contains(query)).ToList())
|
||||||
|
if (!products.Contains(prod))
|
||||||
|
products.Add(prod);
|
||||||
|
foreach (Product prod in _searchCache.Where(x => x.Category.Contains(query)).ToList())
|
||||||
|
if (!products.Contains(prod))
|
||||||
|
products.Add(prod);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
_logger.LogError(8, e.Message);
|
_logger.LogError(8, e.Message);
|
||||||
|
@ -8,7 +8,7 @@ import LogoTG from "./partenaires/tg.jpg";
|
|||||||
const Footer = () => {
|
const Footer = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<footer className="footer-container footer">
|
<footer className="footer-container">
|
||||||
<div className="footer-links">
|
<div className="footer-links">
|
||||||
<div className="footer-link">
|
<div className="footer-link">
|
||||||
<Link className="nav-link" to="/aboutUs">À Propos</Link>
|
<Link className="nav-link" to="/aboutUs">À Propos</Link>
|
||||||
|
Loading…
Reference in New Issue
Block a user