Continuage d'API
This commit is contained in:
parent
418f79985e
commit
f5351340d8
@ -0,0 +1,38 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using GrossesMitainesAPI.Models;
|
||||
using System.Linq;
|
||||
using GrossesMitainesAPI.Data;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace GrossesMitainesAPI.Controllers;
|
||||
|
||||
[ApiController, Route("api/[controller]")]
|
||||
public class SearchController : Controller {
|
||||
private readonly ILogger<SearchController> _logger;
|
||||
private readonly InventoryContext _context;
|
||||
|
||||
public SearchController(ILogger<SearchController> logger, InventoryContext context) {
|
||||
_logger = logger;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpPost(Name = "Search")]
|
||||
public IEnumerable<Product> Post(string query, bool preview) {
|
||||
HashSet<Product> products = new();
|
||||
|
||||
query = query.Trim();
|
||||
|
||||
try { // Pour faire une liste priorisée.
|
||||
products.Concat(_context.Products.Where(x => x.Title.Contains(query)).ToHashSet());
|
||||
products.Concat(_context.Products.Where(x => x.Category.Contains(query)).ToHashSet());
|
||||
products.Concat(_context.Products.Where(x => x.Description.Contains(query)).ToHashSet());
|
||||
} catch (Exception e) {
|
||||
_logger.LogError(8, e.Message);
|
||||
}
|
||||
|
||||
return products;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,21 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.Data.SqlClient.Server;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace GrossesMitainesAPI.Models;
|
||||
|
||||
// nom du produit,
|
||||
// catégories, description, quantité disponible, images, prix normal et
|
||||
// autres informations pertinentes
|
||||
public class Product {
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
[Required, MaxLength(255)]
|
||||
public string Title { get; set; } = "Erreur Aucun Objet";
|
||||
[Required]
|
||||
public string Category { get; set; } = "Inconnue";
|
||||
[Required]
|
||||
public string Description { get; set; } = "Lorem Ipsum.";
|
||||
[Range(0.01, (double)decimal.MaxValue)] // Range qui prend pas les decimals!
|
||||
[Required, Range(0.01, (double)decimal.MaxValue)] // Range qui prend pas les decimals!
|
||||
public decimal Price { get; set; } = 0;
|
||||
public string? ImageName { get; set; } // Base pour sortir les images ({ImageName}.png , {ImageName}_thumbnail.png, etc...)
|
||||
public uint Quantity { get; set; } = 0;
|
||||
public string? ImageName { get; set; } // Base pour sortir les images ({ImageName}.jpg , {ImageName}_thumbnail.jpg, etc...)
|
||||
}
|
Loading…
Reference in New Issue
Block a user