From 83373f7dd0f0f63a7ce41439d2d3da99b4bf1f9f Mon Sep 17 00:00:00 2001 From: Damien Ostler Date: Sun, 17 Mar 2024 06:03:17 -0400 Subject: [PATCH] fix: sellers now returns statistics and in a administration api model instead of the db entity. --- ...ontroller.cs => AdminArtistsController.cs} | 14 ++++-- .../Models/Admin/AdminArtistModel.cs | 49 +++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) rename src/comissions.app.api/Controllers/Admin/{AdminSellersController.cs => AdminArtistsController.cs} (82%) create mode 100644 src/comissions.app.api/Models/Admin/AdminArtistModel.cs diff --git a/src/comissions.app.api/Controllers/Admin/AdminSellersController.cs b/src/comissions.app.api/Controllers/Admin/AdminArtistsController.cs similarity index 82% rename from src/comissions.app.api/Controllers/Admin/AdminSellersController.cs rename to src/comissions.app.api/Controllers/Admin/AdminArtistsController.cs index 05ffefb..55351ab 100644 --- a/src/comissions.app.api/Controllers/Admin/AdminSellersController.cs +++ b/src/comissions.app.api/Controllers/Admin/AdminArtistsController.cs @@ -1,5 +1,6 @@ using comissions.app.api.Extensions; using comissions.app.database; +using comissions.app.database.Models.Admin; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; @@ -23,9 +24,13 @@ public class AdminArtistsController:ControllerBase public async Task GetArtists([FromQuery]string search="", [FromQuery]int offset = 0, [FromQuery]int pageSize = 10) { var sellers = await _dbContext.UserArtists.Include(x=>x.User) + .Include(x=>x.Requests) + .Include(x=>x.Requests).ThenInclude(x=>x.RequestAssets) + .Include(x=>x.PortfolioPieces) .Where(x=>x.User.DisplayName.Contains(search) || x.User.Email.Contains(search)) .Skip(offset).Take(pageSize).ToListAsync(); - return Ok(sellers); + var result = sellers.Select(x => x.ToAdminArtistModel()); + return Ok(result); } [HttpGet("Count")] @@ -41,12 +46,15 @@ public class AdminArtistsController:ControllerBase public async Task GetArtist(int sellerId) { var seller = await _dbContext.UserArtists.Include(x=>x.User) + .Include(x=>x.Requests) + .Include(x=>x.Requests).ThenInclude(x=>x.RequestAssets) + .Include(x=>x.PortfolioPieces) .FirstOrDefaultAsync(x=>x.Id==sellerId); if (seller == null) return NotFound(); - - return Ok(seller); + var result = seller.ToAdminArtistModel(); + return Ok(result); } diff --git a/src/comissions.app.api/Models/Admin/AdminArtistModel.cs b/src/comissions.app.api/Models/Admin/AdminArtistModel.cs new file mode 100644 index 0000000..093dd3a --- /dev/null +++ b/src/comissions.app.api/Models/Admin/AdminArtistModel.cs @@ -0,0 +1,49 @@ +using comissions.app.database.Entities; + +namespace comissions.app.database.Models.Admin; + +public class AdminArtistModel +{ + public int Id { get; set; } + public bool PrepaymentRequired { get; set; } + public string SocialMediaLink3 { get; set; } + public string SocialMediaLink2 { get; set; } + public string SocialMediaLink1 { get; set; } + public string Description { get; set; } + public string SocialMediaLink4 { get; set; } + public string RequestGuidelines { get; set; } + public string Name { get; set; } + public int NumberOfRequests { get; set; } + public int NumberOfReviews { get; set; } + public int NumberOfPaid { get; set; } + public decimal AmountMade { get; set; } + public decimal FeesCollected { get; set; } + public int NumberOfAssets { get; set; } + public int NumberOfPortfolio { get; set; } +} + +public static class AdminArtistModelExtensions +{ + public static AdminArtistModel ToAdminArtistModel(this UserArtist artist) + { + return new AdminArtistModel + { + Id = artist.Id, + PrepaymentRequired = artist.PrepaymentRequired, + SocialMediaLink3 = artist.SocialMediaLink3, + SocialMediaLink2 = artist.SocialMediaLink2, + SocialMediaLink1 = artist.SocialMediaLink1, + Description = artist.Description, + SocialMediaLink4 = artist.SocialMediaLink4, + RequestGuidelines = artist.RequestGuidelines, + Name = artist.Name, + NumberOfRequests = artist.Requests.Count, + NumberOfReviews = artist.Requests.Count(x => x.Reviewed), + NumberOfPaid = artist.Requests.Count(x => x.Paid), + AmountMade = artist.Requests.Sum(r => r.Amount), + FeesCollected = artist.Requests.Sum(r => r.Amount)*(decimal)0.15, + NumberOfAssets = artist.Requests.SelectMany(x=>x.RequestAssets).Count(), + NumberOfPortfolio = artist.PortfolioPieces.Count + }; + } +} \ No newline at end of file