HELL YE- ...oh.
This commit is contained in:
parent
ccb8fa941d
commit
8068f6965d
@ -9,7 +9,13 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using GrossesMitainesAPI.Services;
|
||||
|
||||
namespace GrossesMitainesAPI.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Ce contrôleur ne va pas chercher dans la cache,
|
||||
/// mais les changements dans celui-ci entrainera
|
||||
/// une demande de mise à jour dans cette dernière
|
||||
/// qui sera effectuée dans les 10 secondes après
|
||||
/// l'éxécution d'une modification de la BD.
|
||||
/// </summary>
|
||||
[EnableCors("_myAllowSpecificOrigins")]
|
||||
[ApiController, Route("api/[controller]")]
|
||||
public class ProductController : ControllerBase {
|
||||
@ -40,20 +46,17 @@ public class ProductController : ControllerBase {
|
||||
[EnableCors("_myAllowSpecificOrigins")]
|
||||
[HttpPost(Name = "Product")]
|
||||
public ActionResult<Product> Post(Product prod) {
|
||||
|
||||
if (prod.Price <= prod.PromoPrice)
|
||||
prod.PromoPrice = prod.Price - 0.01M;
|
||||
|
||||
try {
|
||||
_context.Products.Add(prod);
|
||||
_context.SaveChanges();
|
||||
_cache.askForRefresh();
|
||||
}
|
||||
catch (Exception e) {
|
||||
_logger.LogError(8, e.Message);
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
|
||||
_cache.askForRefresh();
|
||||
return prod;
|
||||
}
|
||||
|
||||
@ -63,13 +66,12 @@ public class ProductController : ControllerBase {
|
||||
try {
|
||||
_context.Products.Update(prod);
|
||||
_context.SaveChanges();
|
||||
_cache.askForRefresh();
|
||||
}
|
||||
catch (Exception e) {
|
||||
_logger.LogError(8, e.Message);
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
|
||||
_cache.askForRefresh();
|
||||
return prod;
|
||||
}
|
||||
|
||||
@ -79,13 +81,12 @@ public class ProductController : ControllerBase {
|
||||
try {
|
||||
_context.Products.Remove(_context.Products.Where(x => x.Id == id).First());
|
||||
_context.SaveChanges();
|
||||
_cache.askForRefresh();
|
||||
}
|
||||
catch (Exception e) {
|
||||
_logger.LogError(8, e.Message);
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
|
||||
_cache.askForRefresh();
|
||||
return id;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user