Kavita/API/Data/Repositories/UserTableOfContentRepository.cs
Joe Milazzo a0a6da9c60
Personal Table of Contents (#2148)
* Fixed a bad default setting for token key

* Changed the payment link to support Google Pay

* Fixed duplicate events occurring on newly added series from a scan.

Fixed the version update code from not firing and made it check every 4-6 hours (random per user per restart)

* Check for new releases on startup as well.

Added Personal Table of Contents (called Bookmarks on epub and pdf reader). The idea is that sometimes you want to bookmark certain parts of pages to get back to quickly later. This mechanism will allow you to do that without having to edit the underlying ToC.

* Added a button to update modal to show how to update for those unaware.

* Darkened the link text within tables to be more visible.

* Update link for how to update now is dynamic for docker users

* Refactored to send proper star/end dates for scrobble read events for upcoming changes in the API.

Added GoogleBooks Rating UI code if I go forward with API changes.

* When Scrobbling, send when the first and last progress for the series was.

Added OpenLibrary icon for upcoming enhancements for Kavita+.

Changed the Update checker to execute at start.

* Fixed backups not saving favicons in the correct place

* Refactored the layout code for Personal ToC

* More bugfixes around toc

* Box alignment

* Fixed up closing the overlay when bookmark mode is active

* Fixed up closing the overlay when bookmark mode is active

---------

Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
2023-07-21 15:29:35 -07:00

65 lines
2.1 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using API.DTOs.Reader;
using API.Entities;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using Microsoft.EntityFrameworkCore;
namespace API.Data.Repositories;
#nullable enable
public interface IUserTableOfContentRepository
{
void Attach(AppUserTableOfContent toc);
void Remove(AppUserTableOfContent toc);
Task<bool> IsUnique(int userId, int chapterId, int page, string title);
IEnumerable<PersonalToCDto> GetPersonalToC(int userId, int chapterId);
Task<AppUserTableOfContent?> Get(int userId, int chapterId, int pageNum, string title);
}
public class UserTableOfContentRepository : IUserTableOfContentRepository
{
private readonly DataContext _context;
private readonly IMapper _mapper;
public UserTableOfContentRepository(DataContext context, IMapper mapper)
{
_context = context;
_mapper = mapper;
}
public void Attach(AppUserTableOfContent toc)
{
_context.AppUserTableOfContent.Attach(toc);
}
public void Remove(AppUserTableOfContent toc)
{
_context.AppUserTableOfContent.Remove(toc);
}
public async Task<bool> IsUnique(int userId, int chapterId, int page, string title)
{
return await _context.AppUserTableOfContent.AnyAsync(t =>
t.AppUserId == userId && t.PageNumber == page && t.Title == title && t.ChapterId == chapterId);
}
public IEnumerable<PersonalToCDto> GetPersonalToC(int userId, int chapterId)
{
return _context.AppUserTableOfContent
.Where(t => t.AppUserId == userId && t.ChapterId == chapterId)
.ProjectTo<PersonalToCDto>(_mapper.ConfigurationProvider)
.OrderBy(t => t.PageNumber)
.AsEnumerable();
}
public async Task<AppUserTableOfContent?> Get(int userId,int chapterId, int pageNum, string title)
{
return await _context.AppUserTableOfContent
.Where(t => t.AppUserId == userId && t.ChapterId == chapterId && t.PageNumber == pageNum && t.Title == title)
.FirstOrDefaultAsync();
}
}