ChannelBroadcastStats.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.ComponentModel.DataAnnotations;
  2. using System.ComponentModel.DataAnnotations.Schema;
  3. namespace Domain.Entities.Members;
  4. /// <summary>
  5. /// 채널별 누적 방송 지표 (매일 자정 재계산)
  6. /// </summary>
  7. public sealed class ChannelBroadcastStats
  8. {
  9. [ForeignKey(nameof(ChannelID))]
  10. public Channel Channel { get; private set; } = null!;
  11. [Key]
  12. public int ChannelID { get; private set; }
  13. public long TotalDurationSec { get; private set; }
  14. public long CumulativeViews { get; private set; }
  15. public long TotalLikes { get; private set; }
  16. public int SessionCount { get; private set; }
  17. public DateTime? LastBroadcastAt { get; private set; }
  18. public DateTime? LastAggregatedAt { get; private set; }
  19. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  20. private ChannelBroadcastStats() { }
  21. private ChannelBroadcastStats(int channelID)
  22. {
  23. if (channelID <= 0)
  24. {
  25. throw new ArgumentOutOfRangeException(nameof(channelID));
  26. }
  27. ChannelID = channelID;
  28. }
  29. public static ChannelBroadcastStats Create(int channelID)
  30. {
  31. return new(channelID);
  32. }
  33. public void Update(long totalDurationSec, long cumulativeViews, long totalLikes, int sessionCount, DateTime? lastBroadcastAt)
  34. {
  35. TotalDurationSec = totalDurationSec;
  36. CumulativeViews = cumulativeViews;
  37. TotalLikes = totalLikes;
  38. SessionCount = sessionCount;
  39. LastBroadcastAt = lastBroadcastAt;
  40. LastAggregatedAt = DateTime.UtcNow;
  41. }
  42. }