Use JSON columns instead of junction tables
This commit is contained in:
parent
8fd50d030b
commit
b36f6c8f0b
35 changed files with 471 additions and 1103 deletions
|
|
@ -81,9 +81,7 @@ public sealed class DataContext : IdentityDbContext<AppUser, AppRole, int,
|
|||
public DbSet<MetadataSettings> MetadataSettings { get; set; } = null!;
|
||||
public DbSet<MetadataFieldMapping> MetadataFieldMapping { get; set; } = null!;
|
||||
public DbSet<AppUserChapterRating> AppUserChapterRating { get; set; } = null!;
|
||||
public DbSet<AppUserReadingProfile> AppUserReadingProfile { get; set; } = null!;
|
||||
public DbSet<SeriesReadingProfile> SeriesReadingProfile { get; set; } = null!;
|
||||
public DbSet<LibraryReadingProfile> LibraryReadingProfile { get; set; } = null!;
|
||||
public DbSet<AppUserReadingProfile> AppUserReadingProfiles { get; set; } = null!;
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
|
|
@ -272,6 +270,19 @@ public sealed class DataContext : IdentityDbContext<AppUser, AppRole, int,
|
|||
builder.Entity<AppUserReadingProfile>()
|
||||
.Property(b => b.AllowAutomaticWebtoonReaderDetection)
|
||||
.HasDefaultValue(true);
|
||||
|
||||
builder.Entity<AppUserReadingProfile>()
|
||||
.Property(rp => rp.LibraryIds)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, JsonSerializerOptions.Default),
|
||||
v => JsonSerializer.Deserialize<List<int>>(v, JsonSerializerOptions.Default) ?? new List<int>())
|
||||
.HasColumnType("TEXT");
|
||||
builder.Entity<AppUserReadingProfile>()
|
||||
.Property(rp => rp.SeriesIds)
|
||||
.HasConversion(
|
||||
v => JsonSerializer.Serialize(v, JsonSerializerOptions.Default),
|
||||
v => JsonSerializer.Deserialize<List<int>>(v, JsonSerializerOptions.Default) ?? new List<int>())
|
||||
.HasColumnType("TEXT");
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Entities.History;
|
||||
using API.Extensions;
|
||||
using API.Helpers.Builders;
|
||||
|
|
@ -23,7 +24,7 @@ public static class ManualMigrateReadingProfiles
|
|||
|
||||
var users = await context.AppUser
|
||||
.Include(u => u.UserPreferences)
|
||||
.Include(u => u.UserPreferences.ReadingProfiles)
|
||||
.Include(u => u.ReadingProfiles)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var user in users)
|
||||
|
|
@ -32,16 +33,19 @@ public static class ManualMigrateReadingProfiles
|
|||
{
|
||||
Name = "Default",
|
||||
NormalizedName = "Default".ToNormalized(),
|
||||
Kind = ReadingProfileKind.Default,
|
||||
LibraryIds = [],
|
||||
SeriesIds = [],
|
||||
BackgroundColor = user.UserPreferences.BackgroundColor,
|
||||
EmulateBook = user.UserPreferences.EmulateBook,
|
||||
User = user,
|
||||
AppUser = user,
|
||||
PdfTheme = user.UserPreferences.PdfTheme,
|
||||
ReaderMode = user.UserPreferences.ReaderMode,
|
||||
ReadingDirection = user.UserPreferences.ReadingDirection,
|
||||
ScalingOption = user.UserPreferences.ScalingOption,
|
||||
LayoutMode = user.UserPreferences.LayoutMode,
|
||||
WidthOverride = null,
|
||||
UserId = user.Id,
|
||||
AppUserId = user.Id,
|
||||
AutoCloseMenu = user.UserPreferences.AutoCloseMenu,
|
||||
BookReaderMargin = user.UserPreferences.BookReaderMargin,
|
||||
PageSplitOption = user.UserPreferences.PageSplitOption,
|
||||
|
|
@ -60,16 +64,10 @@ public static class ManualMigrateReadingProfiles
|
|||
BookReaderTapToPaginate = user.UserPreferences.BookReaderTapToPaginate,
|
||||
ShowScreenHints = user.UserPreferences.ShowScreenHints,
|
||||
};
|
||||
user.UserPreferences.ReadingProfiles.Add(readingProfile);
|
||||
user.ReadingProfiles.Add(readingProfile);
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
foreach (var user in users)
|
||||
{
|
||||
user.UserPreferences.DefaultReadingProfileId =
|
||||
(await context.AppUserReadingProfile
|
||||
.FirstAsync(rp => rp.UserId == user.Id)).Id;
|
||||
}
|
||||
|
||||
context.ManualMigrationHistory.Add(new ManualMigrationHistory
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,198 +0,0 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace API.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AppUserReadingProfiles : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "DefaultReadingProfileId",
|
||||
table: "AppUserPreferences",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AppUserReadingProfile",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Name = table.Column<string>(type: "TEXT", nullable: true),
|
||||
NormalizedName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
UserId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ReadingDirection = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ScalingOption = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
PageSplitOption = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ReaderMode = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
AutoCloseMenu = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
ShowScreenHints = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
EmulateBook = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
LayoutMode = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BackgroundColor = table.Column<string>(type: "TEXT", nullable: true, defaultValue: "#000000"),
|
||||
SwipeToPaginate = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
AllowAutomaticWebtoonReaderDetection = table.Column<bool>(type: "INTEGER", nullable: false, defaultValue: true),
|
||||
WidthOverride = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
BookReaderMargin = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderLineSpacing = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderFontSize = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderFontFamily = table.Column<string>(type: "TEXT", nullable: true),
|
||||
BookReaderTapToPaginate = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
BookReaderReadingDirection = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderWritingStyle = table.Column<int>(type: "INTEGER", nullable: false, defaultValue: 0),
|
||||
BookThemeName = table.Column<string>(type: "TEXT", nullable: true, defaultValue: "Dark"),
|
||||
BookReaderLayoutMode = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderImmersiveMode = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
PdfTheme = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
PdfScrollMode = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
PdfSpreadMode = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Implicit = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
AppUserPreferencesId = table.Column<int>(type: "INTEGER", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AppUserReadingProfile", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_AppUserReadingProfile_AppUserPreferences_AppUserPreferencesId",
|
||||
column: x => x.AppUserPreferencesId,
|
||||
principalTable: "AppUserPreferences",
|
||||
principalColumn: "Id");
|
||||
table.ForeignKey(
|
||||
name: "FK_AppUserReadingProfile_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "LibraryReadingProfile",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
AppUserId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
LibraryId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ReadingProfileId = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_LibraryReadingProfile", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_LibraryReadingProfile_AppUserReadingProfile_ReadingProfileId",
|
||||
column: x => x.ReadingProfileId,
|
||||
principalTable: "AppUserReadingProfile",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_LibraryReadingProfile_AspNetUsers_AppUserId",
|
||||
column: x => x.AppUserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_LibraryReadingProfile_Library_LibraryId",
|
||||
column: x => x.LibraryId,
|
||||
principalTable: "Library",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "SeriesReadingProfile",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
AppUserId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
SeriesId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ReadingProfileId = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_SeriesReadingProfile", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_SeriesReadingProfile_AppUserReadingProfile_ReadingProfileId",
|
||||
column: x => x.ReadingProfileId,
|
||||
principalTable: "AppUserReadingProfile",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_SeriesReadingProfile_AspNetUsers_AppUserId",
|
||||
column: x => x.AppUserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_SeriesReadingProfile_Series_SeriesId",
|
||||
column: x => x.SeriesId,
|
||||
principalTable: "Series",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AppUserReadingProfile_AppUserPreferencesId",
|
||||
table: "AppUserReadingProfile",
|
||||
column: "AppUserPreferencesId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AppUserReadingProfile_UserId",
|
||||
table: "AppUserReadingProfile",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_LibraryReadingProfile_AppUserId",
|
||||
table: "LibraryReadingProfile",
|
||||
column: "AppUserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_LibraryReadingProfile_LibraryId_AppUserId",
|
||||
table: "LibraryReadingProfile",
|
||||
columns: new[] { "LibraryId", "AppUserId" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_LibraryReadingProfile_ReadingProfileId",
|
||||
table: "LibraryReadingProfile",
|
||||
column: "ReadingProfileId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SeriesReadingProfile_AppUserId",
|
||||
table: "SeriesReadingProfile",
|
||||
column: "AppUserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SeriesReadingProfile_ReadingProfileId",
|
||||
table: "SeriesReadingProfile",
|
||||
column: "ReadingProfileId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SeriesReadingProfile_SeriesId",
|
||||
table: "SeriesReadingProfile",
|
||||
column: "SeriesId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "LibraryReadingProfile");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "SeriesReadingProfile");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AppUserReadingProfile");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DefaultReadingProfileId",
|
||||
table: "AppUserPreferences");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||
namespace API.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
[Migration("20250519113715_AppUserReadingProfiles")]
|
||||
partial class AppUserReadingProfiles
|
||||
[Migration("20250601200056_ReadingProfiles")]
|
||||
partial class ReadingProfiles
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
|
|
@ -458,9 +458,6 @@ namespace API.Data.Migrations
|
|||
b.Property<bool>("CollapseSeriesRelationships")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("DefaultReadingProfileId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("EmulateBook")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
|
|
@ -626,7 +623,7 @@ namespace API.Data.Migrations
|
|||
.HasColumnType("INTEGER")
|
||||
.HasDefaultValue(true);
|
||||
|
||||
b.Property<int?>("AppUserPreferencesId")
|
||||
b.Property<int>("AppUserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("AutoCloseMenu")
|
||||
|
|
@ -674,12 +671,15 @@ namespace API.Data.Migrations
|
|||
b.Property<bool>("EmulateBook")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("Implicit")
|
||||
b.Property<int>("Kind")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("LayoutMode")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("LibraryIds")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
|
|
@ -707,25 +707,23 @@ namespace API.Data.Migrations
|
|||
b.Property<int>("ScalingOption")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.PrimitiveCollection<string>("SeriesIds")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("ShowScreenHints")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("SwipeToPaginate")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int?>("WidthOverride")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AppUserPreferencesId");
|
||||
b.HasIndex("AppUserId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AppUserReadingProfile");
|
||||
b.ToTable("AppUserReadingProfiles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.AppUserRole", b =>
|
||||
|
|
@ -1380,33 +1378,6 @@ namespace API.Data.Migrations
|
|||
b.ToTable("LibraryFileTypeGroup");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.LibraryReadingProfile", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("AppUserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("LibraryId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ReadingProfileId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AppUserId");
|
||||
|
||||
b.HasIndex("ReadingProfileId");
|
||||
|
||||
b.HasIndex("LibraryId", "AppUserId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("LibraryReadingProfile");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.MangaFile", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
|
@ -2394,32 +2365,6 @@ namespace API.Data.Migrations
|
|||
b.ToTable("Series");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.SeriesReadingProfile", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("AppUserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ReadingProfileId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("SeriesId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AppUserId");
|
||||
|
||||
b.HasIndex("ReadingProfileId");
|
||||
|
||||
b.HasIndex("SeriesId");
|
||||
|
||||
b.ToTable("SeriesReadingProfile");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.ServerSetting", b =>
|
||||
{
|
||||
b.Property<int>("Key")
|
||||
|
|
@ -3012,17 +2957,13 @@ namespace API.Data.Migrations
|
|||
|
||||
modelBuilder.Entity("API.Entities.AppUserReadingProfile", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.AppUserPreferences", null)
|
||||
b.HasOne("API.Entities.AppUser", "AppUser")
|
||||
.WithMany("ReadingProfiles")
|
||||
.HasForeignKey("AppUserPreferencesId");
|
||||
|
||||
b.HasOne("API.Entities.AppUser", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.HasForeignKey("AppUserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
b.Navigation("AppUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.AppUserRole", b =>
|
||||
|
|
@ -3184,33 +3125,6 @@ namespace API.Data.Migrations
|
|||
b.Navigation("Library");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.LibraryReadingProfile", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.AppUser", "AppUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("AppUserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("API.Entities.Library", "Library")
|
||||
.WithMany("ReadingProfiles")
|
||||
.HasForeignKey("LibraryId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("API.Entities.AppUserReadingProfile", "ReadingProfile")
|
||||
.WithMany("Libraries")
|
||||
.HasForeignKey("ReadingProfileId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("AppUser");
|
||||
|
||||
b.Navigation("Library");
|
||||
|
||||
b.Navigation("ReadingProfile");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.MangaFile", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.Chapter", "Chapter")
|
||||
|
|
@ -3468,33 +3382,6 @@ namespace API.Data.Migrations
|
|||
b.Navigation("Library");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.SeriesReadingProfile", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.AppUser", "AppUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("AppUserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("API.Entities.AppUserReadingProfile", "ReadingProfile")
|
||||
.WithMany("Series")
|
||||
.HasForeignKey("ReadingProfileId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("API.Entities.Series", "Series")
|
||||
.WithMany("ReadingProfiles")
|
||||
.HasForeignKey("SeriesId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("AppUser");
|
||||
|
||||
b.Navigation("ReadingProfile");
|
||||
|
||||
b.Navigation("Series");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.Volume", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.Series", "Series")
|
||||
|
|
@ -3717,6 +3604,8 @@ namespace API.Data.Migrations
|
|||
|
||||
b.Navigation("ReadingLists");
|
||||
|
||||
b.Navigation("ReadingProfiles");
|
||||
|
||||
b.Navigation("ScrobbleHolds");
|
||||
|
||||
b.Navigation("SideNavStreams");
|
||||
|
|
@ -3732,18 +3621,6 @@ namespace API.Data.Migrations
|
|||
b.Navigation("WantToRead");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.AppUserPreferences", b =>
|
||||
{
|
||||
b.Navigation("ReadingProfiles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.AppUserReadingProfile", b =>
|
||||
{
|
||||
b.Navigation("Libraries");
|
||||
|
||||
b.Navigation("Series");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.Chapter", b =>
|
||||
{
|
||||
b.Navigation("ExternalRatings");
|
||||
|
|
@ -3767,8 +3644,6 @@ namespace API.Data.Migrations
|
|||
|
||||
b.Navigation("LibraryFileTypes");
|
||||
|
||||
b.Navigation("ReadingProfiles");
|
||||
|
||||
b.Navigation("Series");
|
||||
});
|
||||
|
||||
|
|
@ -3806,8 +3681,6 @@ namespace API.Data.Migrations
|
|||
|
||||
b.Navigation("Ratings");
|
||||
|
||||
b.Navigation("ReadingProfiles");
|
||||
|
||||
b.Navigation("RelationOf");
|
||||
|
||||
b.Navigation("Relations");
|
||||
75
API/Data/Migrations/20250601200056_ReadingProfiles.cs
Normal file
75
API/Data/Migrations/20250601200056_ReadingProfiles.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace API.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ReadingProfiles : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AppUserReadingProfiles",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Name = table.Column<string>(type: "TEXT", nullable: true),
|
||||
NormalizedName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
AppUserId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Kind = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
LibraryIds = table.Column<string>(type: "TEXT", nullable: true),
|
||||
SeriesIds = table.Column<string>(type: "TEXT", nullable: true),
|
||||
ReadingDirection = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ScalingOption = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
PageSplitOption = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ReaderMode = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
AutoCloseMenu = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
ShowScreenHints = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
EmulateBook = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
LayoutMode = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BackgroundColor = table.Column<string>(type: "TEXT", nullable: true, defaultValue: "#000000"),
|
||||
SwipeToPaginate = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
AllowAutomaticWebtoonReaderDetection = table.Column<bool>(type: "INTEGER", nullable: false, defaultValue: true),
|
||||
WidthOverride = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
BookReaderMargin = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderLineSpacing = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderFontSize = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderFontFamily = table.Column<string>(type: "TEXT", nullable: true),
|
||||
BookReaderTapToPaginate = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
BookReaderReadingDirection = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderWritingStyle = table.Column<int>(type: "INTEGER", nullable: false, defaultValue: 0),
|
||||
BookThemeName = table.Column<string>(type: "TEXT", nullable: true, defaultValue: "Dark"),
|
||||
BookReaderLayoutMode = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
BookReaderImmersiveMode = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
PdfTheme = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
PdfScrollMode = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
PdfSpreadMode = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AppUserReadingProfiles", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_AppUserReadingProfiles_AspNetUsers_AppUserId",
|
||||
column: x => x.AppUserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AppUserReadingProfiles_AppUserId",
|
||||
table: "AppUserReadingProfiles",
|
||||
column: "AppUserId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "AppUserReadingProfiles");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -455,9 +455,6 @@ namespace API.Data.Migrations
|
|||
b.Property<bool>("CollapseSeriesRelationships")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("DefaultReadingProfileId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("EmulateBook")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
|
|
@ -623,7 +620,7 @@ namespace API.Data.Migrations
|
|||
.HasColumnType("INTEGER")
|
||||
.HasDefaultValue(true);
|
||||
|
||||
b.Property<int?>("AppUserPreferencesId")
|
||||
b.Property<int>("AppUserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("AutoCloseMenu")
|
||||
|
|
@ -671,12 +668,15 @@ namespace API.Data.Migrations
|
|||
b.Property<bool>("EmulateBook")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("Implicit")
|
||||
b.Property<int>("Kind")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("LayoutMode")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("LibraryIds")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
|
|
@ -704,25 +704,23 @@ namespace API.Data.Migrations
|
|||
b.Property<int>("ScalingOption")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.PrimitiveCollection<string>("SeriesIds")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("ShowScreenHints")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("SwipeToPaginate")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int?>("WidthOverride")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AppUserPreferencesId");
|
||||
b.HasIndex("AppUserId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AppUserReadingProfile");
|
||||
b.ToTable("AppUserReadingProfiles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.AppUserRole", b =>
|
||||
|
|
@ -1377,33 +1375,6 @@ namespace API.Data.Migrations
|
|||
b.ToTable("LibraryFileTypeGroup");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.LibraryReadingProfile", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("AppUserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("LibraryId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ReadingProfileId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AppUserId");
|
||||
|
||||
b.HasIndex("ReadingProfileId");
|
||||
|
||||
b.HasIndex("LibraryId", "AppUserId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("LibraryReadingProfile");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.MangaFile", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
|
@ -2391,32 +2362,6 @@ namespace API.Data.Migrations
|
|||
b.ToTable("Series");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.SeriesReadingProfile", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("AppUserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ReadingProfileId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("SeriesId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AppUserId");
|
||||
|
||||
b.HasIndex("ReadingProfileId");
|
||||
|
||||
b.HasIndex("SeriesId");
|
||||
|
||||
b.ToTable("SeriesReadingProfile");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.ServerSetting", b =>
|
||||
{
|
||||
b.Property<int>("Key")
|
||||
|
|
@ -3009,17 +2954,13 @@ namespace API.Data.Migrations
|
|||
|
||||
modelBuilder.Entity("API.Entities.AppUserReadingProfile", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.AppUserPreferences", null)
|
||||
b.HasOne("API.Entities.AppUser", "AppUser")
|
||||
.WithMany("ReadingProfiles")
|
||||
.HasForeignKey("AppUserPreferencesId");
|
||||
|
||||
b.HasOne("API.Entities.AppUser", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.HasForeignKey("AppUserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
b.Navigation("AppUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.AppUserRole", b =>
|
||||
|
|
@ -3181,33 +3122,6 @@ namespace API.Data.Migrations
|
|||
b.Navigation("Library");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.LibraryReadingProfile", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.AppUser", "AppUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("AppUserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("API.Entities.Library", "Library")
|
||||
.WithMany("ReadingProfiles")
|
||||
.HasForeignKey("LibraryId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("API.Entities.AppUserReadingProfile", "ReadingProfile")
|
||||
.WithMany("Libraries")
|
||||
.HasForeignKey("ReadingProfileId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("AppUser");
|
||||
|
||||
b.Navigation("Library");
|
||||
|
||||
b.Navigation("ReadingProfile");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.MangaFile", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.Chapter", "Chapter")
|
||||
|
|
@ -3465,33 +3379,6 @@ namespace API.Data.Migrations
|
|||
b.Navigation("Library");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.SeriesReadingProfile", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.AppUser", "AppUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("AppUserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("API.Entities.AppUserReadingProfile", "ReadingProfile")
|
||||
.WithMany("Series")
|
||||
.HasForeignKey("ReadingProfileId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("API.Entities.Series", "Series")
|
||||
.WithMany("ReadingProfiles")
|
||||
.HasForeignKey("SeriesId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("AppUser");
|
||||
|
||||
b.Navigation("ReadingProfile");
|
||||
|
||||
b.Navigation("Series");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.Volume", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.Series", "Series")
|
||||
|
|
@ -3714,6 +3601,8 @@ namespace API.Data.Migrations
|
|||
|
||||
b.Navigation("ReadingLists");
|
||||
|
||||
b.Navigation("ReadingProfiles");
|
||||
|
||||
b.Navigation("ScrobbleHolds");
|
||||
|
||||
b.Navigation("SideNavStreams");
|
||||
|
|
@ -3729,18 +3618,6 @@ namespace API.Data.Migrations
|
|||
b.Navigation("WantToRead");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.AppUserPreferences", b =>
|
||||
{
|
||||
b.Navigation("ReadingProfiles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.AppUserReadingProfile", b =>
|
||||
{
|
||||
b.Navigation("Libraries");
|
||||
|
||||
b.Navigation("Series");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.Chapter", b =>
|
||||
{
|
||||
b.Navigation("ExternalRatings");
|
||||
|
|
@ -3764,8 +3641,6 @@ namespace API.Data.Migrations
|
|||
|
||||
b.Navigation("LibraryFileTypes");
|
||||
|
||||
b.Navigation("ReadingProfiles");
|
||||
|
||||
b.Navigation("Series");
|
||||
});
|
||||
|
||||
|
|
@ -3803,8 +3678,6 @@ namespace API.Data.Migrations
|
|||
|
||||
b.Navigation("Ratings");
|
||||
|
||||
b.Navigation("ReadingProfiles");
|
||||
|
||||
b.Navigation("RelationOf");
|
||||
|
||||
b.Navigation("Relations");
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Extensions;
|
||||
using API.Extensions.QueryExtensions;
|
||||
using AutoMapper;
|
||||
|
|
@ -13,210 +13,94 @@ using Microsoft.EntityFrameworkCore;
|
|||
|
||||
namespace API.Data.Repositories;
|
||||
|
||||
[Flags]
|
||||
public enum ReadingProfileIncludes
|
||||
{
|
||||
None = 0,
|
||||
Series = 1 << 1,
|
||||
Library = 1 << 2
|
||||
}
|
||||
|
||||
public interface IAppUserReadingProfileRepository
|
||||
{
|
||||
Task<IList<AppUserReadingProfile>> GetProfilesForUser(int userId, bool nonImplicitOnly, ReadingProfileIncludes includes = ReadingProfileIncludes.None);
|
||||
Task<IList<UserReadingProfileDto>> GetProfilesDtoForUser(int userId, bool nonImplicitOnly, ReadingProfileIncludes includes = ReadingProfileIncludes.None);
|
||||
Task<AppUserReadingProfile?> GetProfileForSeries(int userId, int seriesId, ReadingProfileIncludes includes = ReadingProfileIncludes.None);
|
||||
|
||||
/// <summary>
|
||||
/// Returns both implicit and "real" reading profiles
|
||||
/// Return the given profile if it belongs the user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="seriesId"></param>
|
||||
/// <param name="includes"></param>
|
||||
/// <param name="profileId"></param>
|
||||
/// <returns></returns>
|
||||
Task<AppUserReadingProfile?> GetUserProfile(int userId, int profileId);
|
||||
/// <summary>
|
||||
/// Returns all reading profiles for the user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<IList<AppUserReadingProfile>> GetProfilesForUser(int userId);
|
||||
/// <summary>
|
||||
/// Returns all non-implicit reading profiles for the user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<IList<UserReadingProfileDto>> GetProfilesDtoForUser(int userId);
|
||||
/// <summary>
|
||||
/// Find a profile by name, belonging to a specific user
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
Task<IList<AppUserReadingProfile>> GetAllProfilesForSeries(int userId, int seriesId, ReadingProfileIncludes includes = ReadingProfileIncludes.None);
|
||||
Task<IList<AppUserReadingProfile>> GetProfilesForSeries(int userId, IList<int> seriesIds, bool implicitOnly, ReadingProfileIncludes includes = ReadingProfileIncludes.None);
|
||||
Task<UserReadingProfileDto?> GetProfileDtoForSeries(int userId, int seriesId);
|
||||
Task<AppUserReadingProfile?> GetProfileForLibrary(int userId, int libraryId, ReadingProfileIncludes includes = ReadingProfileIncludes.None);
|
||||
Task<UserReadingProfileDto?> GetProfileDtoForLibrary(int userId, int libraryId);
|
||||
Task<AppUserReadingProfile?> GetProfile(int profileId, ReadingProfileIncludes includes = ReadingProfileIncludes.None);
|
||||
Task<UserReadingProfileDto?> GetProfileDto(int profileId);
|
||||
Task<AppUserReadingProfile?> GetProfileByName(int userId, string name);
|
||||
Task<SeriesReadingProfile?> GetSeriesProfile(int userId, int seriesId);
|
||||
Task<IList<SeriesReadingProfile>> GetSeriesProfilesForSeries(int userId, IList<int> seriesIds);
|
||||
Task<LibraryReadingProfile?> GetLibraryProfile(int userId, int libraryId);
|
||||
|
||||
void Add(AppUserReadingProfile readingProfile);
|
||||
void Add(SeriesReadingProfile readingProfile);
|
||||
void Add(LibraryReadingProfile readingProfile);
|
||||
void Attach(AppUserReadingProfile readingProfile);
|
||||
void Update(AppUserReadingProfile readingProfile);
|
||||
void Update(SeriesReadingProfile readingProfile);
|
||||
void Remove(AppUserReadingProfile readingProfile);
|
||||
void Remove(SeriesReadingProfile readingProfile);
|
||||
void RemoveRange(IEnumerable<AppUserReadingProfile> readingProfiles);
|
||||
}
|
||||
|
||||
public class AppUserReadingProfileRepository(DataContext context, IMapper mapper): IAppUserReadingProfileRepository
|
||||
{
|
||||
|
||||
public async Task<IList<AppUserReadingProfile>> GetProfilesForUser(int userId, bool nonImplicitOnly, ReadingProfileIncludes includes = ReadingProfileIncludes.None)
|
||||
public async Task<AppUserReadingProfile?> GetUserProfile(int userId, int profileId)
|
||||
{
|
||||
return await context.AppUserReadingProfile
|
||||
.Where(rp => rp.UserId == userId && !(nonImplicitOnly && rp.Implicit))
|
||||
.Includes(includes)
|
||||
return await context.AppUserReadingProfiles
|
||||
.Where(rp => rp.AppUserId == userId && rp.Id == profileId)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<IList<AppUserReadingProfile>> GetProfilesForUser(int userId)
|
||||
{
|
||||
return await context.AppUserReadingProfiles
|
||||
.Where(rp => rp.AppUserId == userId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IList<UserReadingProfileDto>> GetProfilesDtoForUser(int userId, bool nonImplicitOnly,
|
||||
ReadingProfileIncludes includes = ReadingProfileIncludes.None)
|
||||
public async Task<IList<UserReadingProfileDto>> GetProfilesDtoForUser(int userId)
|
||||
{
|
||||
return await context.AppUserReadingProfile
|
||||
.Where(rp => rp.UserId == userId && !(nonImplicitOnly && rp.Implicit))
|
||||
.Includes(includes)
|
||||
return await context.AppUserReadingProfiles
|
||||
.Where(rp => rp.AppUserId == userId)
|
||||
.Where(rp => rp.Kind !=ReadingProfileKind.Implicit)
|
||||
.ProjectTo<UserReadingProfileDto>(mapper.ConfigurationProvider)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<AppUserReadingProfile?> GetProfileForSeries(int userId, int seriesId, ReadingProfileIncludes includes = ReadingProfileIncludes.None)
|
||||
{
|
||||
return await context.AppUserReadingProfile
|
||||
.Where(rp => rp.UserId == userId && rp.Series.Any(s => s.SeriesId == seriesId))
|
||||
.Includes(includes)
|
||||
.OrderByDescending(rp => rp.Implicit) // Get implicit profiles first
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<IList<AppUserReadingProfile>> GetAllProfilesForSeries(int userId, int seriesId, ReadingProfileIncludes includes = ReadingProfileIncludes.None)
|
||||
{
|
||||
return await context.AppUserReadingProfile
|
||||
.Where(rp => rp.UserId == userId && rp.Series.Any(s => s.SeriesId == seriesId))
|
||||
.Includes(includes)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IList<AppUserReadingProfile>> GetProfilesForSeries(int userId, IList<int> seriesIds, bool implicitOnly, ReadingProfileIncludes includes = ReadingProfileIncludes.None)
|
||||
{
|
||||
return await context.AppUserReadingProfile
|
||||
.Where(rp
|
||||
=> rp.UserId == userId
|
||||
&& rp.Series.Any(s => seriesIds.Contains(s.SeriesId))
|
||||
&& (!implicitOnly || rp.Implicit))
|
||||
.Includes(includes)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<UserReadingProfileDto?> GetProfileDtoForSeries(int userId, int seriesId)
|
||||
{
|
||||
return await context.AppUserReadingProfile
|
||||
.Where(rp => rp.UserId == userId && rp.Series.Any(s => s.SeriesId == seriesId))
|
||||
.OrderByDescending(rp => rp.Implicit) // Get implicit profiles first
|
||||
.ProjectTo<UserReadingProfileDto>(mapper.ConfigurationProvider)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<AppUserReadingProfile?> GetProfileForLibrary(int userId, int libraryId, ReadingProfileIncludes includes = ReadingProfileIncludes.None)
|
||||
{
|
||||
return await context.AppUserReadingProfile
|
||||
.Where(rp => rp.UserId == userId && rp.Libraries.Any(s => s.LibraryId == libraryId))
|
||||
.Includes(includes)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<UserReadingProfileDto?> GetProfileDtoForLibrary(int userId, int libraryId)
|
||||
{
|
||||
return await context.AppUserReadingProfile
|
||||
.Where(rp => rp.UserId == userId && rp.Libraries.Any(s => s.LibraryId == libraryId))
|
||||
.ProjectTo<UserReadingProfileDto>(mapper.ConfigurationProvider)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<AppUserReadingProfile?> GetProfile(int profileId, ReadingProfileIncludes includes = ReadingProfileIncludes.None)
|
||||
{
|
||||
return await context.AppUserReadingProfile
|
||||
.Where(rp => rp.Id == profileId)
|
||||
.Includes(includes)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
public async Task<UserReadingProfileDto?> GetProfileDto(int profileId)
|
||||
{
|
||||
return await context.AppUserReadingProfile
|
||||
.Where(rp => rp.Id == profileId)
|
||||
.ProjectTo<UserReadingProfileDto>(mapper.ConfigurationProvider)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<AppUserReadingProfile?> GetProfileByName(int userId, string name)
|
||||
{
|
||||
var normalizedName = name.ToNormalized();
|
||||
|
||||
return await context.AppUserReadingProfile
|
||||
.Where(rp => rp.NormalizedName == normalizedName && rp.UserId == userId)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<SeriesReadingProfile?> GetSeriesProfile(int userId, int seriesId)
|
||||
{
|
||||
return await context.SeriesReadingProfile
|
||||
.Where(rp => rp.SeriesId == seriesId && rp.AppUserId == userId)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<IList<SeriesReadingProfile>> GetSeriesProfilesForSeries(int userId, IList<int> seriesIds)
|
||||
{
|
||||
return await context.SeriesReadingProfile
|
||||
.Where(rp => seriesIds.Contains(rp.SeriesId) && rp.AppUserId == userId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<LibraryReadingProfile?> GetLibraryProfile(int userId, int libraryId)
|
||||
{
|
||||
return await context.LibraryReadingProfile
|
||||
.Where(rp => rp.LibraryId == libraryId && rp.AppUserId == userId)
|
||||
return await context.AppUserReadingProfiles
|
||||
.Where(rp => rp.NormalizedName == normalizedName && rp.AppUserId == userId)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public void Add(AppUserReadingProfile readingProfile)
|
||||
{
|
||||
context.AppUserReadingProfile.Add(readingProfile);
|
||||
}
|
||||
|
||||
public void Add(SeriesReadingProfile readingProfile)
|
||||
{
|
||||
context.SeriesReadingProfile.Add(readingProfile);
|
||||
}
|
||||
|
||||
public void Add(LibraryReadingProfile readingProfile)
|
||||
{
|
||||
context.LibraryReadingProfile.Add(readingProfile);
|
||||
}
|
||||
|
||||
public void Attach(AppUserReadingProfile readingProfile)
|
||||
{
|
||||
context.AppUserReadingProfile.Attach(readingProfile);
|
||||
context.AppUserReadingProfiles.Add(readingProfile);
|
||||
}
|
||||
|
||||
public void Update(AppUserReadingProfile readingProfile)
|
||||
{
|
||||
context.AppUserReadingProfile.Update(readingProfile).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
public void Update(SeriesReadingProfile readingProfile)
|
||||
{
|
||||
context.SeriesReadingProfile.Update(readingProfile).State = EntityState.Modified;
|
||||
context.AppUserReadingProfiles.Update(readingProfile).State = EntityState.Modified;
|
||||
}
|
||||
|
||||
public void Remove(AppUserReadingProfile readingProfile)
|
||||
{
|
||||
context.AppUserReadingProfile.Remove(readingProfile);
|
||||
}
|
||||
|
||||
public void Remove(SeriesReadingProfile readingProfile)
|
||||
{
|
||||
context.SeriesReadingProfile.Remove(readingProfile);
|
||||
context.AppUserReadingProfiles.Remove(readingProfile);
|
||||
}
|
||||
|
||||
public void RemoveRange(IEnumerable<AppUserReadingProfile> readingProfiles)
|
||||
{
|
||||
context.AppUserReadingProfile.RemoveRange(readingProfiles);
|
||||
context.AppUserReadingProfiles.RemoveRange(readingProfiles);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ public class GenreRepository : IGenreRepository
|
|||
|
||||
/// <summary>
|
||||
/// Returns a set of Genre tags for a set of library Ids.
|
||||
/// UserId will restrict returned Genres based on user's age restriction and library access.
|
||||
/// AppUserId will restrict returned Genres based on user's age restriction and library access.
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="libraryIds"></param>
|
||||
|
|
|
|||
|
|
@ -757,7 +757,7 @@ public class UserRepository : IUserRepository
|
|||
|
||||
|
||||
/// <summary>
|
||||
/// Fetches the UserId by API Key. This does not include any extra information
|
||||
/// Fetches the AppUserId by API Key. This does not include any extra information
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <returns></returns>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue