Ca va p-e marcher
This commit is contained in:
		| @@ -16,8 +16,10 @@ public class InventoryController : Controller { | ||||
|         _logger = logger; | ||||
|     } | ||||
|  | ||||
|     [HttpGet(Name = "Inventory")] // Pour faire des calls async par paquet de 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 filter) { | ||||
|         const uint AMOUNT = 5; | ||||
|  | ||||
|         var ret = _context.Products.AsQueryable(); | ||||
|  | ||||
|         switch (filter) { | ||||
| @@ -45,45 +47,38 @@ public class InventoryController : Controller { | ||||
|             case "isDiscontinued": | ||||
|                 ret = ret.Where(x => x.Quantity == 0 && x.isDiscontinued); | ||||
|                 break; | ||||
|             default: break; | ||||
|         } | ||||
|  | ||||
|         switch (order) { | ||||
|             case "Price": | ||||
|                 ret = ret.OrderBy(x => x.Price) | ||||
|                          .Where(x => x.Id > lastId && x.Id < lastId + 5); | ||||
|                 ret = ret.OrderBy(x => x.Price); | ||||
|                 break; | ||||
|             case "PriceDesc": | ||||
|                 ret = ret.OrderByDescending(x => x.Price) | ||||
|                          .Where(x => x.Id < lastId && x.Id > lastId - 5); | ||||
|                 ret = ret.OrderByDescending(x => x.Price); | ||||
|                 break; | ||||
|             case "Title": | ||||
|                 ret = ret.OrderBy(x => x.Title) | ||||
|                          .Where(x => x.Id > lastId && x.Id < lastId + 5); | ||||
|                 ret = ret.OrderBy(x => x.Title); | ||||
|                 break; | ||||
|             case "TitleDesc": | ||||
|                 ret = ret.OrderByDescending(x => x.Title) | ||||
|                          .Where(x => x.Id < lastId && x.Id > lastId - 5); | ||||
|                 ret = ret.OrderByDescending(x => x.Title); | ||||
|                 break; | ||||
|             case "Category": | ||||
|                 ret = ret.OrderBy(x => x.Category) | ||||
|                          .Where(x => x.Id > lastId && x.Id < lastId + 5); | ||||
|                 ret = ret.OrderBy(x => x.Category); | ||||
|                 break; | ||||
|             case "CategoryDesc": | ||||
|                 ret = ret.OrderByDescending(x => x.Category) | ||||
|                          .Where(x => x.Id < lastId && x.Id > lastId - 5); | ||||
|                 break; | ||||
|             default: | ||||
|                 | ||||
|                 ret = ret.OrderByDescending(x => x.Category); | ||||
|                 break; | ||||
|             default: break; | ||||
|         } | ||||
|         if (order.Contains("Desc")) { | ||||
|         if (order is not null && order.Contains("Desc")) { | ||||
|             if (!lastId.HasValue) | ||||
|                 lastId = _context.Products.Max(x => x.Id); | ||||
|             ret = ret.Where(x => x.Id < lastId && x.Id > lastId - 5); | ||||
|             ret = ret.Where(x => x.Id < lastId && x.Id > lastId - AMOUNT); | ||||
|         } else { | ||||
|             if (!lastId.HasValue) | ||||
|                 lastId = 1; | ||||
|             ret = ret.Where(x => x.Id > lastId && x.Id < lastId + 5); | ||||
|             ret = ret.Where(x => x.Id > lastId && x.Id < lastId + AMOUNT); | ||||
|         } | ||||
|         return ret.ToList(); | ||||
|     } | ||||
|   | ||||
| @@ -3,6 +3,7 @@ using GrossesMitainesAPI.Models; | ||||
| using System.Linq; | ||||
| using GrossesMitainesAPI.Data; | ||||
| using Microsoft.Extensions.Logging; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
|  | ||||
| namespace GrossesMitainesAPI.Controllers; | ||||
|  | ||||
| @@ -16,7 +17,7 @@ public class ProductController : Controller { | ||||
|         _context = context; | ||||
|     } | ||||
|  | ||||
|     [HttpGet(Name = "Product")] | ||||
|     [HttpGet(Name = "Product"), AllowAnonymous] | ||||
|     public Product Get(int id) { | ||||
|         Product prod; | ||||
|         try { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user