diff --git a/frontend/src/hooks/useRealTimeUpdates.ts b/frontend/src/hooks/useRealTimeUpdates.ts index d20a4e2..a8846b1 100644 --- a/frontend/src/hooks/useRealTimeUpdates.ts +++ b/frontend/src/hooks/useRealTimeUpdates.ts @@ -11,6 +11,15 @@ const entityToQueryKeys: Record = { articoli: ['articoli', 'lookup'], 'evento-costi': ['evento-costi', 'evento'], demo: ['eventi', 'clienti', 'location', 'risorse', 'articoli', 'calendario', 'lookup'], + // Warehouse Module + warehouse_article: ['warehouse', 'articles'], + warehouse_category: ['warehouse', 'categories'], + warehouse_location: ['warehouse', 'locations'], + stock_movement: ['warehouse', 'movements'], + article_batch: ['warehouse', 'batches'], + article_serial: ['warehouse', 'serials'], + inventory_count: ['warehouse', 'inventories'], + stock_level: ['warehouse', 'stock-levels'], }; /** diff --git a/src/Apollinare.API/Modules/Warehouse/Services/WarehouseService.cs b/src/Apollinare.API/Modules/Warehouse/Services/WarehouseService.cs index c076c06..b35934a 100644 --- a/src/Apollinare.API/Modules/Warehouse/Services/WarehouseService.cs +++ b/src/Apollinare.API/Modules/Warehouse/Services/WarehouseService.cs @@ -4,6 +4,8 @@ using Apollinare.Infrastructure.Data; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; +using Apollinare.API.Hubs; + namespace Apollinare.API.Modules.Warehouse.Services; /// @@ -15,6 +17,7 @@ public class WarehouseService : IWarehouseService private readonly IMemoryCache _cache; private readonly ILogger _logger; private readonly AutoCodeService _autoCodeService; + private readonly DataNotificationService _notificationService; private const string WAREHOUSES_CACHE_KEY = "warehouse_locations"; private const string CATEGORIES_CACHE_KEY = "warehouse_categories"; @@ -25,12 +28,14 @@ public class WarehouseService : IWarehouseService AppollinareDbContext context, IMemoryCache cache, ILogger logger, - AutoCodeService autoCodeService) + AutoCodeService autoCodeService, + DataNotificationService notificationService) { _context = context; _cache = cache; _logger = logger; _autoCodeService = autoCodeService; + _notificationService = notificationService; } #region Articoli @@ -141,6 +146,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); _logger.LogInformation("Creato articolo {Code} - {Description}", article.Code, article.Description); + await _notificationService.NotifyCreated("warehouse_article", article); return article; } @@ -159,6 +165,7 @@ public class WarehouseService : IWarehouseService existing.UpdatedAt = DateTime.UtcNow; await _context.SaveChangesAsync(); + await _notificationService.NotifyUpdated("warehouse_article", existing); return existing; } @@ -180,6 +187,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); _logger.LogInformation("Eliminato articolo {Code}", article.Code); + await _notificationService.NotifyDeleted("warehouse_article", id); } #endregion @@ -280,6 +288,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); InvalidateCategoriesCache(); + await _notificationService.NotifyCreated("warehouse_category", category); return category; } @@ -294,6 +303,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); InvalidateCategoriesCache(); + await _notificationService.NotifyUpdated("warehouse_category", existing); return existing; } @@ -315,6 +325,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); InvalidateCategoriesCache(); + await _notificationService.NotifyDeleted("warehouse_category", id); } private void InvalidateCategoriesCache() @@ -387,6 +398,7 @@ public class WarehouseService : IWarehouseService InvalidateWarehousesCache(); _logger.LogInformation("Creato magazzino {Code} - {Name}", warehouse.Code, warehouse.Name); + await _notificationService.NotifyCreated("warehouse_location", warehouse); return warehouse; } @@ -409,6 +421,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); InvalidateWarehousesCache(); + await _notificationService.NotifyUpdated("warehouse_location", existing); return existing; } @@ -426,6 +439,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); InvalidateWarehousesCache(); + await _notificationService.NotifyDeleted("warehouse_location", id); } public async Task SetDefaultWarehouseAsync(int id) @@ -445,6 +459,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); InvalidateWarehousesCache(); + await _notificationService.NotifyUpdated("warehouse_location", warehouse); } private void InvalidateWarehousesCache() @@ -517,6 +532,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); _logger.LogInformation("Creato lotto {BatchNumber} per articolo {ArticleId}", batch.BatchNumber, batch.ArticleId); + await _notificationService.NotifyCreated("article_batch", batch); return batch; } @@ -530,6 +546,7 @@ public class WarehouseService : IWarehouseService existing.UpdatedAt = DateTime.UtcNow; await _context.SaveChangesAsync(); + await _notificationService.NotifyUpdated("article_batch", existing); return existing; } @@ -558,6 +575,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); _logger.LogInformation("Aggiornato stato lotto {Id} a {Status}", id, status); + await _notificationService.NotifyUpdated("article_batch", batch); } #endregion @@ -618,6 +636,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); _logger.LogInformation("Creato seriale {SerialNumber} per articolo {ArticleId}", serial.SerialNumber, serial.ArticleId); + await _notificationService.NotifyCreated("article_serial", serial); return serial; } @@ -631,6 +650,7 @@ public class WarehouseService : IWarehouseService existing.UpdatedAt = DateTime.UtcNow; await _context.SaveChangesAsync(); + await _notificationService.NotifyUpdated("article_serial", existing); return existing; } @@ -645,6 +665,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); _logger.LogInformation("Aggiornato stato seriale {Id} a {Status}", id, status); + await _notificationService.NotifyUpdated("article_serial", serial); } #endregion @@ -767,6 +788,7 @@ public class WarehouseService : IWarehouseService stockLevel.StockValue = stockLevel.Quantity * (stockLevel.UnitCost ?? 0); await _context.SaveChangesAsync(); + await _notificationService.NotifyUpdated("stock_level", stockLevel); } #endregion @@ -879,6 +901,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); _logger.LogInformation("Creato movimento {DocumentNumber} tipo {Type}", movement.DocumentNumber, movement.Type); + await _notificationService.NotifyCreated("stock_movement", movement); return movement; } @@ -908,6 +931,7 @@ public class WarehouseService : IWarehouseService } await _context.SaveChangesAsync(); + await _notificationService.NotifyUpdated("stock_movement", existing); return existing; } @@ -936,6 +960,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); _logger.LogInformation("Confermato movimento {DocumentNumber}", movement.DocumentNumber); + await _notificationService.NotifyUpdated("stock_movement", movement); return movement; } @@ -959,6 +984,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); _logger.LogWarning("Annullato movimento {DocumentNumber}", movement.DocumentNumber); + await _notificationService.NotifyUpdated("stock_movement", movement); return movement; } @@ -1493,6 +1519,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); _logger.LogInformation("Creato inventario {Code}", inventory.Code); + await _notificationService.NotifyCreated("inventory_count", inventory); return inventory; } @@ -1509,6 +1536,7 @@ public class WarehouseService : IWarehouseService existing.UpdatedAt = DateTime.UtcNow; await _context.SaveChangesAsync(); + await _notificationService.NotifyUpdated("inventory_count", existing); return existing; } @@ -1531,6 +1559,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); _logger.LogInformation("Avviato inventario {Code} con {Count} righe", inventory.Code, inventory.Lines.Count); + await _notificationService.NotifyUpdated("inventory_count", inventory); return inventory; } @@ -1563,6 +1592,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); _logger.LogInformation("Completato inventario {Code}", inventory.Code); + await _notificationService.NotifyUpdated("inventory_count", inventory); return inventory; } @@ -1632,6 +1662,7 @@ public class WarehouseService : IWarehouseService _logger.LogInformation("Confermato inventario {Code}, movimento rettifica: {MovementId}", inventory.Code, inventory.AdjustmentMovementId); + await _notificationService.NotifyUpdated("inventory_count", inventory); return inventory; } @@ -1650,6 +1681,7 @@ public class WarehouseService : IWarehouseService await _context.SaveChangesAsync(); _logger.LogWarning("Annullato inventario {Code}", inventory.Code); + await _notificationService.NotifyUpdated("inventory_count", inventory); return inventory; } diff --git a/src/Apollinare.API/apollinare.db-shm b/src/Apollinare.API/apollinare.db-shm index ad2011c..fc0c255 100644 Binary files a/src/Apollinare.API/apollinare.db-shm and b/src/Apollinare.API/apollinare.db-shm differ diff --git a/src/Apollinare.API/apollinare.db-wal b/src/Apollinare.API/apollinare.db-wal index f270da5..7a1b575 100644 Binary files a/src/Apollinare.API/apollinare.db-wal and b/src/Apollinare.API/apollinare.db-wal differ