Temp commit to record attempts. Stream APIs are implemented and working. Added some new test cases based on deployed Kavita server testing.
This commit is contained in:
parent
55cd0c5fe5
commit
0a85555f38
16 changed files with 247 additions and 90 deletions
|
|
@ -280,87 +280,52 @@ namespace API.Data
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of Series that were added within 2 weeks.
|
||||
/// Returns a list of Series that were added, ordered by Created desc
|
||||
/// </summary>
|
||||
/// <param name="libraryId">Library to restrict to, if 0, will apply to all libraries</param>
|
||||
/// <param name="limit"></param>
|
||||
/// <param name="limit">How many series to pick.</param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<SeriesDto>> GetRecentlyAdded(int libraryId, int limit)
|
||||
{
|
||||
// TODO: Remove 2 week condition
|
||||
var twoWeeksAgo = DateTime.Today.Subtract(TimeSpan.FromDays(14));
|
||||
_logger.LogDebug("2 weeks from today is: {Date}", twoWeeksAgo);
|
||||
return await _context.Series
|
||||
.Where(s => s.Created > twoWeeksAgo && (libraryId <= 0 || s.LibraryId == libraryId))
|
||||
.Where(s => (libraryId <= 0 || s.LibraryId == libraryId))
|
||||
.Take(limit)
|
||||
.OrderBy(s => s.Created)
|
||||
.OrderByDescending(s => s.Created)
|
||||
.AsNoTracking()
|
||||
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="libraryId"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<SeriesDto>> GetInProgress(int userId, int libraryId, int limit)
|
||||
{
|
||||
//&& (libraryId <= 0 || s.Series.LibraryId == libraryId)
|
||||
var twoWeeksAgo = DateTime.Today.Subtract(TimeSpan.FromDays(14));
|
||||
_logger.LogInformation("GetInProgress");
|
||||
_logger.LogDebug("2 weeks from today is: {Date}", twoWeeksAgo);
|
||||
// var series = await _context.Series
|
||||
// .Join(_context.AppUserProgresses, s => s.Id, progress => progress.SeriesId, (s, progress) => new
|
||||
// {
|
||||
// Series = s,
|
||||
// Progress = progress
|
||||
// })
|
||||
// .DefaultIfEmpty()
|
||||
// .Where(s => s.Series.Created > twoWeeksAgo
|
||||
// && s.Progress.AppUserId == userId
|
||||
// && s.Progress.PagesRead > s.Series.Pages)
|
||||
// .Take(limit)
|
||||
// .OrderBy(s => s.Series.Created)
|
||||
// .AsNoTracking()
|
||||
// .Select(s => s.Series)
|
||||
// .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
|
||||
// .ToListAsync();
|
||||
//var twoWeeksAgo = DateTime.Today.Subtract(TimeSpan.FromDays(14)); // TODO: Think about moving this to a setting
|
||||
var series = await _context.Series
|
||||
.Where(s => s.Created > twoWeeksAgo) // && (libraryId <= 0 || s.LibraryId == libraryId)
|
||||
.AsNoTracking()
|
||||
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
|
||||
await AddSeriesModifiers(userId, series);
|
||||
|
||||
return series.Where(s => s.PagesRead > 0).Take(limit).ToList();
|
||||
}
|
||||
|
||||
|
||||
public async Task<IEnumerable<SeriesDto>> GetSeriesStream(int userId)
|
||||
{
|
||||
// Testing out In Progress to figure out how to design generalized solution
|
||||
var userProgress = await _context.AppUserProgresses
|
||||
.Where(p => p.AppUserId == userId && p.PagesRead > 0)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
if (!userProgress.Any()) return new SeriesDto[] {};
|
||||
|
||||
var seriesIds = userProgress.Select(p => p.SeriesId).ToList();
|
||||
/*
|
||||
*select P.*, S.Name, S.Pages from AppUserProgresses AS P
|
||||
LEFT join Series as "S" on s.Id = P.SeriesId
|
||||
where AppUserId = 1 AND P.PagesRead > 0 AND P.PagesRead < S.Pages
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
// var series = await _context.Series
|
||||
// .Where(s => seriesIds.Contains(s.Id) && s.Pages) // I need a join
|
||||
|
||||
|
||||
|
||||
|
||||
return new SeriesDto[] {};
|
||||
.Join(_context.AppUserProgresses, s => s.Id, progress => progress.SeriesId, (s, progress) => new
|
||||
{
|
||||
Series = s,
|
||||
progress.PagesRead,
|
||||
progress.AppUserId,
|
||||
progress.LastModified
|
||||
})
|
||||
.Where(s => s.AppUserId == userId
|
||||
&& s.PagesRead > 0
|
||||
&& s.PagesRead < s.Series.Pages
|
||||
&& (libraryId <= 0 || s.Series.LibraryId == libraryId) )
|
||||
.Take(limit)
|
||||
.OrderByDescending(s => s.LastModified)
|
||||
.AsNoTracking()
|
||||
.Select(s => s.Series)
|
||||
.Distinct()
|
||||
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
return series;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,21 +12,21 @@ namespace API.Data
|
|||
private readonly DataContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly UserManager<AppUser> _userManager;
|
||||
private readonly ILogger<UnitOfWork> _seriesLogger;
|
||||
private readonly ILogger<UnitOfWork> _logger;
|
||||
|
||||
public UnitOfWork(DataContext context, IMapper mapper, UserManager<AppUser> userManager, ILogger<UnitOfWork> seriesLogger)
|
||||
public UnitOfWork(DataContext context, IMapper mapper, UserManager<AppUser> userManager, ILogger<UnitOfWork> logger)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
_userManager = userManager;
|
||||
_seriesLogger = seriesLogger;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public ISeriesRepository SeriesRepository => new SeriesRepository(_context, _mapper, _seriesLogger);
|
||||
public ISeriesRepository SeriesRepository => new SeriesRepository(_context, _mapper, _logger);
|
||||
public IUserRepository UserRepository => new UserRepository(_context, _userManager);
|
||||
public ILibraryRepository LibraryRepository => new LibraryRepository(_context, _mapper);
|
||||
|
||||
public IVolumeRepository VolumeRepository => new VolumeRepository(_context, _mapper);
|
||||
public IVolumeRepository VolumeRepository => new VolumeRepository(_context, _mapper, _logger);
|
||||
|
||||
public ISettingsRepository SettingsRepository => new SettingsRepository(_context, _mapper);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Comparators;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
using API.Extensions;
|
||||
using API.Interfaces;
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace API.Data
|
||||
{
|
||||
|
|
@ -14,11 +17,13 @@ namespace API.Data
|
|||
{
|
||||
private readonly DataContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public VolumeRepository(DataContext context, IMapper mapper)
|
||||
public VolumeRepository(DataContext context, IMapper mapper, ILogger logger)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Update(Volume volume)
|
||||
|
|
@ -84,5 +89,95 @@ namespace API.Data
|
|||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the first (ordered) volume/chapter in a series where the user has progress on it. Only completed volumes/chapters, next entity shouldn't
|
||||
/// have any read progress on it.
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="libraryId"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<InProgressChapterDto>> GetContinueReading(int userId, int libraryId, int limit)
|
||||
{
|
||||
_logger.LogInformation("Get Continue Reading");
|
||||
var progress = await _context.Chapter
|
||||
.Join(_context.AppUserProgresses, chapter => chapter.Id, progress => progress.ChapterId,
|
||||
(chapter, progress) =>
|
||||
new
|
||||
{
|
||||
Chapter = chapter,
|
||||
Progress = progress
|
||||
})
|
||||
.Join(_context.Series, arg => arg.Progress.SeriesId, series => series.Id, (arg, series) =>
|
||||
new
|
||||
{
|
||||
arg.Chapter,
|
||||
arg.Progress,
|
||||
Series = series
|
||||
})
|
||||
.AsNoTracking()
|
||||
.Where(arg => arg.Progress.AppUserId == userId
|
||||
&& arg.Progress.PagesRead < arg.Chapter.Pages)
|
||||
.OrderByDescending(d => d.Progress.LastModified)
|
||||
.Take(limit)
|
||||
.ToListAsync();
|
||||
|
||||
return progress
|
||||
.OrderBy(c => float.Parse(c.Chapter.Number), new ChapterSortComparer())
|
||||
.DistinctBy(p => p.Series.Id)
|
||||
.Select(arg => new InProgressChapterDto()
|
||||
{
|
||||
Id = arg.Chapter.Id,
|
||||
Number = arg.Chapter.Number,
|
||||
Range = arg.Chapter.Range,
|
||||
SeriesId = arg.Progress.SeriesId,
|
||||
SeriesName = arg.Series.Name,
|
||||
LibraryId = arg.Series.LibraryId,
|
||||
Pages = arg.Chapter.Pages,
|
||||
});
|
||||
|
||||
// var chapters = await _context.Chapter
|
||||
// .Join(_context.AppUserProgresses, chapter => chapter.Id, progress => progress.ChapterId, (chapter, progress) =>
|
||||
// new
|
||||
// {
|
||||
// Chapter = chapter,
|
||||
// Progress = progress
|
||||
// })
|
||||
// .Where(arg => arg.Progress.AppUserId == userId && arg.Progress.PagesRead < arg.Chapter.Pages)
|
||||
// .Join(_context.Series, arg => arg.Progress.SeriesId, series => series.Id, (arg, series) =>
|
||||
// new
|
||||
// {
|
||||
// arg.Chapter,
|
||||
// arg.Progress,
|
||||
// Series = series
|
||||
// })
|
||||
// .AsNoTracking()
|
||||
// //.OrderBy(s => s.Chapter.Number)
|
||||
// .GroupBy(p => p.Series.Id)
|
||||
// .Select(g => g.FirstOrDefault())
|
||||
// .Select(arg => new InProgressChapterDto()
|
||||
// {
|
||||
// Id = arg.Chapter.Id,
|
||||
// Number = arg.Chapter.Number,
|
||||
// Range = arg.Chapter.Range,
|
||||
// SeriesId = arg.Progress.SeriesId,
|
||||
// SeriesName = arg.Series.Name,
|
||||
// LibraryId = arg.Series.LibraryId,
|
||||
// Pages = arg.Chapter.Pages,
|
||||
// })
|
||||
//
|
||||
// //.OrderBy(c => float.Parse(c.Number)) //can't convert to SQL
|
||||
//
|
||||
// .ToListAsync();
|
||||
//
|
||||
//
|
||||
// return chapters;
|
||||
|
||||
|
||||
// return chapters
|
||||
// .OrderBy(c => float.Parse(c.Number), new ChapterSortComparer())
|
||||
// .DistinctBy(c => c.SeriesName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue