diff --git a/Newsbot.Collector.Database/Repositories/DiscordQueue.cs b/Newsbot.Collector.Database/Repositories/DiscordQueue.cs index 233d8ac..ad77070 100644 --- a/Newsbot.Collector.Database/Repositories/DiscordQueue.cs +++ b/Newsbot.Collector.Database/Repositories/DiscordQueue.cs @@ -1,5 +1,6 @@ using System.Data; using Dapper; +using Newsbot.Collector.Domain.Entities; using Newsbot.Collector.Domain.Interfaces; using Newsbot.Collector.Domain.Models; using Npgsql; @@ -22,33 +23,28 @@ public class DiscordQueueTable : IDiscordQueueRepository return conn; } - public void New(DiscordQueueModel model) + public void New(DiscordQueueEntity model) { - using var conn = OpenConnection(_connectionString); - var query = "Insert into DiscordQueue(ID, ArticleId) Values (@id, @articleid);"; - conn.Execute(query, new - { - id = Guid.NewGuid(), - articleid = model.ArticleID - }); + model.Id = new Guid(); + + using var context = new DatabaseContext(_connectionString); + var res = context.DiscordQueue.Add(model); + context.SaveChanges(); } public void Delete(Guid id) { - using var conn = OpenConnection(_connectionString); - var query = "Delete From DiscordQueue Where ID = @id;"; - conn.Execute(query, new - { - id = id - }); + using var context = new DatabaseContext(_connectionString); + var res = context.DiscordQueue.FirstOrDefault(d => d.Id.Equals(id)); + res ??= new DiscordQueueEntity(); + context.DiscordQueue.Remove(res); + context.SaveChanges(); } - public List List(int limit = 25) + public List List(int limit = 25) { - using var conn = OpenConnection(_connectionString); - var query = "Select * from DiscordQueue LIMIT @limit;"; - return conn.Query(query, new { - limit = limit - }).ToList(); + using var context = new DatabaseContext(_connectionString); + var res = context.DiscordQueue.Take(limit).ToList(); + return res; } } \ No newline at end of file diff --git a/Newsbot.Collector.Domain/Interfaces/IDiscordQueueRepository.cs b/Newsbot.Collector.Domain/Interfaces/IDiscordQueueRepository.cs index 2af0c6d..4cba109 100644 --- a/Newsbot.Collector.Domain/Interfaces/IDiscordQueueRepository.cs +++ b/Newsbot.Collector.Domain/Interfaces/IDiscordQueueRepository.cs @@ -1,10 +1,10 @@ -using Newsbot.Collector.Domain.Models; +using Newsbot.Collector.Domain.Entities; namespace Newsbot.Collector.Domain.Interfaces; public interface IDiscordQueueRepository { - void New(DiscordQueueModel model); + void New(DiscordQueueEntity model); void Delete(Guid id); - List List(int limit); + List List(int limit); } \ No newline at end of file diff --git a/Newsbot.Collector.Services/Jobs/CodeProjectWatcherJob.cs b/Newsbot.Collector.Services/Jobs/CodeProjectWatcherJob.cs index 9904ab9..8b58df4 100644 --- a/Newsbot.Collector.Services/Jobs/CodeProjectWatcherJob.cs +++ b/Newsbot.Collector.Services/Jobs/CodeProjectWatcherJob.cs @@ -75,9 +75,9 @@ public class CodeProjectWatcherJob foreach (var item in items) { _articles.New(item); - _queue.New(new DiscordQueueModel + _queue.New(new DiscordQueueEntity() { - ArticleID = item.Id + ArticleId = item.Id }); } } diff --git a/Newsbot.Collector.Services/Jobs/DiscordNotificationJob.cs b/Newsbot.Collector.Services/Jobs/DiscordNotificationJob.cs index a933191..de090f8 100644 --- a/Newsbot.Collector.Services/Jobs/DiscordNotificationJob.cs +++ b/Newsbot.Collector.Services/Jobs/DiscordNotificationJob.cs @@ -84,11 +84,11 @@ public class DiscordNotificationJob _logger.Information($"{JobName} - Loop has been completed."); } - public void ProcessQueueItem(DiscordQueueModel request) + public void ProcessQueueItem(DiscordQueueEntity request) { - _logger.Debug($"{JobName} - Processing {request.ID}"); + _logger.Debug($"{JobName} - Processing {request.Id}"); // Get all details on the article in the queue - var articleDetails = _article.GetById(request.ArticleID); + var articleDetails = _article.GetById(request.ArticleId); // Get the details of the source var sourceDetails = _sources.GetByID(articleDetails.SourceId); @@ -96,7 +96,7 @@ public class DiscordNotificationJob { _logger.Error( $"{JobName} - Article ({articleDetails.Id}) was linked to a empty Source ID. Removing from the queue."); - _queue.Delete(request.ID); + _queue.Delete(request.Id); return; } @@ -115,10 +115,10 @@ public class DiscordNotificationJob var allSubscriptions = _subs.ListBySourceID(sourceDetails.ID); foreach (var sub in allSubscriptions) - SendSubscriptionNotification(request.ID, articleDetails, sourceDetails, sourceIcon, sub); + SendSubscriptionNotification(request.Id, articleDetails, sourceDetails, sourceIcon, sub); - _logger.Debug("{JobName} - Removing {RequestId} from the queue", JobName, request.ID); - _queue.Delete(request.ID); + _logger.Debug("{JobName} - Removing {RequestId} from the queue", JobName, request.Id); + _queue.Delete(request.Id); } public void SendSubscriptionNotification(Guid requestId, ArticlesEntity articleDetails, SourceModel sourceDetails, diff --git a/Newsbot.Collector.Services/Jobs/RssWatcherJob.cs b/Newsbot.Collector.Services/Jobs/RssWatcherJob.cs index 3641345..8548006 100644 --- a/Newsbot.Collector.Services/Jobs/RssWatcherJob.cs +++ b/Newsbot.Collector.Services/Jobs/RssWatcherJob.cs @@ -131,9 +131,9 @@ public class RssWatcherJob } var p = _articles.New(item); - _queue.New(new DiscordQueueModel + _queue.New(new DiscordQueueEntity { - ArticleID = p.Id + ArticleId = p.Id }); } } diff --git a/Newsbot.Collector.Services/Jobs/YoutubeWatcherJob.cs b/Newsbot.Collector.Services/Jobs/YoutubeWatcherJob.cs index e055ad0..8297684 100644 --- a/Newsbot.Collector.Services/Jobs/YoutubeWatcherJob.cs +++ b/Newsbot.Collector.Services/Jobs/YoutubeWatcherJob.cs @@ -83,9 +83,9 @@ public class YoutubeWatcherJob { _logger.Debug($"{JobName} - {video.AuthorName} '{video.Title}' was found"); _articles.New(video); - _queue.New(new DiscordQueueModel + _queue.New(new DiscordQueueEntity { - ArticleID = video.Id + ArticleId = video.Id }); } }