Kavita/API/Helpers/Builders/AppUserReadingProfileBuilder.cs
Joe Milazzo 6d1c7a4ff5
Last of the Year - Page Offset, Device-bound Reading Profiles, and more! (#4313)
Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com>
Co-authored-by: DieselTech <30128380+DieselTech@users.noreply.github.com>
Co-authored-by: Alex George <xzeroknightx@gmail.com>
Co-authored-by: Lucas Winther <lucasw89@live.dk>
Co-authored-by: Toni Kielo <toni.kielo@gmail.com>
Co-authored-by: Patrick Orave <oravep@gmail.com>
2025-12-31 11:01:55 -08:00

64 lines
1.5 KiB
C#

using API.Entities;
using API.Entities.Enums;
using API.Extensions;
namespace API.Helpers.Builders;
public class AppUserReadingProfileBuilder
{
private readonly AppUserReadingProfile _profile;
public AppUserReadingProfile Build() => _profile;
/// <summary>
/// The profile's kind will be <see cref="ReadingProfileKind.User"/> unless overwritten with <see cref="WithKind"/>
/// </summary>
/// <param name="userId"></param>
public AppUserReadingProfileBuilder(int userId)
{
_profile = new AppUserReadingProfile
{
AppUserId = userId,
Kind = ReadingProfileKind.User,
SeriesIds = [],
LibraryIds = [],
DeviceIds = [],
};
}
public AppUserReadingProfileBuilder WithSeries(Series series)
{
_profile.SeriesIds.Add(series.Id);
return this;
}
public AppUserReadingProfileBuilder WithLibrary(Library library)
{
_profile.LibraryIds.Add(library.Id);
return this;
}
public AppUserReadingProfileBuilder WithKind(ReadingProfileKind kind)
{
_profile.Kind = kind;
return this;
}
public AppUserReadingProfileBuilder WithName(string name)
{
_profile.Name = name;
_profile.NormalizedName = name.ToNormalized();
return this;
}
public AppUserReadingProfileBuilder WithDeviceId(int deviceId)
{
if (_profile.DeviceIds.Contains(deviceId)) return this;
_profile.DeviceIds.Add(deviceId);
return this;
}
}