-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added equipment register export service
- Loading branch information
1 parent
7fe752a
commit 8e40441
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/MusicCatalogue.Api/Entities/EquipmentExportWorkItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace MusicCatalogue.Api.Entities | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
public class EquipmentExportWorkItem : BackgroundWorkItem | ||
{ | ||
public string FileName { get; set; } = ""; | ||
|
||
public override string ToString() | ||
{ | ||
return $"{base.ToString()}, FileName = {FileName}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Microsoft.Extensions.Options; | ||
using MusicCatalogue.Api.Entities; | ||
using MusicCatalogue.Api.Interfaces; | ||
using MusicCatalogue.Entities.Config; | ||
using MusicCatalogue.Entities.Interfaces; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace MusicCatalogue.Api.Services | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
public class EquipmentExportService : BackgroundQueueProcessor<EquipmentExportWorkItem> | ||
{ | ||
private readonly MusicApplicationSettings _settings; | ||
public EquipmentExportService( | ||
ILogger<BackgroundQueueProcessor<EquipmentExportWorkItem>> logger, | ||
IBackgroundQueue<EquipmentExportWorkItem> queue, | ||
IServiceScopeFactory serviceScopeFactory, | ||
IOptions<MusicApplicationSettings> settings) | ||
: base(logger, queue, serviceScopeFactory) | ||
{ | ||
_settings = settings.Value; | ||
} | ||
|
||
/// <summary> | ||
/// Export the equipment register | ||
/// </summary> | ||
/// <param name="item"></param> | ||
/// <param name="factory"></param> | ||
/// <returns></returns> | ||
protected override async Task ProcessWorkItem(EquipmentExportWorkItem item, IMusicCatalogueFactory factory) | ||
{ | ||
MessageLogger.LogInformation("Retrieving equipment records for export"); | ||
|
||
// Use the file extension to determine which exporter to use | ||
var extension = Path.GetExtension(item.FileName).ToLower(); | ||
IEquipmentExporter? exporter = extension == ".xlsx" ? factory.EquipmentXlsxExporter : factory.EquipmentCsvExporter; | ||
|
||
// Construct the full path to the export file | ||
var filePath = Path.Combine(_settings.CatalogueExportPath, item.FileName); | ||
|
||
// Export the equipment register | ||
await exporter.Export(filePath); | ||
MessageLogger.LogInformation("Equipment register export completed"); | ||
} | ||
} | ||
} |