From 12235a62a2eb886b4e30b88b82242e90f35d75cf Mon Sep 17 00:00:00 2001 From: Amelia <77553571+Fesaa@users.noreply.github.com> Date: Fri, 30 May 2025 13:29:29 +0200 Subject: [PATCH] Fix tests - temp this introduced another bug --- API/Controllers/AccountController.cs | 7 ++++++- API/Data/Repositories/AppUserReadingProfileRepository.cs | 6 ++++++ API/Entities/AppUserPreferences.cs | 1 - 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/API/Controllers/AccountController.cs b/API/Controllers/AccountController.cs index 5501bb338..66218390a 100644 --- a/API/Controllers/AccountController.cs +++ b/API/Controllers/AccountController.cs @@ -790,8 +790,13 @@ public class AccountController : BaseApiController var profile = new AppUserReadingProfileBuilder(user.Id) .WithName("Default Profile") .Build(); + _unitOfWork.AppUserReadingProfileRepository.Attach(profile); + user.UserPreferences.ReadingProfiles.Add(profile); - user.UserPreferences.DefaultReadingProfile = profile; + // TODO: This doesn't save, but I've had to revert it having the full entity or everything would start failing + // in tests because of foreign key constrains. This HAS to be resolved as the code does expect there to always be a + // default profile + user.UserPreferences.DefaultReadingProfileId = profile.Id; } /// diff --git a/API/Data/Repositories/AppUserReadingProfileRepository.cs b/API/Data/Repositories/AppUserReadingProfileRepository.cs index 1c785b647..fd06c4bcd 100644 --- a/API/Data/Repositories/AppUserReadingProfileRepository.cs +++ b/API/Data/Repositories/AppUserReadingProfileRepository.cs @@ -47,6 +47,7 @@ public interface IAppUserReadingProfileRepository void Add(AppUserReadingProfile readingProfile); void Add(SeriesReadingProfile readingProfile); + void Attach(AppUserReadingProfile readingProfile); void Update(AppUserReadingProfile readingProfile); void Update(SeriesReadingProfile readingProfile); void Remove(AppUserReadingProfile readingProfile); @@ -183,6 +184,11 @@ public class AppUserReadingProfileRepository(DataContext context, IMapper mapper context.SeriesReadingProfile.Add(readingProfile); } + public void Attach(AppUserReadingProfile readingProfile) + { + context.AppUserReadingProfile.Attach(readingProfile); + } + public void Update(AppUserReadingProfile readingProfile) { context.AppUserReadingProfile.Update(readingProfile).State = EntityState.Modified; diff --git a/API/Entities/AppUserPreferences.cs b/API/Entities/AppUserPreferences.cs index d38b68bad..9545f190b 100644 --- a/API/Entities/AppUserPreferences.cs +++ b/API/Entities/AppUserPreferences.cs @@ -12,7 +12,6 @@ public class AppUserPreferences #region ReadingProfiles public int DefaultReadingProfileId { get; set; } - public AppUserReadingProfile DefaultReadingProfile { get; set; } public ICollection ReadingProfiles { get; set; } = null!;