Slight changes to the entity, more UI work

This commit is contained in:
Amelia 2025-05-19 14:54:20 +02:00
parent 5656fb2148
commit 9b4a4b8a50
24 changed files with 864 additions and 315 deletions

View file

@ -29,6 +29,7 @@ public interface IReadingProfileService
/// <param name="userId"></param>
/// <param name="dto"></param>
/// <returns></returns>
/// <remarks>Does not update connected series and libraries</remarks>
Task<bool> UpdateReadingProfile(int userId, UserReadingProfileDto dto);
/// <summary>
@ -74,6 +75,12 @@ public interface IReadingProfileService
/// <returns></returns>
Task SetDefaultReadingProfile(int userId, int profileId);
Task AddProfileToSeries(int userId, int profileId, int seriesId);
Task RemoveProfileFromSeries(int userId, int profileId, int seriesId);
Task AddProfileToLibrary(int userId, int profileId, int libraryId);
Task RemoveProfileFromLibrary(int userId, int profileId, int libraryId);
}
public class ReadingProfileService(IUnitOfWork unitOfWork, ILocalizationService localizationService): IReadingProfileService
@ -164,7 +171,7 @@ public class ReadingProfileService(IUnitOfWork unitOfWork, ILocalizationService
if (!profile.Implicit) return;
profile.Series = profile.Series.Where(s => s.Id != seriesId).ToList();
profile.Series = profile.Series.Where(s => s.SeriesId != seriesId).ToList();
await unitOfWork.CommitAsync();
}
@ -197,6 +204,70 @@ public class ReadingProfileService(IUnitOfWork unitOfWork, ILocalizationService
await unitOfWork.CommitAsync();
}
public async Task AddProfileToSeries(int userId, int profileId, int seriesId)
{
var profile = await unitOfWork.AppUserReadingProfileRepository.GetProfile(profileId);
if (profile == null) throw new KavitaException("profile-not-found");
if (profile.UserId != userId) throw new UnauthorizedAccessException();
var seriesProfile = await unitOfWork.AppUserReadingProfileRepository.GetSeriesProfile(userId, seriesId);
if (seriesProfile == null)
{
seriesProfile = new SeriesReadingProfile
{
AppUserId = userId,
SeriesId = seriesId,
};
}
seriesProfile.ReadingProfile = profile;
await unitOfWork.CommitAsync();
}
public async Task RemoveProfileFromSeries(int userId, int profileId, int seriesId)
{
var profile = await unitOfWork.AppUserReadingProfileRepository.GetProfile(profileId);
if (profile == null) throw new KavitaException("profile-not-found");
if (profile.UserId != userId) throw new UnauthorizedAccessException();
profile.Series = profile.Series.Where(s => s.SeriesId != seriesId).ToList();
await unitOfWork.CommitAsync();
}
public async Task AddProfileToLibrary(int userId, int profileId, int libraryId)
{
var profile = await unitOfWork.AppUserReadingProfileRepository.GetProfile(profileId);
if (profile == null) throw new KavitaException("profile-not-found");
if (profile.UserId != userId) throw new UnauthorizedAccessException();
var libraryProfile = await unitOfWork.AppUserReadingProfileRepository.GetLibraryProfile(userId, libraryId);
if (libraryProfile == null)
{
libraryProfile = new LibraryReadingProfile
{
AppUserId = userId,
LibraryId = libraryId,
};
}
libraryProfile.ReadingProfile = profile;
await unitOfWork.CommitAsync();
}
public async Task RemoveProfileFromLibrary(int userId, int profileId, int libraryId)
{
var profile = await unitOfWork.AppUserReadingProfileRepository.GetProfile(profileId);
if (profile == null) throw new KavitaException("profile-not-found");
if (profile.UserId != userId) throw new UnauthorizedAccessException();
profile.Libraries = profile.Libraries.Where(s => s.LibraryId != libraryId).ToList();
await unitOfWork.CommitAsync();
}
private static void UpdateReaderProfileFields(AppUserReadingProfile existingProfile, UserReadingProfileDto dto, bool updateName = true)
{
if (updateName && !string.IsNullOrEmpty(dto.Name) && existingProfile.NormalizedName != dto.Name.ToNormalized())