Files
tiku-backend.net/Tiku.Infrastructure/Learning/Access/StudentLearningCatalogService.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

51 lines
2.1 KiB
C#

using Microsoft.EntityFrameworkCore;
using Tiku.Application.Learning;
using Tiku.Infrastructure.Persistence;
namespace Tiku.Infrastructure.Learning;
internal sealed class StudentLearningCatalogService(
ILearningAccessPersistence access,
IEffectiveLearningAccessService effectiveAccess) : IStudentLearningCatalogService
{
public async Task<StudentLearningCatalogItem> GetAsync(
LearningActor actor,
Guid businessLineId,
CancellationToken cancellationToken = default)
{
var snapshot = await effectiveAccess.GetSnapshotAsync(actor, businessLineId, cancellationToken);
var manifestIds = snapshot.ManifestVersionIds.ToArray();
var rows = await access.ProductManifestResources.AsNoTracking()
.Where(item => item.TenantId == actor.TenantId &&
manifestIds.Contains(item.ProductAccessManifestVersionId))
.OrderBy(item => item.SortOrder)
.ThenBy(item => item.Id)
.ToArrayAsync(cancellationToken);
var resources = rows
.GroupBy(item => new { item.ResourceType, item.ResourceId })
.Select(group =>
{
var first = group.OrderBy(item => item.SortOrder).ThenBy(item => item.Id).First();
return new StudentCatalogResourceItem(
first.ResourceType,
first.ResourceId,
string.IsNullOrWhiteSpace(first.DisplayName)
? first.ResourceType.ToString()
: first.DisplayName,
first.SortOrder,
group.Select(item => item.ProductAccessManifestVersionId).Distinct().Order().ToArray());
})
.OrderBy(item => item.SortOrder)
.ThenBy(item => item.DisplayName)
.ThenBy(item => item.ResourceId)
.ToArray();
return new StudentLearningCatalogItem(
businessLineId,
snapshot.PrimaryProfileVersionId,
snapshot.AlternateProfileVersionIds.Order().ToArray(),
resources,
snapshot.GrantVersion,
snapshot.ContentVersion);
}
}