RankingSnapshot.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System.ComponentModel.DataAnnotations;
  2. using System.ComponentModel.DataAnnotations.Schema;
  3. using Domain.Entities.Donations.ValueObject;
  4. using Domain.Entities.Members;
  5. namespace Domain.Entities.Donations;
  6. /// <summary>
  7. /// 랭킹 스냅샷 — 매일 자정 00:00 배치로 생성
  8. /// </summary>
  9. public sealed class RankingSnapshot
  10. {
  11. [ForeignKey(nameof(MemberID))]
  12. public Member? Member { get; private set; }
  13. [Key]
  14. public int ID { get; private set; }
  15. public RankingType Type { get; private set; }
  16. public RankingPeriod Period { get; private set; }
  17. public DateTime PeriodStart { get; private set; }
  18. public DateTime PeriodEnd { get; private set; }
  19. public string? Category { get; private set; }
  20. public int MemberID { get; private set; }
  21. public int Rank { get; private set; }
  22. public int? PreviousRank { get; private set; }
  23. public long Score { get; private set; }
  24. public long MoneyAmount { get; private set; }
  25. public int DonorCount { get; private set; }
  26. public long BroadcastSec { get; private set; }
  27. public long ViewCount { get; private set; }
  28. public long LikeCount { get; private set; }
  29. public DateTime SnapshotAt { get; private set; } = DateTime.UtcNow;
  30. private RankingSnapshot() { }
  31. public static RankingSnapshot Create(
  32. RankingType type,
  33. RankingPeriod period,
  34. DateTime periodStart,
  35. DateTime periodEnd,
  36. string? category,
  37. int memberID,
  38. int rank,
  39. long score,
  40. long moneyAmount,
  41. int donorCount,
  42. long broadcastSec,
  43. long viewCount,
  44. long likeCount,
  45. int? previousRank
  46. ) {
  47. if (memberID <= 0)
  48. {
  49. throw new ArgumentOutOfRangeException(nameof(memberID));
  50. }
  51. if (rank <= 0)
  52. {
  53. throw new ArgumentOutOfRangeException(nameof(rank));
  54. }
  55. return new RankingSnapshot
  56. {
  57. Type = type,
  58. Period = period,
  59. PeriodStart = periodStart,
  60. PeriodEnd = periodEnd,
  61. Category = category,
  62. MemberID = memberID,
  63. Rank = rank,
  64. PreviousRank = previousRank,
  65. Score = score,
  66. MoneyAmount = moneyAmount,
  67. DonorCount = donorCount,
  68. BroadcastSec = broadcastSec,
  69. ViewCount = viewCount,
  70. LikeCount = likeCount,
  71. SnapshotAt = DateTime.UtcNow
  72. };
  73. }
  74. }