mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-06-05 22:35:17 -04:00
Progress Overhaul + Profile Page and a LOT more! (#4262)
Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com> Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
This commit is contained in:
@@ -2,17 +2,20 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using API.Constants;
|
||||
using API.Data;
|
||||
using API.Data.Repositories;
|
||||
using API.DTOs.Statistics;
|
||||
using API.DTOs.Stats.V3;
|
||||
using API.DTOs.Stats.V3.ClientDevice;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Extensions;
|
||||
using API.Helpers;
|
||||
using API.Middleware;
|
||||
using API.Services;
|
||||
using API.Services.Plus;
|
||||
using API.Services.Tasks.Scanner.Parser;
|
||||
using CsvHelper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -24,76 +27,63 @@ namespace API.Controllers;
|
||||
|
||||
#nullable enable
|
||||
|
||||
public class StatsController : BaseApiController
|
||||
public class StatsController(
|
||||
IStatisticService statService,
|
||||
IUnitOfWork unitOfWork,
|
||||
UserManager<AppUser> userManager,
|
||||
ILocalizationService localizationService,
|
||||
IDirectoryService directoryService)
|
||||
: BaseApiController
|
||||
{
|
||||
private readonly IStatisticService _statService;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly UserManager<AppUser> _userManager;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly ILicenseService _licenseService;
|
||||
private readonly IDirectoryService _directoryService;
|
||||
|
||||
public StatsController(IStatisticService statService, IUnitOfWork unitOfWork,
|
||||
UserManager<AppUser> userManager, ILocalizationService localizationService,
|
||||
ILicenseService licenseService, IDirectoryService directoryService)
|
||||
{
|
||||
_statService = statService;
|
||||
_unitOfWork = unitOfWork;
|
||||
_userManager = userManager;
|
||||
_localizationService = localizationService;
|
||||
_licenseService = licenseService;
|
||||
_directoryService = directoryService;
|
||||
}
|
||||
|
||||
[HttpGet("user/{userId}/read")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<UserReadStatistics>> GetUserReadStatistics(int userId)
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
if (user!.Id != userId && !await _userManager.IsInRoleAsync(user, PolicyConstants.AdminRole))
|
||||
return Unauthorized(await _localizationService.Translate(User.GetUserId(), "stats-permission-denied"));
|
||||
var user = await unitOfWork.UserRepository.GetUserByUsernameAsync(Username!);
|
||||
if (user!.Id != userId && !await userManager.IsInRoleAsync(user, PolicyConstants.AdminRole))
|
||||
return Unauthorized(await localizationService.Translate(UserId, "stats-permission-denied"));
|
||||
|
||||
return Ok(await _statService.GetUserReadStatistics(userId, new List<int>()));
|
||||
return Ok(await statService.GetUserReadStatistics(userId, new List<int>()));
|
||||
}
|
||||
|
||||
[Authorize("RequireAdminRole")]
|
||||
[Authorize(PolicyGroups.AdminPolicy)]
|
||||
[HttpGet("server/stats")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<ServerStatisticsDto>> GetHighLevelStats()
|
||||
{
|
||||
return Ok(await _statService.GetServerStatistics());
|
||||
return Ok(await statService.GetServerStatistics());
|
||||
}
|
||||
|
||||
[Authorize("RequireAdminRole")]
|
||||
[Authorize(PolicyGroups.AdminPolicy)]
|
||||
[HttpGet("server/count/year")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<IEnumerable<StatCount<int>>>> GetYearStatistics()
|
||||
{
|
||||
return Ok(await _statService.GetYearCount());
|
||||
return Ok(await statService.GetYearCount());
|
||||
}
|
||||
|
||||
[Authorize("RequireAdminRole")]
|
||||
[Authorize(PolicyGroups.AdminPolicy)]
|
||||
[HttpGet("server/count/publication-status")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<IEnumerable<StatCount<PublicationStatus>>>> GetPublicationStatus()
|
||||
{
|
||||
return Ok(await _statService.GetPublicationCount());
|
||||
return Ok(await statService.GetPublicationCount());
|
||||
}
|
||||
|
||||
[Authorize("RequireAdminRole")]
|
||||
[Authorize(PolicyGroups.AdminPolicy)]
|
||||
[HttpGet("server/count/manga-format")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<IEnumerable<StatCount<MangaFormat>>>> GetMangaFormat()
|
||||
{
|
||||
return Ok(await _statService.GetMangaFormatCount());
|
||||
return Ok(await statService.GetMangaFormatCount());
|
||||
}
|
||||
|
||||
[Authorize("RequireAdminRole")]
|
||||
[Authorize(PolicyGroups.AdminPolicy)]
|
||||
[HttpGet("server/top/years")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<IEnumerable<StatCount<int>>>> GetTopYears()
|
||||
{
|
||||
return Ok(await _statService.GetTopYears());
|
||||
return Ok(await statService.GetTopYears());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -101,45 +91,45 @@ public class StatsController : BaseApiController
|
||||
/// </summary>
|
||||
/// <param name="days"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize("RequireAdminRole")]
|
||||
[Authorize(PolicyGroups.AdminPolicy)]
|
||||
[HttpGet("server/top/users")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<IEnumerable<TopReadDto>>> GetTopReads(int days = 0)
|
||||
{
|
||||
return Ok(await _statService.GetTopUsers(days));
|
||||
return Ok(await statService.GetTopUsers(days));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A breakdown of different files, their size, and format
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize("RequireAdminRole")]
|
||||
[Authorize(PolicyGroups.AdminPolicy)]
|
||||
[HttpGet("server/file-breakdown")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<IEnumerable<FileExtensionBreakdownDto>>> GetFileSize()
|
||||
{
|
||||
return Ok(await _statService.GetFileBreakdown());
|
||||
return Ok(await statService.GetFileBreakdown());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a csv of all file paths for a given extension
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize("RequireAdminRole")]
|
||||
[Authorize(PolicyGroups.AdminPolicy)]
|
||||
[HttpGet("server/file-extension")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult> DownloadFilesByExtension(string fileExtension)
|
||||
{
|
||||
if (!Regex.IsMatch(fileExtension, Parser.SupportedExtensions))
|
||||
{
|
||||
return BadRequest("Invalid file format");
|
||||
}
|
||||
var tempFile = Path.Join(_directoryService.TempDirectory,
|
||||
var tempFile = Path.Join(directoryService.TempDirectory,
|
||||
$"file_breakdown_{fileExtension.Replace(".", string.Empty)}.csv");
|
||||
|
||||
if (!_directoryService.FileSystem.File.Exists(tempFile))
|
||||
if (!directoryService.FileSystem.File.Exists(tempFile))
|
||||
{
|
||||
var results = await _statService.GetFilesByExtension(fileExtension);
|
||||
var results = await statService.GetFilesByExtension(fileExtension);
|
||||
await using var writer = new StreamWriter(tempFile);
|
||||
await using var csv = new CsvWriter(writer, CultureInfo.InvariantCulture);
|
||||
await csv.WriteRecordsAsync(results);
|
||||
@@ -157,41 +147,41 @@ public class StatsController : BaseApiController
|
||||
/// <param name="days">If 0, defaults to all time, else just those days asked for</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("reading-count-by-day")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<IEnumerable<PagesReadOnADayCount<DateTime>>>> ReadCountByDay(int userId = 0, int days = 0)
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
var user = await unitOfWork.UserRepository.GetUserByUsernameAsync(Username!);
|
||||
var isAdmin = User.IsInRole(PolicyConstants.AdminRole);
|
||||
if (!isAdmin && userId != user!.Id) return BadRequest();
|
||||
|
||||
return Ok(await _statService.ReadCountByDay(userId, days));
|
||||
return Ok(await statService.ReadCountByDay(userId, days));
|
||||
}
|
||||
|
||||
[HttpGet("day-breakdown")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<IEnumerable<StatCount<DayOfWeek>>>> GetDayBreakdown(int userId = 0)
|
||||
{
|
||||
if (userId == 0)
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
var isAdmin = await _unitOfWork.UserRepository.IsUserAdminAsync(user);
|
||||
var user = await unitOfWork.UserRepository.GetUserByUsernameAsync(Username!);
|
||||
var isAdmin = await unitOfWork.UserRepository.IsUserAdminAsync(user);
|
||||
if (!isAdmin) return BadRequest();
|
||||
}
|
||||
|
||||
return Ok(_statService.GetDayBreakdown(userId));
|
||||
return Ok(statService.GetDayBreakdown(userId));
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpGet("user/reading-history")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<IEnumerable<ReadHistoryEvent>>> GetReadingHistory(int userId)
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
var user = await unitOfWork.UserRepository.GetUserByUsernameAsync(Username!);
|
||||
var isAdmin = User.IsInRole(PolicyConstants.AdminRole);
|
||||
if (!isAdmin && userId != user!.Id) return BadRequest();
|
||||
|
||||
return Ok(await _statService.GetReadingHistory(userId));
|
||||
return Ok(await statService.GetReadingHistory(userId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -200,12 +190,12 @@ public class StatsController : BaseApiController
|
||||
/// <param name="userId">If userId is 0 and user is not an admin, API will default to userId</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("pages-per-year")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<IEnumerable<StatCount<int>>>> GetPagesReadPerYear(int userId = 0)
|
||||
{
|
||||
var isAdmin = User.IsInRole(PolicyConstants.AdminRole);
|
||||
if (!isAdmin) userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
|
||||
return Ok(_statService.GetPagesReadCountByYear(userId));
|
||||
if (!isAdmin) userId = await unitOfWork.UserRepository.GetUserIdByUsernameAsync(Username!);
|
||||
return Ok(statService.GetPagesReadCountByYear(userId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -214,12 +204,220 @@ public class StatsController : BaseApiController
|
||||
/// <param name="userId">If userId is 0 and user is not an admin, API will default to userId</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("words-per-year")]
|
||||
[ResponseCache(CacheProfileName = "Statistics")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<IEnumerable<StatCount<int>>>> GetWordsReadPerYear(int userId = 0)
|
||||
{
|
||||
var isAdmin = User.IsInRole(PolicyConstants.AdminRole);
|
||||
if (!isAdmin) userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
|
||||
return Ok(_statService.GetWordsReadCountByYear(userId));
|
||||
if (!isAdmin) userId = await unitOfWork.UserRepository.GetUserIdByUsernameAsync(Username!);
|
||||
return Ok(statService.GetWordsReadCountByYear(userId));
|
||||
}
|
||||
|
||||
#region Device Insights
|
||||
|
||||
/// <summary>
|
||||
/// Returns client type breakdown for the current month
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("device/client-type")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
[Authorize(PolicyGroups.AdminPolicy)]
|
||||
public async Task<ActionResult<DeviceClientBreakdownDto>> GetClientTypeBreakdown()
|
||||
{
|
||||
return Ok(await statService.GetClientTypeBreakdown(DateTime.UtcNow.StartOfMonth()));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Desktop vs Mobile spread over last month
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("device/device-type")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
[Authorize(PolicyGroups.AdminPolicy)]
|
||||
public async Task<ActionResult<StatCount<string>>> GetDeviceTypeCounts()
|
||||
{
|
||||
// Mobile vs Desktop Ratio - Overall usage pattern
|
||||
return Ok(await statService.GetDeviceTypeCounts(DateTime.UtcNow.StartOfMonth()));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Reading History
|
||||
|
||||
[HttpGet("reading-activity")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<ReadingActivityGraphDto>> GetReadingActivity([FromQuery] StatsFilterDto filter, int userId, int year)
|
||||
{
|
||||
await CleanStatsFilter(filter, UserId);
|
||||
|
||||
return Ok(await statService.GetReadingActivityGraphData(filter, userId, year, UserId));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Profile Stats
|
||||
|
||||
|
||||
[ProfilePrivacy]
|
||||
[HttpGet("reading-pace")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<ReadingPaceDto>> GetReadingPace([FromQuery] StatsFilterDto filter, int userId, int year)
|
||||
{
|
||||
await CleanStatsFilter(filter, UserId);
|
||||
|
||||
return Ok(await statService.GetReadingPaceForUser(filter, userId, year));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns each format type read
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[ProfilePrivacy]
|
||||
[HttpGet("preferred-format")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<IList<StatCount<MangaFormat>>>> GetPreferredMangaFormat([FromQuery] StatsFilterDto filter, int userId)
|
||||
{
|
||||
await CleanStatsFilter(filter, UserId);
|
||||
|
||||
return Ok(await statService.GetPreferredFormatForUser(filter, userId, UserId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns top 10 genres that user likes reading
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[ProfilePrivacy]
|
||||
[HttpGet("genre-breakdown")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<BreakDownDto<string>>> GetGenreBreakdown([FromQuery] StatsFilterDto filter, int userId)
|
||||
{
|
||||
await CleanStatsFilter(filter, UserId);
|
||||
|
||||
return Ok(await statService.GetGenreBreakdownForUser(filter, userId, UserId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns top 10 tags that user likes reading
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[ProfilePrivacy]
|
||||
[HttpGet("tag-breakdown")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<BreakDownDto<string>>> GetTagBreakdown([FromQuery] StatsFilterDto filter, int userId)
|
||||
{
|
||||
await CleanStatsFilter(filter, UserId);
|
||||
|
||||
return Ok(await statService.GetTagBreakdownForUser(filter, userId, UserId));
|
||||
}
|
||||
|
||||
|
||||
[ProfilePrivacy]
|
||||
[HttpGet("page-spread")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<SpreadStatsDto>> GetPageSpread([FromQuery] StatsFilterDto filter, int userId)
|
||||
{
|
||||
await CleanStatsFilter(filter, UserId);
|
||||
|
||||
return Ok(await statService.GetPageSpreadForUser(filter, userId, UserId));
|
||||
}
|
||||
|
||||
[ProfilePrivacy]
|
||||
[HttpGet("word-spread")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<SpreadStatsDto>> GetWordSpread([FromQuery] StatsFilterDto filter, int userId)
|
||||
{
|
||||
await CleanStatsFilter(filter, UserId);
|
||||
|
||||
return Ok(await statService.GetWordSpreadForUser(filter, userId, UserId));
|
||||
}
|
||||
|
||||
[ProfilePrivacy]
|
||||
[HttpGet("favorite-authors")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<MostReadAuthorsDto>> GetMostReadAuthors([FromQuery] StatsFilterDto filter, int userId)
|
||||
{
|
||||
await CleanStatsFilter(filter, UserId);
|
||||
|
||||
return Ok(await statService.GetMostReadAuthors(filter, userId, UserId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the avg time read by hour in the given filter
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[ProfilePrivacy]
|
||||
[HttpGet("avg-time-by-hour")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<ReadTimeByHourDto>> GetAverageTimePerHour([FromQuery] StatsFilterDto filter, int userId)
|
||||
{
|
||||
await CleanStatsFilter(filter, UserId);
|
||||
|
||||
var dto = await statService.GetTimeReadingByHour(filter, userId, UserId);
|
||||
if (dto == null) return BadRequest();
|
||||
|
||||
return Ok(dto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives the total amount of chapters reads per month, filters start & end date will not apply
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[ProfilePrivacy]
|
||||
[HttpGet("reads-by-month")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<IList<StatCount<YearMonthGroupingDto>>>> GetReadsPerMonth([FromQuery] StatsFilterDto filter, int userId)
|
||||
{
|
||||
await CleanStatsFilter(filter, UserId);
|
||||
|
||||
return Ok(await statService.GetReadsPerMonth(filter, userId, UserId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the total amount reads in the given filter
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[ProfilePrivacy]
|
||||
[HttpGet("total-reads")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<int>> GetTotalReads(int userId)
|
||||
{
|
||||
return Ok(await statService.GetTotalReads(userId, UserId));
|
||||
}
|
||||
|
||||
[ProfilePrivacy]
|
||||
[HttpGet("user-stats")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Statistics)]
|
||||
public async Task<ActionResult<ProfileStatBarDto>> GetStatsForUserBar([FromQuery] StatsFilterDto filter, int userId)
|
||||
{
|
||||
await CleanStatsFilter(filter, userId);
|
||||
return Ok(await statService.GetUserStatBar(filter, userId, UserId));
|
||||
}
|
||||
|
||||
// TODO: Can we cache this? Can we make an attribute to cache methods based on keys?
|
||||
/// <summary>
|
||||
/// Cleans the stats filter to only include valid data. I.e. only requests libraries the user has access to
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
private async Task CleanStatsFilter(StatsFilterDto filter, int userId)
|
||||
{
|
||||
var libraries = await unitOfWork.LibraryRepository.GetLibraryIdsForUserIdAsync(userId);
|
||||
|
||||
filter.Libraries = filter.Libraries.Intersect(libraries).ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user