Skip to content

Commit

Permalink
Make sure artist stats account for wish list/non wish list album split
Browse files Browse the repository at this point in the history
  • Loading branch information
davewalker5 committed Nov 10, 2023
1 parent eaea1e3 commit 1813977
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/MusicCatalogue.Api/Controllers/ArtistsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task<ActionResult<List<Artist>>> GetArtistsAsync(bool wishlist)
}

// Populate the artist statistics
await _factory.Statistics.PopulateArtistStatistics(artists);
await _factory.Statistics.PopulateArtistStatistics(artists, wishlist);

return artists;
}
Expand Down
4 changes: 2 additions & 2 deletions src/MusicCatalogue.Data/MusicCatalogue.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>MusicCatalogue.Data</PackageId>
<PackageVersion>1.8.0.0</PackageVersion>
<PackageVersion>1.9.0.0</PackageVersion>
<Authors>Dave Walker</Authors>
<Copyright>Copyright (c) Dave Walker 2023</Copyright>
<Owners>Dave Walker</Owners>
Expand All @@ -17,7 +17,7 @@
<PackageProjectUrl>https://github.com/davewalker5/MusicCatalogue</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<ReleaseVersion>1.8.0.0</ReleaseVersion>
<ReleaseVersion>1.9.0.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace MusicCatalogue.Entities.Interfaces
{
public interface IStatisticsManager
{
Task PopulateArtistStatistics(IEnumerable<Artist> artists);
Task PopulateArtistStatistics(IEnumerable<Artist> artists, bool wishlist);
}
}
4 changes: 2 additions & 2 deletions src/MusicCatalogue.Entities/MusicCatalogue.Entities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>MusicCatalogue.Entities</PackageId>
<PackageVersion>1.8.0.0</PackageVersion>
<PackageVersion>1.9.0.0</PackageVersion>
<Authors>Dave Walker</Authors>
<Copyright>Copyright (c) Dave Walker 2023</Copyright>
<Owners>Dave Walker</Owners>
Expand All @@ -17,7 +17,7 @@
<PackageProjectUrl>https://github.com/davewalker5/MusicCatalogue</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<ReleaseVersion>1.8.0.0</ReleaseVersion>
<ReleaseVersion>1.9.0.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
14 changes: 10 additions & 4 deletions src/MusicCatalogue.Logic/Database/StatisticsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@ internal StatisticsManager(IMusicCatalogueFactory factory)
/// Populate the album and track counts on each artist in the specified collection
/// </summary>
/// <param name="artists"></param>
/// <param name="wishlist"></param>
/// <returns></returns>
public async Task PopulateArtistStatistics(IEnumerable<Artist> artists)
public async Task PopulateArtistStatistics(IEnumerable<Artist> artists, bool wishlist)
{
// Iterate over the supplied list
foreach (var artist in artists)
{
// Get the albums for the current artist
var albums = await _factory.Albums.ListAsync(x => x.ArtistId == artist.Id);
// If the albums are already attached, use that list to calculate the statistics. Otherwise,
// load the albums from the database
var albums = artist.Albums;
if ((albums?.Count ?? 0) == 0)
{
albums = await _factory.Albums.ListAsync(x => x.ArtistId == artist.Id);
}

// Count the albums and tracks
artist.AlbumCount = albums.Count;
artist.AlbumCount = albums!.Count;
artist.TrackCount = (albums.Count > 0) ? albums.Sum(x => x.Tracks.Count) : 0;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/MusicCatalogue.Logic/MusicCatalogue.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>MusicCatalogue.Logic</PackageId>
<PackageVersion>1.8.0.0</PackageVersion>
<PackageVersion>1.9.0.0</PackageVersion>
<Authors>Dave Walker</Authors>
<Copyright>Copyright (c) Dave Walker 2023</Copyright>
<Owners>Dave Walker</Owners>
Expand All @@ -17,7 +17,7 @@
<PackageProjectUrl>https://github.com/davewalker5/MusicCatalogue</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<ReleaseVersion>1.8.0.0</ReleaseVersion>
<ReleaseVersion>1.9.0.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ReleaseVersion>1.8.0.0</ReleaseVersion>
<FileVersion>1.8.0.0</FileVersion>
<ProductVersion>1.8.0</ProductVersion>
<ReleaseVersion>1.9.0.0</ReleaseVersion>
<FileVersion>1.9.0.0</FileVersion>
<ProductVersion>1.9.0</ProductVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion src/MusicCatalogue.Tests/StatisticsManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void ArtistStatisticsTest()
Assert.IsNull(artists[0].AlbumCount);
Assert.IsNull(artists[0].TrackCount);

Task.Run(() => _factory!.Statistics.PopulateArtistStatistics(artists)).Wait();
Task.Run(() => _factory!.Statistics.PopulateArtistStatistics(artists, false)).Wait();
Assert.AreEqual(1, artists[0].AlbumCount);
Assert.AreEqual(1, artists[0].TrackCount);
}
Expand Down

0 comments on commit 1813977

Please sign in to comment.