UserController.Delete was calling userRepository.Delete(user) which performed a hard delete (context.Users.Remove), violating the project's soft-delete convention. Changed to set user.DeletedAt = DateTime.UtcNow, matching the pattern used in AssetController.Delete. Also removed the now-unused Delete method from IUserRepository and UserRepository for consistency with AssetRepository (which also has no Delete method). Extended REST tests 103-104 to verify deletedAt is set after deletion. Closes #130
43 lines
1.4 KiB
C#
43 lines
1.4 KiB
C#
using Lactose.Context;
|
|
using Lactose.Models;
|
|
|
|
namespace Lactose.Repositories;
|
|
|
|
/// <inheritdoc />
|
|
public class UserRepository(LactoseDbContext context) : IUserRepository {
|
|
/// <inheritdoc />
|
|
public void Dispose() => context.Dispose();
|
|
|
|
/// <inheritdoc />
|
|
public IEnumerable<User> GetAll() => context.Users.Include(u => u.MaintainedPersons).AsEnumerable();
|
|
|
|
/// <inheritdoc />
|
|
public void Insert(User user) => context.Users.Add(user);
|
|
|
|
/// <inheritdoc />
|
|
public void Save() => context.SaveChanges();
|
|
|
|
/// <inheritdoc />
|
|
public User? Find(Guid id) => context.Users.Find(id);
|
|
|
|
/// <inheritdoc />
|
|
public User? FindByEmail(string email) => context.Users.FirstOrDefault(u => u.Email == email);
|
|
|
|
/// <inheritdoc />
|
|
public User? FindByUsername(string username) => context.Users.FirstOrDefault(u => u.Username == username);
|
|
|
|
/// <inheritdoc />
|
|
public User? FindWithMaintainedPersons(Guid id) =>
|
|
context.Users.Include(u => u.MaintainedPersons).FirstOrDefault(u => u.Id == id);
|
|
|
|
/// <inheritdoc />
|
|
public void SetMaintainedPersons(Guid userId, IEnumerable<Guid> personIds) {
|
|
var existing = context.PersonMaintainers.Where(pm => pm.UserId == userId);
|
|
context.PersonMaintainers.RemoveRange(existing);
|
|
|
|
foreach (var personId in personIds) {
|
|
context.PersonMaintainers.Add(new PersonMaintainer { PersonId = personId, UserId = userId });
|
|
}
|
|
}
|
|
}
|