refactor(console): remove Repository layer, use Manager pattern
- Remove Repositories folder (IUserRepository, UserRepository, IRoleRepository, RoleRepository) - Remove Managers folder (old TenantManager) - Remove Datas folder (old ApplicationDbContext) - Remove Models/Entities folder (old domain entities) - Remove EntityConfigurations folder - Update Services to use UserManager/RoleManager/PlatformDbContext directly - Update DTOs to use Platform's TenantStatus
This commit is contained in:
parent
a17dc9c419
commit
c1f1e09796
@ -1,11 +1,13 @@
|
||||
namespace Fengling.Platform.Infrastructure;
|
||||
|
||||
using Fengling.Platform.Domain.AggregatesModel.RoleAggregate;
|
||||
using Fengling.Platform.Domain.AggregatesModel.TenantAggregate;
|
||||
using Fengling.Platform.Domain.AggregatesModel.UserAggregate;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
||||
namespace Fengling.Platform.Infrastructure;
|
||||
|
||||
|
||||
public partial class PlatformDbContext(DbContextOptions<PlatformDbContext> options)
|
||||
: IdentityDbContext<ApplicationUser, ApplicationRole, long>(options)
|
||||
{
|
||||
|
||||
@ -17,65 +17,58 @@ public interface ITenantManager
|
||||
Task<IdentityResult> SetTenantCodeAsync(Tenant tenant, string code, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
public class TenantManager : ITenantManager
|
||||
public sealed class TenantManager(ITenantStore store) : ITenantManager
|
||||
{
|
||||
private readonly ITenantStore _store;
|
||||
|
||||
public TenantManager(ITenantStore store)
|
||||
public async Task<Tenant?> FindByIdAsync(long tenantId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
_store = store;
|
||||
return await store.FindByIdAsync(tenantId, cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task<Tenant?> FindByIdAsync(long tenantId, CancellationToken cancellationToken = default)
|
||||
public async Task<Tenant?> FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _store.FindByIdAsync(tenantId, cancellationToken);
|
||||
return await store.FindByTenantCodeAsync(tenantCode, cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task<Tenant?> FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default)
|
||||
public async Task<IList<Tenant>> GetAllAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _store.FindByTenantCodeAsync(tenantCode, cancellationToken);
|
||||
return await store.GetAllAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task<IList<Tenant>> GetAllAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _store.GetAllAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task<IList<Tenant>> GetPagedAsync(int page, int pageSize, string? name = null,
|
||||
public async Task<IList<Tenant>> GetPagedAsync(int page, int pageSize, string? name = null,
|
||||
string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _store.GetPagedAsync(page, pageSize, name, tenantCode, status, cancellationToken);
|
||||
return await store.GetPagedAsync(page, pageSize, name, tenantCode, status, cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task<int> GetCountAsync(string? name = null, string? tenantCode = null,
|
||||
public async Task<int> GetCountAsync(string? name = null, string? tenantCode = null,
|
||||
TenantStatus? status = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _store.GetCountAsync(name, tenantCode, status, cancellationToken);
|
||||
return await store.GetCountAsync(name, tenantCode, status, cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task<IdentityResult> CreateAsync(Tenant tenant, CancellationToken cancellationToken = default)
|
||||
public async Task<IdentityResult> CreateAsync(Tenant tenant, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _store.CreateAsync(tenant, cancellationToken);
|
||||
return await store.CreateAsync(tenant, cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task<IdentityResult> UpdateAsync(Tenant tenant, CancellationToken cancellationToken = default)
|
||||
public async Task<IdentityResult> UpdateAsync(Tenant tenant, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _store.UpdateAsync(tenant, cancellationToken);
|
||||
return await store.UpdateAsync(tenant, cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task<IdentityResult> DeleteAsync(Tenant tenant, CancellationToken cancellationToken = default)
|
||||
public async Task<IdentityResult> DeleteAsync(Tenant tenant, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _store.DeleteAsync(tenant, cancellationToken);
|
||||
return await store.DeleteAsync(tenant, cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task<int> GetUserCountAsync(long tenantId, CancellationToken cancellationToken = default)
|
||||
public async Task<int> GetUserCountAsync(long tenantId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _store.GetUserCountAsync(tenantId, cancellationToken);
|
||||
return await store.GetUserCountAsync(tenantId, cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task<IdentityResult> SetTenantCodeAsync(Tenant tenant, string code, CancellationToken cancellationToken = default)
|
||||
public async Task<IdentityResult> SetTenantCodeAsync(Tenant tenant, string code, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await _store.SetTenantCodeAsync(tenant, code, cancellationToken);
|
||||
await store.SetTenantCodeAsync(tenant, code, cancellationToken);
|
||||
return IdentityResult.Success;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user