62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
using DysonNetwork.Shared.Models;
|
|
using DysonNetwork.Shared.Services;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace DysonNetwork.Pass.Safety;
|
|
|
|
public class SafetyService(AppDatabase db, IAccountService accountService, ILogger<SafetyService> logger)
|
|
{
|
|
public async Task<AbuseReport> CreateReport(string resourceIdentifier, AbuseReportType type, string reason, Guid accountId)
|
|
{
|
|
// Check if a similar report already exists from this user
|
|
var existingReport = await db.AbuseReports
|
|
.Where(r => r.ResourceIdentifier == resourceIdentifier &&
|
|
r.AccountId == accountId &&
|
|
r.DeletedAt == null)
|
|
.FirstOrDefaultAsync();
|
|
|
|
if (existingReport != null)
|
|
{
|
|
throw new InvalidOperationException("You have already reported this content.");
|
|
}
|
|
|
|
return await accountService.CreateAbuseReport(resourceIdentifier, type, reason, accountId);
|
|
}
|
|
|
|
public async Task<int> CountReports(bool includeResolved = false)
|
|
{
|
|
return await accountService.CountAbuseReports(includeResolved);
|
|
}
|
|
|
|
public async Task<int> CountUserReports(Guid accountId, bool includeResolved = false)
|
|
{
|
|
return await accountService.CountUserAbuseReports(accountId, includeResolved);
|
|
}
|
|
|
|
public async Task<List<AbuseReport>> GetReports(int skip = 0, int take = 20, bool includeResolved = false)
|
|
{
|
|
return await accountService.GetAbuseReports(skip, take, includeResolved);
|
|
}
|
|
|
|
public async Task<List<AbuseReport>> GetUserReports(Guid accountId, int skip = 0, int take = 20, bool includeResolved = false)
|
|
{
|
|
return await accountService.GetUserAbuseReports(accountId, skip, take, includeResolved);
|
|
}
|
|
|
|
public async Task<AbuseReport?> GetReportById(Guid id)
|
|
{
|
|
return await accountService.GetAbuseReport(id);
|
|
}
|
|
|
|
public async Task<AbuseReport> ResolveReport(Guid id, string resolution)
|
|
{
|
|
return await accountService.ResolveAbuseReport(id, resolution);
|
|
}
|
|
|
|
public async Task<int> GetPendingReportsCount()
|
|
{
|
|
return await accountService.GetPendingAbuseReportsCount();
|
|
}
|
|
}
|