refactor(platform): migrate Tenant to anemia model, use Manager pattern
- Convert Tenant to anemia model with long Id (no strong-typed ID) - Add ApplicationUser, ApplicationRole to Platform.Domain (inherit Identity) - Add TenantInfo value object for user-tenant redundancy - Implement TenantManager/TenantStore in Platform.Infrastructure - Update PlatformDbContext to inherit IdentityDbContext - Migrate AuthService and Console to use Platform entities - Remove old TenantRepository (replaced by TenantManager) - Update AGENTS.md documentation
This commit is contained in:
parent
7a9fcf9fc1
commit
a8656ca982
@ -26,7 +26,7 @@ public class StatsController(
|
|||||||
var tomorrow = today.AddDays(1);
|
var tomorrow = today.AddDays(1);
|
||||||
|
|
||||||
var userCount = await context.Users.CountAsync(u => !u.IsDeleted);
|
var userCount = await context.Users.CountAsync(u => !u.IsDeleted);
|
||||||
var tenantCount = await platformDbContext.Tenants.CountAsync(t => !t.Deleted);
|
var tenantCount = await platformDbContext.Tenants.CountAsync(t => !t.IsDeleted);
|
||||||
var oauthClientCount = await CountOAuthClientsAsync();
|
var oauthClientCount = await CountOAuthClientsAsync();
|
||||||
var todayAccessCount = await context.AccessLogs
|
var todayAccessCount = await context.AccessLogs
|
||||||
.CountAsync(l => l.CreatedAt >= today && l.CreatedAt < tomorrow);
|
.CountAsync(l => l.CreatedAt >= today && l.CreatedAt < tomorrow);
|
||||||
|
|||||||
@ -85,7 +85,7 @@ public class TenantsController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public async Task<ActionResult<Tenant>> GetTenant(TenantId id)
|
public async Task<ActionResult<Tenant>> GetTenant(long id)
|
||||||
{
|
{
|
||||||
var tenant = await platformDbContext.Tenants.FindAsync(id);
|
var tenant = await platformDbContext.Tenants.FindAsync(id);
|
||||||
if (tenant == null)
|
if (tenant == null)
|
||||||
@ -111,7 +111,7 @@ public class TenantsController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{tenantId}/users")]
|
[HttpGet("{tenantId}/users")]
|
||||||
public async Task<ActionResult<List<object>>> GetTenantUsers(TenantId tenantId)
|
public async Task<ActionResult<List<object>>> GetTenantUsers(long tenantId)
|
||||||
{
|
{
|
||||||
var tenant = await platformDbContext.Tenants
|
var tenant = await platformDbContext.Tenants
|
||||||
.FirstOrDefaultAsync(t => t.Id == tenantId);
|
.FirstOrDefaultAsync(t => t.Id == tenantId);
|
||||||
@ -142,7 +142,7 @@ public class TenantsController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{tenantId}/roles")]
|
[HttpGet("{tenantId}/roles")]
|
||||||
public async Task<ActionResult<List<object>>> GetTenantRoles(TenantId tenantId)
|
public async Task<ActionResult<List<object>>> GetTenantRoles(long tenantId)
|
||||||
{
|
{
|
||||||
var tenant = await platformDbContext.Tenants
|
var tenant = await platformDbContext.Tenants
|
||||||
.FirstOrDefaultAsync(t => t.Id == tenantId);
|
.FirstOrDefaultAsync(t => t.Id == tenantId);
|
||||||
@ -166,7 +166,7 @@ public class TenantsController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{tenantId}/settings")]
|
[HttpGet("{tenantId}/settings")]
|
||||||
public async Task<ActionResult<TenantSettings>> GetTenantSettings(TenantId tenantId)
|
public async Task<ActionResult<TenantSettings>> GetTenantSettings(long tenantId)
|
||||||
{
|
{
|
||||||
var tenant = await platformDbContext.Tenants
|
var tenant = await platformDbContext.Tenants
|
||||||
.FirstOrDefaultAsync(t => t.Id == tenantId);
|
.FirstOrDefaultAsync(t => t.Id == tenantId);
|
||||||
@ -189,7 +189,7 @@ public class TenantsController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("{tenantId}/settings")]
|
[HttpPut("{tenantId}/settings")]
|
||||||
public async Task<IActionResult> UpdateTenantSettings(TenantId tenantId, TenantSettings settings)
|
public async Task<IActionResult> UpdateTenantSettings(long tenantId, TenantSettings settings)
|
||||||
{
|
{
|
||||||
var tenant = await platformDbContext.Tenants.FirstOrDefaultAsync(t => t.Id == tenantId);
|
var tenant = await platformDbContext.Tenants.FirstOrDefaultAsync(t => t.Id == tenantId);
|
||||||
if (tenant == null)
|
if (tenant == null)
|
||||||
@ -206,8 +206,19 @@ public class TenantsController(
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ActionResult<Tenant>> CreateTenant(CreateTenantDto dto)
|
public async Task<ActionResult<Tenant>> CreateTenant(CreateTenantDto dto)
|
||||||
{
|
{
|
||||||
var tenant = new Tenant(dto.TenantCode, dto.TenantName, dto.ContactName, dto.ContactEmail, dto.ContactPhone,
|
var tenant = new Tenant
|
||||||
dto.MaxUsers, dto.Description, dto.ExpiresAt);
|
{
|
||||||
|
TenantCode = dto.TenantCode,
|
||||||
|
Name = dto.TenantName,
|
||||||
|
ContactName = dto.ContactName,
|
||||||
|
ContactEmail = dto.ContactEmail,
|
||||||
|
ContactPhone = dto.ContactPhone,
|
||||||
|
MaxUsers = dto.MaxUsers,
|
||||||
|
Description = dto.Description,
|
||||||
|
ExpiresAt = dto.ExpiresAt,
|
||||||
|
Status = TenantStatus.Active,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
};
|
||||||
|
|
||||||
platformDbContext.Tenants.Add(tenant);
|
platformDbContext.Tenants.Add(tenant);
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
@ -228,7 +239,11 @@ public class TenantsController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var oldValue = JsonSerializer.Serialize(tenant);
|
var oldValue = JsonSerializer.Serialize(tenant);
|
||||||
tenant.UpdateInfo(dto.Name, dto.ContactName, dto.ContactEmail, dto.ContactPhone);
|
tenant.Name = dto.Name;
|
||||||
|
tenant.ContactName = dto.ContactName;
|
||||||
|
tenant.ContactEmail = dto.ContactEmail;
|
||||||
|
tenant.ContactPhone = dto.ContactPhone;
|
||||||
|
tenant.UpdatedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
|
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
@ -257,7 +272,8 @@ public class TenantsController(
|
|||||||
user.UpdatedTime = DateTime.UtcNow;
|
user.UpdatedTime = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
tenant.Delete();
|
tenant.IsDeleted = true;
|
||||||
|
tenant.UpdatedAt = DateTime.UtcNow;
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
await CreateAuditLog("tenant", "delete", "Tenant", tenant.Id, tenant.Name, oldValue);
|
await CreateAuditLog("tenant", "delete", "Tenant", tenant.Id, tenant.Name, oldValue);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user