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:
movingsam 2026-02-19 19:20:06 +08:00
parent 4d2127637d
commit f5d6e0652c
9 changed files with 8 additions and 117 deletions

View File

@ -4,6 +4,7 @@
<TargetFramework>net10.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">

View File

@ -7,7 +7,7 @@ public class UserDto
public string? Email { get; set; } public string? Email { get; set; }
public string? RealName { get; set; } public string? RealName { get; set; }
public string? Phone { get; set; } public string? Phone { get; set; }
public string TenantCode { get; set; } public string TenantCode { get; set; } = "";
public string TenantName { get; set; } = ""; public string TenantName { get; set; } = "";
public List<string> Roles { get; set; } = new(); public List<string> Roles { get; set; } = new();
public bool EmailConfirmed { get; set; } public bool EmailConfirmed { get; set; }

View File

@ -1,6 +1,7 @@
using System.Reflection; using System.Reflection;
using Fengling.Console.Repositories; using Fengling.Console.Repositories;
using Fengling.Console.Services; using Fengling.Console.Services;
using Fengling.Platform.Infrastructure.Repositories;
using OpenIddict.Abstractions; using OpenIddict.Abstractions;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;

View File

@ -1,17 +0,0 @@
using Fengling.Console.Models.Entities;
using Fengling.Platform.Domain.AggregatesModel.TenantAggregate;
namespace Fengling.Console.Repositories;
public interface ITenantRepository
{
Task<Tenant?> GetByIdAsync(long id);
Task<Tenant?> GetByTenantCodeAsync(string tenantCode);
Task<IEnumerable<Tenant>> GetAllAsync();
Task<IEnumerable<Tenant>> GetPagedAsync(int page, int pageSize, string? name = null, string? tenantCode = null, TenantStatus? status = null);
Task<int> CountAsync(string? name = null, string? tenantCode = null, TenantStatus? status = null);
Task AddAsync(Tenant tenant);
Task UpdateAsync(Tenant tenant);
Task DeleteAsync(Tenant tenant);
Task<int> GetUserCountAsync(TenantId tenantId);
}

View File

@ -1,97 +0,0 @@
using Fengling.Console.Datas;
using Fengling.Console.Models.Entities;
using Fengling.Platform.Domain.AggregatesModel.TenantAggregate;
using Fengling.Platform.Infrastructure;
using Microsoft.EntityFrameworkCore;
namespace Fengling.Console.Repositories;
public class TenantRepository(PlatformDbContext context,ApplicationDbContext identityDbContext) : ITenantRepository
{
public async Task<Tenant?> GetByIdAsync(long id)
{
return await context.Tenants.FindAsync(id);
}
public async Task<Platform.Domain.AggregatesModel.TenantAggregate.Tenant?> GetByTenantCodeAsync(string tenantCode)
{
return await context.Tenants.FirstOrDefaultAsync(t => t.TenantCode == tenantCode);
}
public async Task<IEnumerable<Tenant>> GetAllAsync()
{
return await context.Tenants.ToListAsync();
}
public async Task<IEnumerable<Tenant>> GetPagedAsync(int page, int pageSize, string? name = null,
string? tenantCode = null, TenantStatus? status = null)
{
var query = context.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();
}
public async Task<int> CountAsync(string? name = null, string? tenantCode = null, TenantStatus? status = null)
{
var query = context.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();
}
public async Task AddAsync(Tenant tenant)
{
context.Tenants.Add(tenant);
await context.SaveChangesAsync();
}
public async Task UpdateAsync(Tenant tenant)
{
context.Tenants.Update(tenant);
await context.SaveChangesAsync();
}
public async Task DeleteAsync(Tenant tenant)
{
context.Tenants.Remove(tenant);
await context.SaveChangesAsync();
}
public async Task<int> GetUserCountAsync(TenantId tenantId)
{
return await identityDbContext.Users.CountAsync(u => u.TenantInfo.TenantId == tenantId && !u.IsDeleted);
}
}

View File

@ -1,5 +1,6 @@
using Fengling.Console.Models.Entities; using Fengling.Console.Models.Entities;
using Fengling.Console.Repositories; using Fengling.Console.Repositories;
using Fengling.Platform.Infrastructure.Repositories;
using Fengling.Platform.Domain.AggregatesModel.TenantAggregate; using Fengling.Platform.Domain.AggregatesModel.TenantAggregate;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using QRCoder; using QRCoder;

View File

@ -45,10 +45,10 @@ public class OAuthClientService : IOAuthClientService
var clientIdValue = await _applicationManager.GetClientIdAsync(application); var clientIdValue = await _applicationManager.GetClientIdAsync(application);
var displayNameValue = await _applicationManager.GetDisplayNameAsync(application); var displayNameValue = await _applicationManager.GetDisplayNameAsync(application);
if (!string.IsNullOrEmpty(displayName) && !displayNameValue.Contains(displayName, StringComparison.OrdinalIgnoreCase)) if (!string.IsNullOrEmpty(displayName) && (string.IsNullOrEmpty(displayNameValue) || !displayNameValue.Contains(displayName, StringComparison.OrdinalIgnoreCase)))
continue; continue;
if (!string.IsNullOrEmpty(clientId) && !clientIdValue.Contains(clientId, StringComparison.OrdinalIgnoreCase)) if (!string.IsNullOrEmpty(clientId) && (string.IsNullOrEmpty(clientIdValue) || !clientIdValue.Contains(clientId, StringComparison.OrdinalIgnoreCase)))
continue; continue;
var clientType = await _applicationManager.GetClientTypeAsync(application); var clientType = await _applicationManager.GetClientTypeAsync(application);

View File

@ -1,5 +1,6 @@
using Fengling.Console.Models.Dtos; using Fengling.Console.Models.Dtos;
using Fengling.Console.Repositories; using Fengling.Console.Repositories;
using Fengling.Platform.Infrastructure.Repositories;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using System.Security.Claims; using System.Security.Claims;
using Fengling.Console.Datas; using Fengling.Console.Datas;

View File

@ -1,5 +1,6 @@
using Fengling.Console.Models.Dtos; using Fengling.Console.Models.Dtos;
using Fengling.Console.Repositories; using Fengling.Console.Repositories;
using Fengling.Platform.Infrastructure.Repositories;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using System.Security.Claims; using System.Security.Claims;
using Fengling.Console.Datas; using Fengling.Console.Datas;