Skip to content

Commit

Permalink
Implement the retailer statistics report
Browse files Browse the repository at this point in the history
  • Loading branch information
davewalker5 committed Nov 30, 2023
1 parent 426d005 commit 655a23a
Show file tree
Hide file tree
Showing 16 changed files with 554 additions and 14 deletions.
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.22.0.0 /opt/musiccatalogue.api-1.22.0.0
WORKDIR /opt/musiccatalogue.api-1.22.0.0/bin
COPY musiccatalogue.api-1.23.0.0 /opt/musiccatalogue.api-1.23.0.0
WORKDIR /opt/musiccatalogue.api-1.23.0.0/bin
ENTRYPOINT [ "./MusicCatalogue.Api" ]
23 changes: 23 additions & 0 deletions sql/Summarise By Retailer.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
WITH RETAILER_SPEND ( Id, Name, IsWishListItem, Spend ) AS
(
SELECT r.Id,
r.Name,
IFNULL( al.IsWishListItem, 0),
SUM( IFNULL( al.Price, 0 ) )
FROM ALBUMS al
LEFT OUTER JOIN RETAILERS r ON r.Id = al.RetailerId
GROUP BY r.Id, r.Name, IFNULL( al.IsWishListItem, 0)
)
SELECT RANK() OVER ( ORDER BY rsp.Name ASC ) AS "Id",
rsp.Name,
COUNT( DISTINCT a.Id ) AS "Artists",
COUNT( DISTINCT al.Id ) AS "Albums",
COUNT( DISTINCT t.Id ) AS "Tracks",
rsp.Spend
FROM RETAILER_SPEND rsp
INNER JOIN ALBUMS al ON al.RetailerId = rsp.Id
INNER JOIN TRACKS t ON t.AlbumId = al.Id
INNER JOIN ARTISTS a ON a.Id = al.ArtistId
WHERE rsp.IsWishListItem = 0
AND IFNULL( al.IsWishListItem, 0 ) = 0
GROUP BY rsp.Name;
21 changes: 21 additions & 0 deletions src/MusicCatalogue.Api/Controllers/ReportsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,26 @@ public async Task<ActionResult<List<MonthlySpend>>> GetMonthlySpendingReportAsyn
// Convert to a list and return the results
return results.ToList();
}

/// <summary>
/// Generate the retailer statistics report
/// </summary>
/// <param name="wishlist"></param>
/// <returns></returns>
[HttpGet]
[Route("retailers/{wishlist}")]
public async Task<ActionResult<List<RetailerStatistics>>> GetRetailerStatisticsReportAsync(bool wishlist)
{
// Get the report content
var results = await _factory.RetailerStatistics.GenerateReportAsync(wishlist, 1, int.MaxValue);

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

// Convert to a list and return the results
return results.ToList();
}
}
}
6 changes: 3 additions & 3 deletions src/MusicCatalogue.Api/MusicCatalogue.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ReleaseVersion>1.22.0.0</ReleaseVersion>
<FileVersion>1.22.0.0</FileVersion>
<ProductVersion>1.22.0</ProductVersion>
<ReleaseVersion>1.23.0.0</ReleaseVersion>
<FileVersion>1.23.0.0</FileVersion>
<ProductVersion>1.23.0</ProductVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
Loading

0 comments on commit 655a23a

Please sign in to comment.