Replace tuple return types with named records

CLAUDE.md prohibits tuples as return types. Add PagedResult<T>,
ProfileUpdateResult, and ApiKeyCreationResult records and update all
callers (AuditLogQueryService, AdminIdentityService, UserService,
ApiKeyService and their controllers/endpoints).
This commit is contained in:
2026-07-04 21:21:29 -07:00
parent b4a666ebf0
commit 643188ca9e
13 changed files with 113 additions and 118 deletions

View File

@@ -9,23 +9,23 @@ public class UserService(IMicCheckDbContext db, IPasswordHasher<User> passwordHa
public async Task<User?> FindByIdAsync(int userId, CancellationToken ct = default) =>
await db.Users.FirstOrDefaultAsync(u => u.Id == userId && u.IsActive, ct);
public async Task<(User? User, bool EmailConflict)> UpdateProfileAsync(
public async Task<ProfileUpdateResult> UpdateProfileAsync(
int userId, string firstName, string lastName, string email, CancellationToken ct = default)
{
var user = await db.Users.FirstOrDefaultAsync(u => u.Id == userId && u.IsActive, ct);
if (user is null) return (null, false);
if (user is null) return new ProfileUpdateResult(null, EmailConflict: false);
if (!string.Equals(user.Email, email, StringComparison.OrdinalIgnoreCase))
{
var emailTaken = await db.Users.AnyAsync(u => u.Email == email && u.Id != userId, ct);
if (emailTaken) return (null, true);
if (emailTaken) return new ProfileUpdateResult(null, EmailConflict: true);
}
user.FirstName = firstName;
user.LastName = lastName;
user.Email = email;
await db.SaveChangesAsync(ct);
return (user, false);
return new ProfileUpdateResult(user, EmailConflict: false);
}
public async Task<bool> ChangePasswordAsync(
@@ -42,3 +42,5 @@ public class UserService(IMicCheckDbContext db, IPasswordHasher<User> passwordHa
return true;
}
}
public record ProfileUpdateResult(User? User, bool EmailConflict);