RssFeedSource.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System.ComponentModel.DataAnnotations;
  2. namespace Domain.Entities.News
  3. {
  4. public class RssFeedSource
  5. {
  6. public virtual List<RssNewsArticle> RssNewsArticle { get; private set; } = [];
  7. [Key]
  8. public int ID { get; private set; }
  9. public string Name { get; private set; } = default!;
  10. public string Url { get; private set; } = default!;
  11. public string? Description { get; private set; }
  12. public int IntervalMinutes { get; private set; } = 10;
  13. public bool IsActive { get; private set; } = true;
  14. public DateTime? LastFetchedAt { get; private set; }
  15. public DateTime? UpdatedAt { get; private set; }
  16. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  17. private RssFeedSource() { }
  18. private RssFeedSource(string name, string url, string? description, int intervalMinutes)
  19. {
  20. if (string.IsNullOrWhiteSpace(name))
  21. {
  22. throw new ArgumentException("Name is required.", nameof(name));
  23. }
  24. if (name.Length > 200)
  25. {
  26. throw new ArgumentOutOfRangeException(nameof(name));
  27. }
  28. if (string.IsNullOrWhiteSpace(url))
  29. {
  30. throw new ArgumentException("Url is required.", nameof(url));
  31. }
  32. if (url.Length > 1000)
  33. {
  34. throw new ArgumentOutOfRangeException(nameof(url));
  35. }
  36. if (intervalMinutes < 1)
  37. {
  38. throw new ArgumentOutOfRangeException(nameof(intervalMinutes));
  39. }
  40. Name = name;
  41. Url = url;
  42. Description = description;
  43. IntervalMinutes = intervalMinutes;
  44. }
  45. public static RssFeedSource Create(string name, string url, string? description = null, int intervalMinutes = 10)
  46. => new(name, url, description, intervalMinutes);
  47. public void Update(string name, string url, string? description, int intervalMinutes, bool isActive)
  48. {
  49. if (string.IsNullOrWhiteSpace(name))
  50. {
  51. throw new ArgumentException("Name is required.", nameof(name));
  52. }
  53. if (name.Length > 200)
  54. {
  55. throw new ArgumentOutOfRangeException(nameof(name));
  56. }
  57. if (string.IsNullOrWhiteSpace(url))
  58. {
  59. throw new ArgumentException("Url is required.", nameof(url));
  60. }
  61. if (url.Length > 1000)
  62. {
  63. throw new ArgumentOutOfRangeException(nameof(url));
  64. }
  65. if (intervalMinutes < 1)
  66. {
  67. throw new ArgumentOutOfRangeException(nameof(intervalMinutes));
  68. }
  69. Name = name;
  70. Url = url;
  71. Description = description;
  72. IntervalMinutes = intervalMinutes;
  73. IsActive = isActive;
  74. UpdatedAt = DateTime.UtcNow;
  75. }
  76. public void MarkFetched()
  77. {
  78. LastFetchedAt = DateTime.UtcNow;
  79. }
  80. }
  81. }