Files
tiku-backend.net/Tiku.Infrastructure/ContentV2/PlatformContentActorResolver.cs
xiong 3f5957d744
Some checks failed
ci / release-gate (push) Has been cancelled
feat(content): establish v2 learning delivery foundation
2026-08-06 09:52:18 +08:00

42 lines
1.6 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Tiku.Application.Content;
using Tiku.Application.Security;
using Tiku.Domain.Tenancy;
using Tiku.Infrastructure.Persistence;
namespace Tiku.Infrastructure.ContentV2;
internal sealed class PlatformContentActorResolver(ITenantExecutionScope tenantExecutionScope)
: IPlatformContentActorResolver
{
public Task<ContentAuthorActor> ResolveAsync(
Guid userId,
CancellationToken cancellationToken = default)
{
return tenantExecutionScope.ExecuteAsync(
new SystemScopeRequest(
null,
SystemScopeCallerType.Platform,
nameof(PlatformContentActorResolver),
"Resolve the single platform-owned V2 content owner",
Guid.NewGuid().ToString("N"),
true),
async (provider, token) =>
{
var tenancy = provider.GetRequiredService<ITenancyPersistence>();
var ownerIds = await tenancy.Tenants.AsNoTracking()
.Where(item => item.Mode == TenantMode.PlatformOwned && item.Status == TenantStatus.Active)
.Select(item => item.Id)
.Take(2)
.ToArrayAsync(token);
if (ownerIds.Length != 1)
throw new ContentV2Exception(
"platform_content_owner_invalid",
"Exactly one active platform content owner is required.");
return new ContentAuthorActor(ownerIds[0], userId);
},
cancellationToken);
}
}