fix: added endpoints to discovery controller for users to see w hypeople have been banned or suspended

This commit is contained in:
Damien Ostler 2024-03-09 22:36:59 -05:00
parent a3f137cb12
commit 40653eff04
2 changed files with 62 additions and 0 deletions

View File

@ -3,6 +3,7 @@ using comissions.app.api.Models.PortfolioModel;
using comissions.app.api.Services.Storage;
using comissions.app.database;
using comissions.app.database.Entities;
using comissions.app.database.Models;
using comissions.app.database.Models.Request;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@ -47,6 +48,34 @@ public class DiscoveryController : Controller
return Ok(result);
}
[HttpGet]
[Route("Artists/{sellerId:int}/Bans")]
public async Task<IActionResult> GetArtistBans(int sellerId)
{
var seller = await _dbContext.UserArtists
.Include(x=>x.User).ThenInclude(x=>x.Requests)
.Include(x=>x.User).ThenInclude(x=>x.Bans)
.FirstOrDefaultAsync(x=>x.Id==sellerId);
if(seller==null)
return NotFound();
var result = seller.User.Bans.Select(x=>x.ToModel()).ToList();
return Ok(result);
}
[HttpGet]
[Route("Artists/{sellerId:int}/Suspensions")]
public async Task<IActionResult> GetArtistSuspensions(int sellerId)
{
var seller = await _dbContext.UserArtists
.Include(x=>x.User).ThenInclude(x=>x.Suspensions)
.Include(x=>x.User).ThenInclude(x=>x.Bans)
.FirstOrDefaultAsync(x=>x.Id==sellerId);
if(seller==null)
return NotFound();
var result = seller.User.Suspensions.Select(x=>x.ToModel()).ToList();
return Ok(result);
}
[HttpGet]
[Route("Artists/{sellerName}")]

View File

@ -0,0 +1,33 @@
using comissions.app.database.Entities;
namespace comissions.app.database.Models;
public class PenaltyModel
{
public DateTime Date { get; set; }
public string Reason { get; set; }
public string Admin { get; set; }
}
public static class PenaltyModelExtensions
{
public static PenaltyModel ToModel(this Ban ban)
{
return new PenaltyModel()
{
Date = ban.BanDate,
Reason = ban.Reason,
Admin = ban.Admin.DisplayName
};
}
public static PenaltyModel ToModel(this Suspension suspension)
{
return new PenaltyModel()
{
Date = suspension.SuspensionDate,
Reason = suspension.Reason,
Admin = suspension.Admin.DisplayName
};
}
}