features/cutover-to-ef #9

Merged
jtom38 merged 27 commits from features/cutover-to-ef into main 2023-06-25 21:15:58 -07:00
15 changed files with 186 additions and 184 deletions
Showing only changes of commit 0797fb8502 - Show all commits

View File

@ -43,7 +43,7 @@ public class ArticlesController : ControllerBase
public ArticleDetailsDto GetDetailsById(Guid id) public ArticleDetailsDto GetDetailsById(Guid id)
{ {
var item = _articles.GetById(id); var item = _articles.GetById(id);
var sourceItem = _sources.GetByID(item.SourceId); var sourceItem = _sources.GetById(item.SourceId);
return ArticleDetailsDto.Convert(item, sourceItem); return ArticleDetailsDto.Convert(item, sourceItem);
} }

View File

@ -3,6 +3,7 @@ using Microsoft.Extensions.Options;
using Newsbot.Collector.Database.Repositories; using Newsbot.Collector.Database.Repositories;
using Newsbot.Collector.Domain.Consts; using Newsbot.Collector.Domain.Consts;
using Newsbot.Collector.Domain.Dto; using Newsbot.Collector.Domain.Dto;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces; using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Models; using Newsbot.Collector.Domain.Models;
using Newsbot.Collector.Services.HtmlParser; using Newsbot.Collector.Services.HtmlParser;
@ -39,10 +40,10 @@ public class SourcesController : ControllerBase
} }
[HttpGet("by/type")] [HttpGet("by/type")]
public IEnumerable<SourceDto> GetByType(string type) public IEnumerable<SourceDto> GetByType(string type, int page)
{ {
var res = new List<SourceDto>(); var res = new List<SourceDto>();
var temp = _sources.ListByType(type); var temp = _sources.ListByType(type, page);
foreach (var item in temp) res.Add(SourceDto.Convert(item)); foreach (var item in temp) res.Add(SourceDto.Convert(item));
return res; return res;
} }
@ -51,7 +52,7 @@ public class SourcesController : ControllerBase
public SourceDto NewReddit(string name) public SourceDto NewReddit(string name)
{ {
var res = _sources.GetByNameAndType(name, SourceTypes.Reddit); var res = _sources.GetByNameAndType(name, SourceTypes.Reddit);
if (res.ID != Guid.Empty) return SourceDto.Convert(res); if (res.Id != Guid.Empty) return SourceDto.Convert(res);
var uri = new Uri($"https://reddit.com/r/{name}"); var uri = new Uri($"https://reddit.com/r/{name}");
@ -61,7 +62,7 @@ public class SourcesController : ControllerBase
}); });
pageReader.Parse(); pageReader.Parse();
var item = _sources.New(new SourceModel var item = _sources.New(new SourceEntity
{ {
Site = SourceTypes.Reddit, Site = SourceTypes.Reddit,
Name = name, Name = name,
@ -74,11 +75,11 @@ public class SourcesController : ControllerBase
// Not all subreddits have an Icon, so we only want to add a record when it has one. // Not all subreddits have an Icon, so we only want to add a record when it has one.
if (pageReader.Data.Header.Image != "") if (pageReader.Data.Header.Image != "")
_icons.New(new IconModel _icons.New(new IconEntity()
{ {
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
FileName = pageReader.Data.Header.Image, FileName = pageReader.Data.Header.Image,
SourceId = item.ID SourceId = item.Id
}); });
return SourceDto.Convert(item); return SourceDto.Convert(item);
} }
@ -87,9 +88,9 @@ public class SourcesController : ControllerBase
public SourceDto NewRss(string name, string url) public SourceDto NewRss(string name, string url)
{ {
var res = _sources.GetByNameAndType(name, SourceTypes.Rss); var res = _sources.GetByNameAndType(name, SourceTypes.Rss);
if (res.ID != Guid.Empty) return SourceDto.Convert(res); if (res.Id != Guid.Empty) return SourceDto.Convert(res);
var m = new SourceModel var m = new SourceEntity
{ {
Site = SourceTypes.Rss, Site = SourceTypes.Rss,
Name = name, Name = name,
@ -107,7 +108,7 @@ public class SourcesController : ControllerBase
public SourceDto NewYoutube(string url) public SourceDto NewYoutube(string url)
{ {
var res = _sources.GetByUrl(url); var res = _sources.GetByUrl(url);
if (res.ID != Guid.Empty) return SourceDto.Convert(res); if (res.Id != Guid.Empty) return SourceDto.Convert(res);
var htmlClient = new HtmlPageReader(new HtmlPageReaderOptions var htmlClient = new HtmlPageReader(new HtmlPageReaderOptions
{ {
@ -115,7 +116,7 @@ public class SourcesController : ControllerBase
}); });
htmlClient.Parse(); htmlClient.Parse();
var item = _sources.New(new SourceModel var item = _sources.New(new SourceEntity
{ {
Site = SourceTypes.YouTube, Site = SourceTypes.YouTube,
Type = SourceTypes.YouTube, Type = SourceTypes.YouTube,
@ -127,11 +128,11 @@ public class SourcesController : ControllerBase
YoutubeId = htmlClient.Data.Header.YoutubeChannelID ?? "" YoutubeId = htmlClient.Data.Header.YoutubeChannelID ?? ""
}); });
_icons.New(new IconModel _icons.New(new IconEntity()
{ {
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
FileName = htmlClient.Data.Header.Image, FileName = htmlClient.Data.Header.Image,
SourceId = item.ID SourceId = item.Id
}); });
return SourceDto.Convert(item); return SourceDto.Convert(item);
@ -141,9 +142,9 @@ public class SourcesController : ControllerBase
public SourceDto NewTwitch(string name) public SourceDto NewTwitch(string name)
{ {
var res = _sources.GetByNameAndType(name, SourceTypes.Twitch); var res = _sources.GetByNameAndType(name, SourceTypes.Twitch);
if (res.ID != Guid.Empty) return SourceDto.Convert(res); if (res.Id != Guid.Empty) return SourceDto.Convert(res);
var item = _sources.New(new SourceModel var item = _sources.New(new SourceEntity
{ {
Site = SourceTypes.Twitch, Site = SourceTypes.Twitch,
Type = SourceTypes.Twitch, Type = SourceTypes.Twitch,
@ -162,7 +163,7 @@ public class SourcesController : ControllerBase
//if (!url.Contains("github.com")) return new SourceDto(); //if (!url.Contains("github.com")) return new SourceDto();
var res = _sources.GetByUrl(url); var res = _sources.GetByUrl(url);
if (res.ID != Guid.Empty) return SourceDto.Convert(res); if (res.Id != Guid.Empty) return SourceDto.Convert(res);
var slice = url.Split('/'); var slice = url.Split('/');
@ -172,7 +173,7 @@ public class SourcesController : ControllerBase
}); });
pageReader.Parse(); pageReader.Parse();
var item = _sources.New(new SourceModel var item = _sources.New(new SourceEntity
{ {
Site = SourceTypes.CodeProject, Site = SourceTypes.CodeProject,
Type = SourceTypes.CodeProject, Type = SourceTypes.CodeProject,
@ -183,11 +184,11 @@ public class SourcesController : ControllerBase
Tags = $"{slice[2]},{slice[3]},{slice[4]}" Tags = $"{slice[2]},{slice[3]},{slice[4]}"
}); });
_icons.New(new IconModel _icons.New(new IconEntity()
{ {
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
FileName = pageReader.Data.Header.Image, FileName = pageReader.Data.Header.Image,
SourceId = item.ID SourceId = item.Id
}); });
return SourceDto.Convert(item); return SourceDto.Convert(item);
@ -196,7 +197,7 @@ public class SourcesController : ControllerBase
[HttpGet("{id}")] [HttpGet("{id}")]
public SourceDto GetById(Guid id) public SourceDto GetById(Guid id)
{ {
var item = _sources.GetByID(id); var item = _sources.GetById(id);
return SourceDto.Convert(item); return SourceDto.Convert(item);
} }

View File

@ -43,8 +43,8 @@ public class SubscriptionsController : ControllerBase
public SubscriptionDetailsDto GetDetailsById(Guid id) public SubscriptionDetailsDto GetDetailsById(Guid id)
{ {
var sub = _subscription.GetById(id); var sub = _subscription.GetById(id);
var webhook = _discord.GetByID(sub.DiscordWebHookId); var webhook = _discord.GetById(sub.DiscordWebHookId);
var source = _sources.GetByID(sub.SourceId); var source = _sources.GetById(sub.SourceId);
return SubscriptionDetailsDto.Convert(sub, source, webhook); return SubscriptionDetailsDto.Convert(sub, source, webhook);
} }
@ -82,11 +82,11 @@ public class SubscriptionsController : ControllerBase
var exists = _subscription.GetByWebhookAndSource(discordId, sourceId); var exists = _subscription.GetByWebhookAndSource(discordId, sourceId);
if (exists.Id != Guid.Empty) return SubscriptionDto.Convert(exists); if (exists.Id != Guid.Empty) return SubscriptionDto.Convert(exists);
var discord = _discord.GetByID(discordId); var discord = _discord.GetById(discordId);
if (discord.ID == Guid.Empty) return new BadRequestResult(); if (discord.Id == Guid.Empty) return new BadRequestResult();
var source = _sources.GetByID(sourceId); var source = _sources.GetById(sourceId);
if (source.ID == Guid.Empty) return new BadRequestResult(); if (source.Id == Guid.Empty) return new BadRequestResult();
var item = _subscription.New(new SubscriptionModel var item = _subscription.New(new SubscriptionModel
{ {
@ -110,11 +110,11 @@ public class SubscriptionsController : ControllerBase
var exists = _subscription.GetByWebhookAndSource(discordId, sourceId); var exists = _subscription.GetByWebhookAndSource(discordId, sourceId);
if (exists.Id != Guid.Empty) return SubscriptionDto.Convert(exists); if (exists.Id != Guid.Empty) return SubscriptionDto.Convert(exists);
var discord = _discord.GetByID(discordId); var discord = _discord.GetById(discordId);
if (discord.ID == Guid.Empty) return new BadRequestResult(); if (discord.Id == Guid.Empty) return new BadRequestResult();
var source = _sources.GetByID(sourceId); var source = _sources.GetById(sourceId);
if (source.ID == Guid.Empty) return new BadRequestResult(); if (source.Id == Guid.Empty) return new BadRequestResult();
var sub = _subscription.New(new SubscriptionModel var sub = _subscription.New(new SubscriptionModel
{ {

View File

@ -1,6 +1,7 @@
using System.Data; using System.Data;
using Dapper; using Dapper;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces; using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Models; using Newsbot.Collector.Domain.Models;
using Npgsql; using Npgsql;
@ -23,157 +24,153 @@ public class SourcesTable : ISourcesRepository
_connectionString = connstr; _connectionString = connstr;
} }
public SourceModel New(SourceModel model) public SourceEntity New(SourceEntity model)
{ {
model.ID = Guid.NewGuid(); model.Id = Guid.NewGuid();
using var conn = OpenConnection(_connectionString); using var context = new DatabaseContext(_connectionString);
var query = context.Sources.Add(model);
"Insert Into Sources (ID, Site, Name, Source, Type, Value, Enabled, Url, Tags, YoutubeId) Values (@id ,@site,@name,@source,@type,@value,@enabled,@url,@tags,@youtubeid);"; try
conn.Execute(query, new
{ {
id = model.ID, context.SaveChanges();
model.Site, }
model.Name, catch (Exception ex)
model.Source, {
model.Type, Console.WriteLine($"Failed to save ");
model.Value, }
model.Enabled,
model.Url,
model.Tags,
model.YoutubeId
});
return model; return model;
} }
public SourceModel GetByID(Guid ID) public SourceEntity GetById(Guid id)
{ {
using var conn = OpenConnection(_connectionString); using var context = new DatabaseContext(_connectionString);
var query = "Select * From Sources where ID = @id Limit 1;"; var res = context.Sources.FirstOrDefault(f => f.Id.Equals(id));
var res = conn.Query<SourceModel>(query, new res ??= new SourceEntity();
{ return res;
id = ID
});
if (res.Count() == 0) return new SourceModel();
return res.First();
} }
public SourceModel GetByID(string ID) public SourceEntity GetById(string id)
{ {
var uid = Guid.Parse(ID); var uid = Guid.Parse(id);
return GetByID(uid); return GetById(uid);
} }
public SourceModel GetByName(string Name) public SourceEntity GetByName(string name)
{ {
using var conn = OpenConnection(_connectionString); using var context = new DatabaseContext(_connectionString);
var query = "Select * from Sources where name = @name Limit 1;"; var res = context.Sources.FirstOrDefault(f => f.Name.Equals(name));
var res = conn.Query<SourceModel>(query, new res ??= new SourceEntity();
{ return res;
name = Name
});
if (res.Count() == 0) return new SourceModel();
return res.First();
} }
public SourceModel GetByNameAndType(string name, string type) public SourceEntity GetByNameAndType(string name, string type)
{ {
using var conn = OpenConnection(_connectionString); using var context = new DatabaseContext(_connectionString);
var query = "Select * from Sources WHERE name = @name and type = @type;"; var res = context.Sources
var res = conn.Query<SourceModel>(query, new .Where(f => f.Name.Equals(name))
{ .FirstOrDefault(f => f.Type.Equals(type));
name, type res ??= new SourceEntity();
}); return res;
if (res.Count() == 0) return new SourceModel();
return res.First();
} }
public SourceModel GetByUrl(string url) public SourceEntity GetByUrl(string url)
{ {
using var conn = OpenConnection(_connectionString); using var context = new DatabaseContext(_connectionString);
var query = "Select * from Sources WHERE url = @url;"; var res = context.Sources
var res = conn.Query<SourceModel>(query, new .FirstOrDefault(f => f.Url.Equals(url));
{ res ??= new SourceEntity();
url return res;
});
if (res.ToList().Count == 0) return new SourceModel();
return res.First();
} }
public List<SourceModel> List(int page = 0, int count = 25) public List<SourceEntity> List(int page = 0, int count = 100)
{ {
using var conn = OpenConnection(_connectionString); using var context = new DatabaseContext(_connectionString);
var query = @"Select * From Sources var res = context.Sources
Offset @page .Skip(page * count)
Fetch Next @count Rows Only;"; .Take(count)
return conn.Query<SourceModel>(query, new .ToList();
{ return res;
page = page * count, count
}).ToList();
} }
public List<SourceModel> ListBySource(string source, int limit = 25) public List<SourceEntity> ListBySource(string source, int page = 0, int limit = 25)
{ {
using var conn = OpenConnection(_connectionString); using var context = new DatabaseContext(_connectionString);
var query = "Select * From Sources where Source = @source Limit @limit;"; var res = context.Sources
return conn.Query<SourceModel>(query, new .Where(f => f.Source.Equals(source))
{ .Skip(page * limit)
source, limit .Take(limit)
}).ToList(); .ToList();
return res;
} }
public List<SourceModel> ListByType(string type, int limit = 25) public List<SourceEntity> ListByType(string type,int page = 0, int limit = 25)
{ {
using var conn = OpenConnection(_connectionString); using var context = new DatabaseContext(_connectionString);
var query = "Select * From Sources where Type = @type Limit @limit;"; var res = context.Sources
return conn.Query<SourceModel>(query, new .Where(f => f.Type.Equals(type))
{ .Skip(page * limit)
type, limit .Take(limit)
}).ToList(); .ToList();
return res;
} }
public int Disable(Guid id) public int Disable(Guid id)
{ {
using var conn = OpenConnection(_connectionString); using var context = new DatabaseContext(_connectionString);
var query = "Update Sources Set Enabled = FALSE where ID = @id;"; var res = GetById(id);
return conn.Execute(query, new res.Enabled = false;
context.Sources.Update(res);
try
{ {
id context.SaveChanges();
}); return 1;
}
catch
{
return 0;
}
} }
public int Enable(Guid id) public int Enable(Guid id)
{ {
using var conn = OpenConnection(_connectionString); using var context = new DatabaseContext(_connectionString);
var query = "Update Sources Set Enabled = TRUE where ID = @id;"; var res = GetById(id);
return conn.Execute(query, new res.Enabled = true;
context.Sources.Update(res);
try
{ {
id context.SaveChanges();
}); return 1;
}
catch
{
return 0;
}
} }
public void Delete(Guid id) public void Delete(Guid id)
{ {
using var conn = OpenConnection(_connectionString); using var context = new DatabaseContext(_connectionString);
var query = "Delete From sources where id = @id;"; var res = GetById(id);
var res = conn.Execute(query, new context.Sources.Remove(res);
{ context.SaveChanges();
id
});
if (res == 0) throw new Exception("Nothing was deleted");
} }
public int UpdateYoutubeId(Guid id, string youtubeId) public int UpdateYoutubeId(Guid id, string youtubeId)
{ {
using var conn = OpenConnection(_connectionString); using var context = new DatabaseContext(_connectionString);
var query = "Update Sources Set youtubeid = @youtubeId where ID = @id;"; var res = GetById(id);
return conn.Execute(query, new res.YoutubeId = youtubeId;
context.Sources.Update(res);
try
{ {
id, youtubeId context.SaveChanges();
}); return 1;
}
catch
{
return 0;
}
} }
private IDbConnection OpenConnection(string connectionString) private IDbConnection OpenConnection(string connectionString)

View File

@ -20,7 +20,7 @@ public class ArticleDetailsDto
public SourceDto? Source { get; set; } public SourceDto? Source { get; set; }
public static ArticleDetailsDto Convert(ArticlesEntity article, SourceModel source) public static ArticleDetailsDto Convert(ArticlesEntity article, SourceEntity source)
{ {
return new ArticleDetailsDto return new ArticleDetailsDto
{ {

View File

@ -1,4 +1,5 @@
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models; using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Dto; namespace Newsbot.Collector.Domain.Dto;
@ -16,10 +17,10 @@ public class SourceDto
public string[]? Tags { get; set; } public string[]? Tags { get; set; }
public bool Deleted { get; set; } public bool Deleted { get; set; }
public static SourceDto Convert(SourceModel model) { public static SourceDto Convert(SourceEntity model) {
return new SourceDto return new SourceDto
{ {
ID = model.ID, ID = model.Id,
Site = model.Site, Site = model.Site,
Name = model.Name, Name = model.Name,
Source = model.Source, Source = model.Source,

View File

@ -1,3 +1,4 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models; using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Dto; namespace Newsbot.Collector.Domain.Dto;
@ -10,8 +11,8 @@ public class SubscriptionDetailsDto
public SourceDto? Source { get; set; } public SourceDto? Source { get; set; }
public DiscordWebHookDto? DiscordWebHook { get; set; } public DiscordWebHookDto? DiscordWebHook { get; set; }
public static SubscriptionDetailsDto Convert(SubscriptionModel subscription, SourceModel source, public static SubscriptionDetailsDto Convert(SubscriptionModel subscription, SourceEntity source,
DiscordWebHookModel discord) DiscordWebhookEntity discord)
{ {
return new SubscriptionDetailsDto return new SubscriptionDetailsDto
{ {

View File

@ -1,18 +1,19 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models; using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Interfaces; namespace Newsbot.Collector.Domain.Interfaces;
public interface ISourcesRepository public interface ISourcesRepository
{ {
public SourceModel New(SourceModel model); public SourceEntity New(SourceEntity model);
public SourceModel GetByID(Guid ID); public SourceEntity GetById(Guid id);
public SourceModel GetByID(string ID); public SourceEntity GetById(string id);
public SourceModel GetByName(string name); public SourceEntity GetByName(string name);
public SourceModel GetByNameAndType(string name, string type); public SourceEntity GetByNameAndType(string name, string type);
SourceModel GetByUrl(string url); SourceEntity GetByUrl(string url);
public List<SourceModel> List(int page, int count); public List<SourceEntity> List(int page, int count);
public List<SourceModel> ListBySource(string source, int limit); public List<SourceEntity> ListBySource(string source,int page, int limit);
public List<SourceModel> ListByType(string type, int limit = 25); public List<SourceEntity> ListByType(string type,int page, int limit = 25);
public int Disable(Guid id); public int Disable(Guid id);
public int Enable(Guid id); public int Enable(Guid id);
public void Delete(Guid id); public void Delete(Guid id);

View File

@ -61,7 +61,7 @@ public class CodeProjectWatcherJob
private void Execute() private void Execute()
{ {
var sources = _source.ListByType(SourceTypes.CodeProject); var sources = _source.ListByType(SourceTypes.CodeProject, 0, 100);
// query sources for things to pull // query sources for things to pull
var items = new List<ArticlesEntity>(); var items = new List<ArticlesEntity>();
@ -82,7 +82,7 @@ public class CodeProjectWatcherJob
} }
} }
public IEnumerable<ArticlesEntity> CheckForReleases(SourceModel source) public IEnumerable<ArticlesEntity> CheckForReleases(SourceEntity source)
{ {
var url = new Uri(source.Url); var url = new Uri(source.Url);
var links = new List<string> var links = new List<string>
@ -114,7 +114,7 @@ public class CodeProjectWatcherJob
return new List<ArticlesEntity>(); return new List<ArticlesEntity>();
} }
public IEnumerable<ArticlesEntity> CheckForCommits(SourceModel source) public IEnumerable<ArticlesEntity> CheckForCommits(SourceEntity source)
{ {
var url = new Uri(source.Url); var url = new Uri(source.Url);
var links = new List<string> var links = new List<string>
@ -140,7 +140,7 @@ public class CodeProjectWatcherJob
return new List<ArticlesEntity>(); return new List<ArticlesEntity>();
} }
private IEnumerable<ArticlesEntity> ProcessFeed(IEnumerable<SyndicationItem> feed, SourceModel source, private IEnumerable<ArticlesEntity> ProcessFeed(IEnumerable<SyndicationItem> feed, SourceEntity source,
bool isRelease, bool isCommit) bool isRelease, bool isCommit)
{ {
var items = new List<ArticlesEntity>(); var items = new List<ArticlesEntity>();
@ -159,7 +159,7 @@ public class CodeProjectWatcherJob
var a = new ArticlesEntity var a = new ArticlesEntity
{ {
SourceId = source.ID, SourceId = source.Id,
Tags = source.Tags, Tags = source.Tags,
Title = item.Title.Text, Title = item.Title.Text,
Url = itemUrl, Url = itemUrl,

View File

@ -91,8 +91,8 @@ public class DiscordNotificationJob
var articleDetails = _article.GetById(request.ArticleId); var articleDetails = _article.GetById(request.ArticleId);
// Get the details of the source // Get the details of the source
var sourceDetails = _sources.GetByID(articleDetails.SourceId); var sourceDetails = _sources.GetById(articleDetails.SourceId);
if (sourceDetails.ID == Guid.Empty) if (sourceDetails.Id == Guid.Empty)
{ {
_logger.Error( _logger.Error(
$"{JobName} - Article ({articleDetails.Id}) was linked to a empty Source ID. Removing from the queue."); $"{JobName} - Article ({articleDetails.Id}) was linked to a empty Source ID. Removing from the queue.");
@ -100,19 +100,19 @@ public class DiscordNotificationJob
return; return;
} }
var sourceIcon = new IconModel(); var sourceIcon = new IconEntity();
try try
{ {
sourceIcon = _icons.GetBySourceId(sourceDetails.ID); sourceIcon = _icons.GetBySourceId(sourceDetails.Id);
} }
catch catch
{ {
_logger.Warning("{JobName} - Source ID \'{SourceDetailsId}\' is missing an icon", JobName, _logger.Warning("{JobName} - Source ID \'{SourceDetailsId}\' is missing an icon", JobName,
sourceDetails.ID); sourceDetails.Id);
} }
// Find all the subscriptions for that source // Find all the subscriptions for that source
var allSubscriptions = _subs.ListBySourceID(sourceDetails.ID); var allSubscriptions = _subs.ListBySourceID(sourceDetails.Id);
foreach (var sub in allSubscriptions) foreach (var sub in allSubscriptions)
SendSubscriptionNotification(request.Id, articleDetails, sourceDetails, sourceIcon, sub); SendSubscriptionNotification(request.Id, articleDetails, sourceDetails, sourceIcon, sub);
@ -121,8 +121,7 @@ public class DiscordNotificationJob
_queue.Delete(request.Id); _queue.Delete(request.Id);
} }
public void SendSubscriptionNotification(Guid requestId, ArticlesEntity articleDetails, SourceModel sourceDetails, public void SendSubscriptionNotification(Guid requestId, ArticlesEntity articleDetails, SourceEntity sourceDetails, IconEntity sourceIcon, SubscriptionModel sub)
IconModel sourceIcon, SubscriptionModel sub)
{ {
// Check if the subscription code flags // Check if the subscription code flags
// If the article is a code commit and the subscription does not want them, skip. // If the article is a code commit and the subscription does not want them, skip.
@ -145,14 +144,14 @@ public class DiscordNotificationJob
_logger.Error("Failed to post message to Discord. {ErrorMessage}", e.Message); _logger.Error("Failed to post message to Discord. {ErrorMessage}", e.Message);
_logger.Debug("Queue Record: {RequestId}", requestId); _logger.Debug("Queue Record: {RequestId}", requestId);
_logger.Debug("Article: {ArticleDetailsId}", articleDetails.Id); _logger.Debug("Article: {ArticleDetailsId}", articleDetails.Id);
_logger.Debug("Source: {SourceDetailsId}", sourceDetails.ID); _logger.Debug("Source: {SourceDetailsId}", sourceDetails.Id);
_logger.Debug("Subscription: {SubId}", sub.Id); _logger.Debug("Subscription: {SubId}", sub.Id);
} }
Thread.Sleep(3000); Thread.Sleep(3000);
} }
public DiscordMessage GenerateDiscordMessage(SourceModel source, ArticlesEntity article, IconModel icon) public DiscordMessage GenerateDiscordMessage(SourceEntity source, ArticlesEntity article, IconEntity icon)
{ {
var embed = new DiscordMessageEmbed var embed = new DiscordMessageEmbed
{ {

View File

@ -60,14 +60,14 @@ public class RssWatcherJob
var articles = new List<ArticlesEntity>(); var articles = new List<ArticlesEntity>();
_logger.Information($"{JobName} - Requesting sources"); _logger.Information($"{JobName} - Requesting sources");
var sources = _source.ListByType(SourceTypes.Rss); var sources = _source.ListByType(SourceTypes.Rss, 0, 100);
_logger.Information("{JobName} - Got {SourcesCount} back", JobName, sources.Count); _logger.Information("{JobName} - Got {SourcesCount} back", JobName, sources.Count);
foreach (var source in sources) foreach (var source in sources)
{ {
_logger.Information("{JobName} - Starting to process \'{SourceName}\'", JobName, source.Name); _logger.Information("{JobName} - Starting to process \'{SourceName}\'", JobName, source.Name);
_logger.Information($"{JobName} - Starting to request feed to be processed"); _logger.Information($"{JobName} - Starting to request feed to be processed");
var results = Collect(source.Url, source.ID); var results = Collect(source.Url, source.Id);
_logger.Information($"{JobName} - Collected {results.Count} posts"); _logger.Information($"{JobName} - Collected {results.Count} posts");
articles.AddRange(results); articles.AddRange(results);

View File

@ -67,11 +67,11 @@ public class YoutubeWatcherJob
if (channelId == "") if (channelId == "")
{ {
channelId = GetChannelId(source.Url); channelId = GetChannelId(source.Url);
_source.UpdateYoutubeId(source.ID, channelId); _source.UpdateYoutubeId(source.Id, channelId);
} }
// Make sure we have a Icon for the channel // Make sure we have a Icon for the channel
var icon = _icons.GetBySourceId(source.ID); var icon = _icons.GetBySourceId(source.Id);
if (icon.Id == Guid.Empty) Console.WriteLine("I was triggered :V"); if (icon.Id == Guid.Empty) Console.WriteLine("I was triggered :V");
_logger.Information($"{JobName} - Checking '{source.Name}'"); _logger.Information($"{JobName} - Checking '{source.Name}'");
@ -110,7 +110,7 @@ public class YoutubeWatcherJob
return id; return id;
} }
private List<ArticlesEntity> CheckFeed(string url, SourceModel source) private List<ArticlesEntity> CheckFeed(string url, SourceEntity source)
{ {
var videos = new List<ArticlesEntity>(); var videos = new List<ArticlesEntity>();
@ -137,7 +137,7 @@ public class YoutubeWatcherJob
PubDate = post.PublishDate.DateTime, PubDate = post.PublishDate.DateTime,
Thumbnail = videoDetails.Data.Header.Image, Thumbnail = videoDetails.Data.Header.Image,
Description = videoDetails.Data.Header.Description, Description = videoDetails.Data.Header.Description,
SourceId = source.ID, SourceId = source.Id,
Video = "true" Video = "true"
}; };

View File

@ -1,5 +1,6 @@
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Newsbot.Collector.Domain.Consts; using Newsbot.Collector.Domain.Consts;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models; using Newsbot.Collector.Domain.Models;
using Newsbot.Collector.Domain.Models.Config; using Newsbot.Collector.Domain.Models.Config;
using Newsbot.Collector.Services.Jobs; using Newsbot.Collector.Services.Jobs;
@ -18,9 +19,9 @@ public class CodeProjectWatcherJobTests
FeaturePullCommits = true, FeaturePullCommits = true,
FeaturePullReleases = true FeaturePullReleases = true
}); });
var results = client.CheckForReleases(new SourceModel var results = client.CheckForReleases(new SourceEntity
{ {
ID = Guid.NewGuid(), Id = Guid.NewGuid(),
Url = "https://github.com/jtom38/dvb", Url = "https://github.com/jtom38/dvb",
Type = SourceTypes.CodeProject, Type = SourceTypes.CodeProject,
Site = SourceTypes.CodeProject, Site = SourceTypes.CodeProject,
@ -44,9 +45,9 @@ public class CodeProjectWatcherJobTests
FeaturePullCommits = true, FeaturePullCommits = true,
FeaturePullReleases = true FeaturePullReleases = true
}); });
var results = client.CheckForReleases(new SourceModel var results = client.CheckForReleases(new SourceEntity
{ {
ID = Guid.NewGuid(), Id = Guid.NewGuid(),
Url = "https://github.com/python/cpython", Url = "https://github.com/python/cpython",
Type = SourceTypes.CodeProject, Type = SourceTypes.CodeProject,
Site = SourceTypes.CodeProject, Site = SourceTypes.CodeProject,
@ -70,9 +71,9 @@ public class CodeProjectWatcherJobTests
FeaturePullCommits = true, FeaturePullCommits = true,
FeaturePullReleases = true FeaturePullReleases = true
}); });
var results = client.CheckForCommits(new SourceModel var results = client.CheckForCommits(new SourceEntity
{ {
ID = Guid.NewGuid(), Id = Guid.NewGuid(),
Url = "https://github.com/jtom38/dvb", Url = "https://github.com/jtom38/dvb",
Type = SourceTypes.CodeProject, Type = SourceTypes.CodeProject,
Site = SourceTypes.CodeProject, Site = SourceTypes.CodeProject,

View File

@ -14,9 +14,9 @@ public class DiscordNotificationJobTest
var webhookClient = new DiscordWebhookClient(uri); var webhookClient = new DiscordWebhookClient(uri);
var client = new DiscordNotificationJob(); var client = new DiscordNotificationJob();
var msg = client.GenerateDiscordMessage(new SourceModel var msg = client.GenerateDiscordMessage(new SourceEntity
{ {
ID = Guid.NewGuid(), Id = Guid.NewGuid(),
Site = "Unit Test", Site = "Unit Test",
Source = "placeholder", Source = "placeholder",
Type = "a", Type = "a",
@ -35,7 +35,7 @@ public class DiscordNotificationJobTest
Description = "Please work", Description = "Please work",
AuthorName = "No one knows" AuthorName = "No one knows"
}, },
new IconModel new IconEntity()
{ {
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
FileName = "https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png" FileName = "https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png"
@ -63,9 +63,9 @@ public class DiscordNotificationJobTest
AuthorName = "No one knows", AuthorName = "No one knows",
CodeIsCommit = true CodeIsCommit = true
}, },
new SourceModel new SourceEntity
{ {
ID = Guid.NewGuid(), Id = Guid.NewGuid(),
Site = "Unit Test", Site = "Unit Test",
Source = "placeholder", Source = "placeholder",
Type = "a", Type = "a",
@ -74,7 +74,7 @@ public class DiscordNotificationJobTest
Url = "https://github.com", Url = "https://github.com",
Tags = "Unit, Testing" Tags = "Unit, Testing"
}, },
new IconModel new IconEntity()
{ {
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
FileName = "https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png" FileName = "https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png"

View File

@ -1,4 +1,5 @@
using Newsbot.Collector.Database.Repositories; using Newsbot.Collector.Database.Repositories;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models; using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Tests.Tables; namespace Newsbot.Collector.Tests.Tables;
@ -9,9 +10,9 @@ public class SourcesTableTests
public void NewRecordTest() public void NewRecordTest()
{ {
var client = new SourcesTable(""); var client = new SourcesTable("");
var m = new SourceModel var m = new SourceEntity
{ {
ID = Guid.NewGuid(), Id = Guid.NewGuid(),
Site = "Testing", Site = "Testing",
Name = "Testing", Name = "Testing",
Source = "Testing", Source = "Testing",