Discord Queue Entity updated

This commit is contained in:
James Tombleson 2023-06-23 20:19:09 -07:00
parent 7d176cb643
commit a6ea89be62
6 changed files with 32 additions and 36 deletions

View File

@ -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<DiscordQueueModel> List(int limit = 25)
public List<DiscordQueueEntity> List(int limit = 25)
{
using var conn = OpenConnection(_connectionString);
var query = "Select * from DiscordQueue LIMIT @limit;";
return conn.Query<DiscordQueueModel>(query, new {
limit = limit
}).ToList();
using var context = new DatabaseContext(_connectionString);
var res = context.DiscordQueue.Take(limit).ToList();
return res;
}
}

View File

@ -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<DiscordQueueModel> List(int limit);
List<DiscordQueueEntity> List(int limit);
}

View File

@ -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
});
}
}

View File

@ -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,

View File

@ -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
});
}
}

View File

@ -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
});
}
}