feat: add student video and profile experience

This commit is contained in:
2026-07-28 15:23:42 +08:00
parent 5e993298e7
commit 7a3cf09a99
31 changed files with 19821 additions and 170 deletions

View File

@@ -4,6 +4,7 @@ using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Tiku.Application.Points;
using Tiku.Domain.Commerce;
using Tiku.Domain.Learning;
using Tiku.Domain.Tenancy;
using Tiku.Infrastructure.Persistence;
@@ -125,6 +126,25 @@ public sealed class PointService(TikuDbContext dbContext) : IPointService
Metadata = JsonSerializer.SerializeToElement(new { source = "student_points" })
};
dbContext.PointActivityClaims.Add(claim);
var balanceAfter = (await GetSummaryCoreAsync(actor, cancellationToken)).BalancePoints + task.Points;
dbContext.UserScoreEvents.Add(new UserScoreEvent
{
TenantId = actor.TenantId,
UserId = actor.UserId,
EventType = task.TaskType == PointActivityTaskType.DailyLogin
? UserScoreEventType.CheckIn
: UserScoreEventType.ActivityReward,
Points = task.Points,
BalanceAfter = balanceAfter,
SourceType = NormalizeOptional(command.SourceType) ?? "point_task",
SourceId = command.SourceId ?? claim.Id,
IdempotencyKey = $"point-claim:{actor.TenantId:N}:{claim.Id:N}",
Metadata = JsonSerializer.SerializeToElement(new
{
task.Id,
task.TaskKey
})
});
await dbContext.SaveChangesAsync(cancellationToken);
return ToClaimItem(claim);
}
@@ -212,6 +232,23 @@ public sealed class PointService(TikuDbContext dbContext) : IPointService
Metadata = JsonSerializer.SerializeToElement(new { source = "student_points_exchange" })
};
dbContext.PointExchangeOrders.Add(order);
dbContext.UserScoreEvents.Add(new UserScoreEvent
{
TenantId = actor.TenantId,
UserId = actor.UserId,
EventType = UserScoreEventType.RedeemCost,
Points = -item.PointsCost,
BalanceAfter = balance - item.PointsCost,
SourceType = "point_exchange_order",
SourceId = order.Id,
IdempotencyKey = $"point-exchange:{actor.TenantId:N}:{order.Id:N}",
Metadata = JsonSerializer.SerializeToElement(new
{
item.Id,
item.ItemKey,
item.Name
})
});
if (item.ItemType == PointExchangeItemType.Entitlement)
{
await GrantEntitlementAsync(actor, item, order, now, cancellationToken);