Some unit tests, names and small fixes

This commit is contained in:
Amelia 2025-05-15 23:58:42 +02:00
parent 23c4a451b4
commit 06914d1135
No known key found for this signature in database
GPG key ID: D6D0ECE365407EAA
10 changed files with 332 additions and 13 deletions

View file

@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace API.Data.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20250514215429_AppUserReadingProfiles")]
[Migration("20250515215234_AppUserReadingProfiles")]
partial class AppUserReadingProfiles
{
/// <inheritdoc />
@ -672,6 +672,12 @@ namespace API.Data.Migrations
b.Property<int>("LayoutMode")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("NormalizedName")
.HasColumnType("TEXT");
b.Property<int>("PageSplitOption")
.HasColumnType("INTEGER");

View file

@ -23,6 +23,8 @@ namespace API.Data.Migrations
{
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),

View file

@ -669,6 +669,12 @@ namespace API.Data.Migrations
b.Property<int>("LayoutMode")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("NormalizedName")
.HasColumnType("TEXT");
b.Property<int>("PageSplitOption")
.HasColumnType("INTEGER");

View file

@ -1,19 +1,29 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using API.Entities;
using API.Extensions.QueryExtensions;
using AutoMapper;
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);
Task<AppUserReadingProfile?> GetProfileForSeries(int userId, int seriesId);
Task<AppUserReadingProfile?> GetProfileForLibrary(int userId, int libraryId);
Task<AppUserReadingProfile?> GetProfile(int profileId);
Task<AppUserReadingProfile?> GetProfile(int profileId, ReadingProfileIncludes includes = ReadingProfileIncludes.None);
void Add(AppUserReadingProfile readingProfile);
void Update(AppUserReadingProfile readingProfile);
@ -44,10 +54,11 @@ public class AppUserReadingProfileRepository(DataContext context, IMapper mapper
.FirstOrDefaultAsync();
}
public async Task<AppUserReadingProfile?> GetProfile(int profileId)
public async Task<AppUserReadingProfile?> GetProfile(int profileId, ReadingProfileIncludes includes = ReadingProfileIncludes.None)
{
return await context.AppUserReadingProfile
.Where(rp => rp.Id == profileId)
.Includes(includes)
.FirstOrDefaultAsync();
}