refactor: align TenantRepository with CleanDDD/NetCorePal规范
- remove duplicate ITenantRepository/TenantRepository from Console - extend Platform ITenantRepository with GetByIdAsync, GetPagedAsync, CountAsync - update Console services to use Platform.Infrastructure.Repositories - fix nullable warnings (UserDto, OAuthClientService) - fix YarpGateway Directory.Build.props duplicate import - fix DynamicProxyConfigProvider CS8618 warning
This commit is contained in:
parent
d737688e9b
commit
0bbc97e4a1
@ -10,6 +10,10 @@ public interface ITenantRepository : IRepository<Tenant, TenantId>
|
||||
{
|
||||
Task<Tenant?> GetByTenantIdAsync(string tenantId, CancellationToken cancellationToken = default);
|
||||
Task<Tenant?> GetByIdIncludeH5Async(TenantId id, CancellationToken cancellationToken = default);
|
||||
Task<Tenant?> GetByIdAsync(long id, CancellationToken cancellationToken = default);
|
||||
Task<IEnumerable<Tenant>> GetPagedAsync(int page, int pageSize, string? name = null, string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default);
|
||||
Task<int> CountAsync(string? name = null, string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default);
|
||||
Task<int> GetUserCountAsync(TenantId tenantId, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
public class TenantRepository(PlatformDbContext context)
|
||||
@ -24,4 +28,51 @@ public class TenantRepository(PlatformDbContext context)
|
||||
{
|
||||
return await DbContext.Tenants.FirstOrDefaultAsync(t => t.Id == id, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<Tenant?> GetByIdAsync(long id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await DbContext.Tenants.FindAsync(new object[] { id }, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Tenant>> GetPagedAsync(int page, int pageSize, string? name = null,
|
||||
string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var query = DbContext.Tenants.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
query = query.Where(t => t.Name.Contains(name));
|
||||
|
||||
if (!string.IsNullOrEmpty(tenantCode))
|
||||
query = query.Where(t => t.TenantCode.Contains(tenantCode));
|
||||
|
||||
if (status.HasValue)
|
||||
query = query.Where(t => t.Status == status);
|
||||
|
||||
return await query
|
||||
.OrderByDescending(t => t.CreatedAt)
|
||||
.Skip((page - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<int> CountAsync(string? name = null, string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var query = DbContext.Tenants.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
query = query.Where(t => t.Name.Contains(name));
|
||||
|
||||
if (!string.IsNullOrEmpty(tenantCode))
|
||||
query = query.Where(t => t.TenantCode.Contains(tenantCode));
|
||||
|
||||
if (status.HasValue)
|
||||
query = query.Where(t => t.Status == status);
|
||||
|
||||
return await query.CountAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<int> GetUserCountAsync(TenantId tenantId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user