Coin.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using System.ComponentModel.DataAnnotations;
  2. namespace Domain.Entities.Crypto
  3. {
  4. public class Coin
  5. {
  6. public virtual List<CoinCategoryMap> CoinCategoryMap { get; private set; } = [];
  7. [Key]
  8. public int ID { get; private set; }
  9. public string Symbol { get; private set; } = default!;
  10. public string KorName { get; private set; } = default!;
  11. public string EngName { get; private set; } = default!;
  12. public string? LogoImage { get; private set; }
  13. public string? Description { get; private set; }
  14. public string? ContractAddress { get; private set; }
  15. public string? WebsiteUrl { get; private set; }
  16. public string? WhitepaperUrl { get; private set; }
  17. public string? TwitterUrl { get; private set; }
  18. public string? TelegramUrl { get; private set; }
  19. public bool IsActive { get; private set; } = false;
  20. public bool IsWarning { get; private set; } = false;
  21. public bool IsNew { get; private set; } = false;
  22. public bool IsDelisted { get; private set; } = false;
  23. public bool IsFeatured { get; private set; } = false;
  24. public short DisplayOrder { get; private set; } = 0;
  25. public DateTime? UpdatedAt { get; private set; }
  26. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  27. private Coin() { }
  28. private Coin(
  29. string symbol,
  30. string korName,
  31. string engName,
  32. string? description,
  33. string? contractAddress,
  34. string? websiteUrl,
  35. string? whitepaperUrl,
  36. string? twitterUrl,
  37. string? telegramUrl,
  38. bool isActive,
  39. bool isWarning,
  40. bool isNew,
  41. bool isDelisted
  42. ) {
  43. if (string.IsNullOrWhiteSpace(symbol))
  44. {
  45. throw new ArgumentException("Symbol is required.", nameof(symbol));
  46. }
  47. if (symbol.Length > 30)
  48. {
  49. throw new ArgumentOutOfRangeException(nameof(symbol));
  50. }
  51. if (string.IsNullOrWhiteSpace(korName))
  52. {
  53. throw new ArgumentException("KorName is required.", nameof(korName));
  54. }
  55. if (korName.Length > 200)
  56. {
  57. throw new ArgumentOutOfRangeException(nameof(korName));
  58. }
  59. if (string.IsNullOrWhiteSpace(engName))
  60. {
  61. throw new ArgumentException("EngName is required.", nameof(engName));
  62. }
  63. if (engName.Length > 200)
  64. {
  65. throw new ArgumentOutOfRangeException(nameof(engName));
  66. }
  67. Symbol = symbol.ToUpper();
  68. KorName = korName;
  69. EngName = engName;
  70. Description = description;
  71. ContractAddress = contractAddress;
  72. WebsiteUrl = websiteUrl;
  73. WhitepaperUrl = whitepaperUrl;
  74. TwitterUrl = twitterUrl;
  75. TelegramUrl = telegramUrl;
  76. IsActive = isActive;
  77. IsWarning = isWarning;
  78. IsNew = isNew;
  79. IsDelisted = isDelisted;
  80. }
  81. public static Coin Create(
  82. string symbol,
  83. string korName,
  84. string engName,
  85. string? description = null,
  86. string? contractAddress = null,
  87. string? websiteUrl = null,
  88. string? whitepaperUrl = null,
  89. string? twitterUrl = null,
  90. string? telegramUrl = null,
  91. bool isActive = false,
  92. bool isWarning = false,
  93. bool isNew = false,
  94. bool isDelisted = false
  95. ) => new(symbol, korName, engName, description, contractAddress, websiteUrl, whitepaperUrl, twitterUrl, telegramUrl, isActive, isWarning, isNew, isDelisted);
  96. public void Update(
  97. string symbol,
  98. string korName,
  99. string engName,
  100. string? description,
  101. string? contractAddress,
  102. string? websiteUrl,
  103. string? whitepaperUrl,
  104. string? twitterUrl,
  105. string? telegramUrl,
  106. bool isActive,
  107. bool isWarning,
  108. bool isNew,
  109. bool isDelisted
  110. ) {
  111. if (string.IsNullOrWhiteSpace(symbol))
  112. {
  113. throw new ArgumentException("Symbol is required.", nameof(symbol));
  114. }
  115. if (symbol.Length > 30)
  116. {
  117. throw new ArgumentOutOfRangeException(nameof(symbol));
  118. }
  119. if (string.IsNullOrWhiteSpace(korName))
  120. {
  121. throw new ArgumentException("KorName is required.", nameof(korName));
  122. }
  123. if (korName.Length > 200)
  124. {
  125. throw new ArgumentOutOfRangeException(nameof(korName));
  126. }
  127. if (string.IsNullOrWhiteSpace(engName))
  128. {
  129. throw new ArgumentException("EngName is required.", nameof(engName));
  130. }
  131. if (engName.Length > 200)
  132. {
  133. throw new ArgumentOutOfRangeException(nameof(engName));
  134. }
  135. Symbol = symbol.ToUpper();
  136. KorName = korName;
  137. EngName = engName;
  138. Description = description;
  139. ContractAddress = contractAddress;
  140. WebsiteUrl = websiteUrl;
  141. WhitepaperUrl = whitepaperUrl;
  142. TwitterUrl = twitterUrl;
  143. TelegramUrl = telegramUrl;
  144. IsActive = isActive;
  145. IsWarning = isWarning;
  146. IsNew = isNew;
  147. IsDelisted = isDelisted;
  148. UpdatedAt = DateTime.UtcNow;
  149. }
  150. public void SetLogoImage(string? logoImage)
  151. {
  152. LogoImage = logoImage;
  153. UpdatedAt = DateTime.UtcNow;
  154. }
  155. public void SetCuration(bool isFeatured, short displayOrder)
  156. {
  157. IsFeatured = isFeatured;
  158. DisplayOrder = displayOrder;
  159. UpdatedAt = DateTime.UtcNow;
  160. }
  161. }
  162. }