Service de cache de database fonctionnel
This commit is contained in:
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using GrossesMitainesAPI.Services;
|
||||
|
||||
namespace GrossesMitainesAPI.Controllers;
|
||||
|
||||
@@ -14,10 +15,12 @@ namespace GrossesMitainesAPI.Controllers;
|
||||
public class ProductController : ControllerBase {
|
||||
private readonly ILogger<ProductController> _logger;
|
||||
private readonly InventoryContext _context;
|
||||
private readonly DatabaseCacheService _cache;
|
||||
|
||||
public ProductController(ILogger<ProductController> logger, InventoryContext context) {
|
||||
public ProductController(ILogger<ProductController> logger, InventoryContext context, DatabaseCacheService cache) {
|
||||
_logger = logger;
|
||||
_context = context;
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
[EnableCors("_myAllowSpecificOrigins")]
|
||||
@@ -44,6 +47,7 @@ public class ProductController : ControllerBase {
|
||||
try {
|
||||
_context.Products.Add(prod);
|
||||
_context.SaveChanges();
|
||||
_cache.askForRefresh();
|
||||
}
|
||||
catch (Exception e) {
|
||||
_logger.LogError(8, e.Message);
|
||||
@@ -59,6 +63,7 @@ public class ProductController : ControllerBase {
|
||||
try {
|
||||
_context.Products.Update(prod);
|
||||
_context.SaveChanges();
|
||||
_cache.askForRefresh();
|
||||
}
|
||||
catch (Exception e) {
|
||||
_logger.LogError(8, e.Message);
|
||||
@@ -74,6 +79,7 @@ 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);
|
||||
|
Reference in New Issue
Block a user