mirror of
https://github.com/D4M13N-D3V/comissions-app-core-api.git
synced 2025-03-14 10:04:55 +00:00
fix: sellers now returns statistics and in a administration api model instead of the db entity.
This commit is contained in:
parent
a4a7af32a7
commit
83373f7dd0
@ -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<IActionResult> 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<IActionResult> 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);
|
||||
}
|
||||
|
||||
|
49
src/comissions.app.api/Models/Admin/AdminArtistModel.cs
Normal file
49
src/comissions.app.api/Models/Admin/AdminArtistModel.cs
Normal file
@ -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
|
||||
};
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user