| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using System.ComponentModel.DataAnnotations;
- namespace Domain.Entities.News
- {
- public class RssFeedSource
- {
- public virtual List<RssNewsArticle> RssNewsArticle { get; private set; } = [];
- [Key]
- public int ID { get; private set; }
- public string Name { get; private set; } = default!;
- public string Url { get; private set; } = default!;
- public string? Description { get; private set; }
- public int IntervalMinutes { get; private set; } = 10;
- public bool IsActive { get; private set; } = true;
- public DateTime? LastFetchedAt { get; private set; }
- public DateTime? UpdatedAt { get; private set; }
- public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
- private RssFeedSource() { }
- private RssFeedSource(string name, string url, string? description, int intervalMinutes)
- {
- if (string.IsNullOrWhiteSpace(name))
- {
- throw new ArgumentException("Name is required.", nameof(name));
- }
- if (name.Length > 200)
- {
- throw new ArgumentOutOfRangeException(nameof(name));
- }
- if (string.IsNullOrWhiteSpace(url))
- {
- throw new ArgumentException("Url is required.", nameof(url));
- }
- if (url.Length > 1000)
- {
- throw new ArgumentOutOfRangeException(nameof(url));
- }
- if (intervalMinutes < 1)
- {
- throw new ArgumentOutOfRangeException(nameof(intervalMinutes));
- }
- Name = name;
- Url = url;
- Description = description;
- IntervalMinutes = intervalMinutes;
- }
- public static RssFeedSource Create(string name, string url, string? description = null, int intervalMinutes = 10)
- => new(name, url, description, intervalMinutes);
- public void Update(string name, string url, string? description, int intervalMinutes, bool isActive)
- {
- if (string.IsNullOrWhiteSpace(name))
- {
- throw new ArgumentException("Name is required.", nameof(name));
- }
- if (name.Length > 200)
- {
- throw new ArgumentOutOfRangeException(nameof(name));
- }
- if (string.IsNullOrWhiteSpace(url))
- {
- throw new ArgumentException("Url is required.", nameof(url));
- }
- if (url.Length > 1000)
- {
- throw new ArgumentOutOfRangeException(nameof(url));
- }
- if (intervalMinutes < 1)
- {
- throw new ArgumentOutOfRangeException(nameof(intervalMinutes));
- }
- Name = name;
- Url = url;
- Description = description;
- IntervalMinutes = intervalMinutes;
- IsActive = isActive;
- UpdatedAt = DateTime.UtcNow;
- }
- public void MarkFetched()
- {
- LastFetchedAt = DateTime.UtcNow;
- }
- }
- }
|