Skip to content

Commit

Permalink
Merge pull request #52 from davewalker5/MC-308-Genre-Albums-Report
Browse files Browse the repository at this point in the history
Implement the Albums by Genre Report
  • Loading branch information
davewalker5 authored Aug 20, 2024
2 parents b5f204a + 539fa41 commit 457016f
Show file tree
Hide file tree
Showing 46 changed files with 1,115 additions and 179 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.302
dotnet-version: 8.0.204
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions docker/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:latest
COPY musiccatalogue.api-1.25.0.0 /opt/musiccatalogue.api-1.25.0.0
WORKDIR /opt/musiccatalogue.api-1.25.0.0/bin
COPY musiccatalogue.api-1.30.0.0 /opt/musiccatalogue.api-1.30.0.0
WORKDIR /opt/musiccatalogue.api-1.30.0.0/bin
ENTRYPOINT [ "./MusicCatalogue.Api" ]
4 changes: 2 additions & 2 deletions docker/ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:20-alpine
COPY musiccatalogue.ui-1.29.0.0 /opt/musiccatalogue.ui-1.29.0.0
WORKDIR /opt/musiccatalogue.ui-1.29.0.0
COPY musiccatalogue.ui-1.30.0.0 /opt/musiccatalogue.ui-1.30.0.0
WORKDIR /opt/musiccatalogue.ui-1.30.0.0
RUN npm install
RUN npm run build
ENTRYPOINT [ "npm", "start" ]
17 changes: 16 additions & 1 deletion src/MusicCatalogue.Api/Controllers/ExportController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ public class ExportController : Controller
private readonly IBackgroundQueue<GenreStatisticsExportWorkItem> _genreStatisticsQueue;
private readonly IBackgroundQueue<MonthlySpendExportWorkItem> _monthlySpendQueue;
private readonly IBackgroundQueue<RetailerStatisticsExportWorkItem> _retailerStatisticsQueue;
private readonly IBackgroundQueue<GenreAlbumsExportWorkItem> _genreAlbumsQueue;

public ExportController(
IBackgroundQueue<CatalogueExportWorkItem> catalogueQueue,
IBackgroundQueue<EquipmentExportWorkItem> equipmentQueue,
IBackgroundQueue<ArtistStatisticsExportWorkItem> artistStatisticsQueue,
IBackgroundQueue<GenreStatisticsExportWorkItem> genreStatisticsQueue,
IBackgroundQueue<MonthlySpendExportWorkItem> monthlySpendQueue,
IBackgroundQueue<RetailerStatisticsExportWorkItem> retailerStatisticsQueue)
IBackgroundQueue<RetailerStatisticsExportWorkItem> retailerStatisticsQueue,
IBackgroundQueue<GenreAlbumsExportWorkItem> genreAlbumsQueue)
{
_catalogueQueue = catalogueQueue;
_equipmentQueue = equipmentQueue;
_artistStatisticsQueue = artistStatisticsQueue;
_genreStatisticsQueue = genreStatisticsQueue;
_monthlySpendQueue = monthlySpendQueue;
_retailerStatisticsQueue = retailerStatisticsQueue;
_genreAlbumsQueue = genreAlbumsQueue;
}

[HttpPost]
Expand Down Expand Up @@ -105,5 +108,17 @@ public IActionResult ExportRetailerStatisticsReport([FromBody] RetailerStatistic
_retailerStatisticsQueue.Enqueue(item);
return Accepted();
}

[HttpPost]
[Route("genrealbums")]
public IActionResult ExportGenreAlbumsReport([FromBody] GenreAlbumsExportWorkItem item)
{
// Set the job name used in the job status record
item.JobName = "Albums by Genre Export";

// Queue the work item
_genreAlbumsQueue.Enqueue(item);
return Accepted();
}
}
}
16 changes: 16 additions & 0 deletions src/MusicCatalogue.Api/Controllers/ReportsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,21 @@ public async Task<ActionResult<List<RetailerStatistics>>> GetRetailerStatisticsR
// Convert to a list and return the results
return results.ToList();
}

[HttpGet]
[Route("genreAlbums/{genreId}")]
public async Task<ActionResult<List<GenreAlbum>>> GetGenreAlbumsReportAsync(int genreId)
{
// Get the report content
var results = await _factory.GenreAlbums.GenerateReportAsync(genreId, 1, int.MaxValue);

if (!results.Any())
{
return NoContent();
}

// Convert to a list and return the results
return results.ToList();
}
}
}
8 changes: 8 additions & 0 deletions src/MusicCatalogue.Api/Entities/GenreAlbumsExportWorkItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace MusicCatalogue.Api.Entities
{
public class GenreAlbumsExportWorkItem : BackgroundWorkItem
{
public string FileName { get; set; } = "";
public int GenreId { get; set; }
}
}
22 changes: 11 additions & 11 deletions src/MusicCatalogue.Api/MusicCatalogue.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ReleaseVersion>1.25.0.0</ReleaseVersion>
<FileVersion>1.25.0.0</FileVersion>
<ProductVersion>1.25.0</ProductVersion>
<TargetFramework>net8.0</TargetFramework>
<ReleaseVersion>1.30.0.0</ReleaseVersion>
<FileVersion>1.30.0.0</FileVersion>
<ProductVersion>1.30.0</ProductVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand All @@ -14,13 +14,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.11" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.11" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.5" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.1" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 25 additions & 0 deletions src/MusicCatalogue.Api/MusicCatalogue.Api.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MusicCatalogue.Api", "MusicCatalogue.Api.csproj", "{161E1F59-74B9-4B7F-A41D-124733824FA2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{161E1F59-74B9-4B7F-A41D-124733824FA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{161E1F59-74B9-4B7F-A41D-124733824FA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{161E1F59-74B9-4B7F-A41D-124733824FA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{161E1F59-74B9-4B7F-A41D-124733824FA2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B6903EC5-48B3-48BA-9C2D-F0F52303EE9E}
EndGlobalSection
EndGlobal
4 changes: 4 additions & 0 deletions src/MusicCatalogue.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public static void Main(string[] args)
builder.Services.AddSingleton<IBackgroundQueue<RetailerStatisticsExportWorkItem>, BackgroundQueue<RetailerStatisticsExportWorkItem>>();
builder.Services.AddHostedService<RetailerStatisticsExportService>();

// Add the albums by genre exporter hosted service
builder.Services.AddSingleton<IBackgroundQueue<GenreAlbumsExportWorkItem>, BackgroundQueue<GenreAlbumsExportWorkItem>>();
builder.Services.AddHostedService<GenreAlbumsExportService>();

// Configure JWT
byte[] key = Encoding.ASCII.GetBytes(settings!.Secret);
builder.Services.AddAuthentication(x =>
Expand Down
45 changes: 45 additions & 0 deletions src/MusicCatalogue.Api/Services/GenreAlbumsExportService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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;

namespace MusicCatalogue.Api.Services
{
public class GenreAlbumsExportService : BackgroundQueueProcessor<GenreAlbumsExportWorkItem>
{
private readonly MusicApplicationSettings _settings;
public GenreAlbumsExportService(
ILogger<BackgroundQueueProcessor<GenreAlbumsExportWorkItem>> logger,
IBackgroundQueue<GenreAlbumsExportWorkItem> queue,
IServiceScopeFactory serviceScopeFactory,
IOptions<MusicApplicationSettings> settings)
: base(logger, queue, serviceScopeFactory)
{
_settings = settings.Value;
}

/// <summary>
/// Export the albums by genre report
/// </summary>
/// <param name="item"></param>
/// <param name="factory"></param>
/// <returns></returns>
protected override async Task ProcessWorkItem(GenreAlbumsExportWorkItem item, IMusicCatalogueFactory factory)
{
// Get the report data
MessageLogger.LogInformation("Retrieving the albums by genre report for export");
var records = await factory.GenreAlbums.GenerateReportAsync(item.GenreId, 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<GenreAlbum>();
exporter.Export(records, filePath, ',');
MessageLogger.LogInformation("Albums by genre report export completed");
}
}
}
Loading

0 comments on commit 457016f

Please sign in to comment.