-
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.
- Loading branch information
1 parent
655a23a
commit fcc35b0
Showing
4 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
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
8 changes: 8 additions & 0 deletions
8
src/MusicCatalogue.Api/Entities/RetailerStatisticsExportWorkItem.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,8 @@ | ||
namespace MusicCatalogue.Api.Entities | ||
{ | ||
public class RetailerStatisticsExportWorkItem : BackgroundWorkItem | ||
{ | ||
public string FileName { get; set; } = ""; | ||
public bool WishList { get; set; } | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
src/MusicCatalogue.Api/Services/RetailerStatisticsExportService.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,47 @@ | ||
using Microsoft.Extensions.Options; | ||
using MusicCatalogue.Api.Entities; | ||
using MusicCatalogue.Api.Interfaces; | ||
using MusicCatalogue.Entities.Config; | ||
using MusicCatalogue.Entities.Interfaces; | ||
using MusicCatalogue.Entities.Reporting; | ||
using MusicCatalogue.Logic.DataExchange.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace MusicCatalogue.Api.Services | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
public class RetailerStatisticsExportService : BackgroundQueueProcessor<RetailerStatisticsExportWorkItem> | ||
{ | ||
private readonly MusicApplicationSettings _settings; | ||
public RetailerStatisticsExportService( | ||
ILogger<BackgroundQueueProcessor<RetailerStatisticsExportWorkItem>> logger, | ||
IBackgroundQueue<RetailerStatisticsExportWorkItem> queue, | ||
IServiceScopeFactory serviceScopeFactory, | ||
IOptions<MusicApplicationSettings> settings) | ||
: base(logger, queue, serviceScopeFactory) | ||
{ | ||
_settings = settings.Value; | ||
} | ||
|
||
/// <summary> | ||
/// Export the retailer statistics report | ||
/// </summary> | ||
/// <param name="item"></param> | ||
/// <param name="factory"></param> | ||
/// <returns></returns> | ||
protected override async Task ProcessWorkItem(RetailerStatisticsExportWorkItem item, IMusicCatalogueFactory factory) | ||
{ | ||
// Get the report data | ||
MessageLogger.LogInformation("Retrieving the retailer statistics report for export"); | ||
var records = await factory.RetailerStatistics.GenerateReportAsync(item.WishList, 1, int.MaxValue); | ||
|
||
// Construct the full path to the export file | ||
var filePath = Path.Combine(_settings.ReportsExportPath, item.FileName); | ||
|
||
// Export the report | ||
var exporter = new CsvExporter<RetailerStatistics>(); | ||
exporter.Export(records, filePath, ','); | ||
MessageLogger.LogInformation("Retailer statistics report export completed"); | ||
} | ||
} | ||
} |