Compare commits
No commits in common. "52e86c01cea407f9c28bd7e74512b94572e86308" and "0797fb85029f2fd42e31a8e846d23365fe10222a" have entirely different histories.
52e86c01ce
...
0797fb8502
@ -1,4 +1,3 @@
|
||||
appsettings.json
|
||||
**/bin/**
|
||||
**/obj/**
|
||||
**/efbundle
|
||||
**/bin/
|
||||
**/obj/
|
@ -17,7 +17,7 @@ RUN dotnet publish -o build
|
||||
RUN ls build
|
||||
|
||||
FROM build as ef
|
||||
RUN dotnet tool install dotnet-ef --tool-path /usr/bin --version 7.0.8
|
||||
RUN dotnet tool install dotnet-ef --tool-path /usr/bin
|
||||
RUN dotnet ef migrations bundle --project "Newsbot.Collector.Database"
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0.3 as app
|
||||
|
@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newsbot.Collector.Database.Repositories;
|
||||
using Newsbot.Collector.Domain.Dto;
|
||||
using Newsbot.Collector.Domain.Entities;
|
||||
using Newsbot.Collector.Domain.Interfaces;
|
||||
using Newsbot.Collector.Domain.Models;
|
||||
|
||||
@ -69,7 +68,7 @@ public class SubscriptionsController : ControllerBase
|
||||
public IEnumerable<SubscriptionDto> GetBySourceId(Guid id)
|
||||
{
|
||||
var res = new List<SubscriptionDto>();
|
||||
var items = _subscription.ListBySourceId(id);
|
||||
var items = _subscription.ListBySourceID(id);
|
||||
foreach (var item in items) res.Add(SubscriptionDto.Convert(item));
|
||||
return res;
|
||||
}
|
||||
@ -89,7 +88,7 @@ public class SubscriptionsController : ControllerBase
|
||||
var source = _sources.GetById(sourceId);
|
||||
if (source.Id == Guid.Empty) return new BadRequestResult();
|
||||
|
||||
var item = _subscription.New(new SubscriptionEntity
|
||||
var item = _subscription.New(new SubscriptionModel
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
SourceId = sourceId,
|
||||
@ -117,7 +116,7 @@ public class SubscriptionsController : ControllerBase
|
||||
var source = _sources.GetById(sourceId);
|
||||
if (source.Id == Guid.Empty) return new BadRequestResult();
|
||||
|
||||
var sub = _subscription.New(new SubscriptionEntity
|
||||
var sub = _subscription.New(new SubscriptionModel
|
||||
{
|
||||
DiscordWebHookId = discordId,
|
||||
SourceId = sourceId,
|
||||
|
@ -14,11 +14,6 @@
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.33" />
|
||||
<PackageReference Include="Hangfire.MemoryStorage" Version="1.7.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.8">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.4.0" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.4.0" />
|
||||
|
@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Newsbot.Collector.Api;
|
||||
using Newsbot.Collector.Api.Authentication;
|
||||
using Newsbot.Collector.Database;
|
||||
using Newsbot.Collector.Domain.Consts;
|
||||
using Newsbot.Collector.Domain.Models;
|
||||
using Newsbot.Collector.Domain.Models.Config;
|
||||
@ -72,8 +71,6 @@ builder.Services.AddSwaggerGen(cfg =>
|
||||
cfg.AddSecurityRequirement(requirement);
|
||||
});
|
||||
|
||||
builder.Services.AddDbContext<DatabaseContext>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
@ -16,7 +16,7 @@ public class DatabaseContext : DbContext
|
||||
|
||||
private string ConnectionString { get; set; }
|
||||
|
||||
public DatabaseContext(IConfiguration appsettings, string connectionString)
|
||||
public DatabaseContext(IConfiguration appsettings)
|
||||
{
|
||||
var connString = appsettings.GetConnectionString(ConfigConnectionStringConst.Database);
|
||||
ConnectionString = connString ?? "";
|
||||
@ -27,24 +27,13 @@ public class DatabaseContext : DbContext
|
||||
ConnectionString = connectionString;
|
||||
}
|
||||
|
||||
public DatabaseContext(DbContextOptions<DatabaseContext> connectionString)
|
||||
{
|
||||
ConnectionString = "";
|
||||
}
|
||||
|
||||
public DatabaseContext()
|
||||
{
|
||||
ConnectionString = "";
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||
{
|
||||
options.UseNpgsql(ConnectionString);
|
||||
}
|
||||
|
||||
public DatabaseContext(DbContextOptions<DatabaseContext> options, string connectionString)
|
||||
public DatabaseContext(DbContextOptions<DatabaseContext> options)
|
||||
: base(options)
|
||||
{
|
||||
ConnectionString = connectionString;
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Newsbot.Collector.Database;
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="dapper" Version="2.0.123" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.8">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.7" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.7">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
@ -35,7 +35,7 @@ public class SourcesTable : ISourcesRepository
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Failed to save source to db. {model.ToString()} {ex.Message} ");
|
||||
Console.WriteLine($"Failed to save ");
|
||||
}
|
||||
|
||||
return model;
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newsbot.Collector.Domain.Entities;
|
||||
using Newsbot.Collector.Domain.Interfaces;
|
||||
using Newsbot.Collector.Domain.Models;
|
||||
using Npgsql;
|
||||
@ -24,64 +23,104 @@ public class SubscriptionsTable : ISubscriptionRepository
|
||||
_connectionString = connstr;
|
||||
}
|
||||
|
||||
public SubscriptionEntity New(SubscriptionEntity model)
|
||||
public SubscriptionModel New(SubscriptionModel model)
|
||||
{
|
||||
model.Id = new Guid();
|
||||
using var context = new DatabaseContext(_connectionString);
|
||||
context.Subscriptions.Add(model);
|
||||
context.SaveChanges();
|
||||
return model;
|
||||
model.Id = Guid.NewGuid();
|
||||
using var conn = OpenConnection(_connectionString);
|
||||
var query =
|
||||
"Insert Into subscriptions (ID, DiscordWebHookId, SourceId, codeAllowCommits, codeAllowReleases) Values (@id, @webhookId, @sourceId, @codeAllowCommits, @codeAllowReleases);";
|
||||
try
|
||||
{
|
||||
conn.Execute(query, new
|
||||
{
|
||||
id = model.Id,
|
||||
webhookId = model.DiscordWebHookId,
|
||||
sourceId = model.SourceId,
|
||||
codeAllowCommits = model.CodeAllowCommits,
|
||||
codeAllowReleases = model.CodeAllowReleases
|
||||
});
|
||||
return model;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new SubscriptionModel();
|
||||
}
|
||||
}
|
||||
|
||||
public List<SubscriptionEntity> List(int page = 0, int count = 25)
|
||||
public List<SubscriptionModel> List(int page = 0, int count = 25)
|
||||
{
|
||||
using var context = new DatabaseContext(_connectionString);
|
||||
return context.Subscriptions.Skip(page * count).Take(count).ToList();
|
||||
using var conn = OpenConnection(_connectionString);
|
||||
var query = @"Select * From subscriptions
|
||||
Offset @page Fetch Next @count Rows Only;";
|
||||
return conn.Query<SubscriptionModel>(query, new
|
||||
{
|
||||
page = page * count, count
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public List<SubscriptionEntity> ListBySourceId(Guid id, int page = 0, int count = 25)
|
||||
public List<SubscriptionModel> ListBySourceID(Guid id, int page = 0, int count = 25)
|
||||
{
|
||||
using var context = new DatabaseContext(_connectionString);
|
||||
return context.Subscriptions.Where(f => f.SourceId.Equals(id))
|
||||
.Skip(page * count)
|
||||
.ToList();
|
||||
using var conn = OpenConnection(_connectionString);
|
||||
var query = @"Select * From subscriptions
|
||||
Where sourceid = @sourceid
|
||||
Offset @page Fetch Next @count Rows Only";
|
||||
return conn.Query<SubscriptionModel>(query, new
|
||||
{
|
||||
page = page * count,
|
||||
count,
|
||||
sourceid = id
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public List<SubscriptionEntity> ListByWebhook(Guid id, int page = 0, int count = 25)
|
||||
public List<SubscriptionModel> ListByWebhook(Guid id, int page = 0, int count = 25)
|
||||
{
|
||||
using var context = new DatabaseContext(_connectionString);
|
||||
return context.Subscriptions.Where(f => f.DiscordWebHookId.Equals(id)).Skip(page * count).ToList();
|
||||
using var conn = OpenConnection(_connectionString);
|
||||
var query = @"Select * From subscriptions
|
||||
Where discordwebhookid = @webhookid
|
||||
Offset @page Fetch Next @count Rows Only";
|
||||
return conn.Query<SubscriptionModel>(query, new
|
||||
{
|
||||
page = page * count,
|
||||
count,
|
||||
webhookid = id
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public SubscriptionEntity GetById(Guid id)
|
||||
public SubscriptionModel GetById(Guid id)
|
||||
{
|
||||
using var context = new DatabaseContext(_connectionString);
|
||||
var res = context.Subscriptions
|
||||
.FirstOrDefault(f => f.Id.Equals(id));
|
||||
return res ??= new SubscriptionEntity();
|
||||
using var conn = OpenConnection(_connectionString);
|
||||
var query = @"Select * From subscriptions Where id = @id;";
|
||||
var res = conn.Query<SubscriptionModel>(query, new
|
||||
{
|
||||
id
|
||||
});
|
||||
if (res.Count() == 0) return new SubscriptionModel();
|
||||
return res.First();
|
||||
}
|
||||
|
||||
public SubscriptionEntity GetByWebhookAndSource(Guid webhookId, Guid sourceId)
|
||||
public SubscriptionModel GetByWebhookAndSource(Guid webhookId, Guid sourceId)
|
||||
{
|
||||
using var context = new DatabaseContext(_connectionString);
|
||||
var res = context.Subscriptions
|
||||
.Where(f => f.DiscordWebHookId.Equals(webhookId))
|
||||
.FirstOrDefault(f => f.SourceId.Equals(sourceId));
|
||||
return res ??= new SubscriptionEntity();
|
||||
using var conn = OpenConnection(_connectionString);
|
||||
var query = @"Select * From subscriptions
|
||||
Where discordwebhookid = @webhookid
|
||||
and sourceid = @sourceid;";
|
||||
var res = conn.Query<SubscriptionModel>(query, new
|
||||
{
|
||||
webhookid = webhookId,
|
||||
sourceid = sourceId
|
||||
});
|
||||
if (res.Count() == 0) return new SubscriptionModel();
|
||||
return res.First();
|
||||
}
|
||||
|
||||
public void Delete(Guid id)
|
||||
{
|
||||
using var context = new DatabaseContext(_connectionString);
|
||||
var res = context.Subscriptions.FirstOrDefault(f => f.Id.Equals(id));
|
||||
if (res is null)
|
||||
using var conn = OpenConnection(_connectionString);
|
||||
var query = "Delete From subscriptions Where id = @id;";
|
||||
conn.Execute(query, new
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
context.Subscriptions.Remove(res);
|
||||
context.SaveChanges();
|
||||
|
||||
id
|
||||
});
|
||||
}
|
||||
|
||||
private IDbConnection OpenConnection(string connectionString)
|
||||
|
@ -11,7 +11,7 @@ public class SubscriptionDetailsDto
|
||||
public SourceDto? Source { get; set; }
|
||||
public DiscordWebHookDto? DiscordWebHook { get; set; }
|
||||
|
||||
public static SubscriptionDetailsDto Convert(SubscriptionEntity subscription, SourceEntity source,
|
||||
public static SubscriptionDetailsDto Convert(SubscriptionModel subscription, SourceEntity source,
|
||||
DiscordWebhookEntity discord)
|
||||
{
|
||||
return new SubscriptionDetailsDto
|
||||
|
@ -1,4 +1,3 @@
|
||||
using Newsbot.Collector.Domain.Entities;
|
||||
using Newsbot.Collector.Domain.Models;
|
||||
|
||||
namespace Newsbot.Collector.Domain.Dto;
|
||||
@ -11,7 +10,7 @@ public class SubscriptionDto
|
||||
public bool CodeAllowReleases { get; set; }
|
||||
public bool CodeAllowCommits { get; set; }
|
||||
|
||||
public static SubscriptionDto Convert(SubscriptionEntity model)
|
||||
public static SubscriptionDto Convert(SubscriptionModel model)
|
||||
{
|
||||
return new SubscriptionDto
|
||||
{
|
||||
|
@ -1,18 +1,17 @@
|
||||
using Newsbot.Collector.Domain.Entities;
|
||||
using Newsbot.Collector.Domain.Models;
|
||||
|
||||
namespace Newsbot.Collector.Domain.Interfaces;
|
||||
|
||||
public interface ISubscriptionRepository
|
||||
{
|
||||
SubscriptionEntity New(SubscriptionEntity model);
|
||||
SubscriptionModel New(SubscriptionModel model);
|
||||
|
||||
List<SubscriptionEntity> List(int page = 0, int count = 25);
|
||||
List<SubscriptionEntity> ListBySourceId(Guid id, int page = 0, int count = 25);
|
||||
List<SubscriptionEntity> ListByWebhook(Guid id, int page = 0, int count = 25);
|
||||
List<SubscriptionModel> List(int page = 0, int count = 25);
|
||||
List<SubscriptionModel> ListBySourceID(Guid id, int page = 0, int count = 25);
|
||||
List<SubscriptionModel> ListByWebhook(Guid id, int page = 0, int count = 25);
|
||||
|
||||
SubscriptionEntity GetById(Guid id);
|
||||
SubscriptionEntity GetByWebhookAndSource(Guid webhookId, Guid sourceId);
|
||||
SubscriptionModel GetById(Guid id);
|
||||
SubscriptionModel GetByWebhookAndSource(Guid webhookId, Guid sourceId);
|
||||
|
||||
void Delete(Guid id);
|
||||
}
|
@ -112,7 +112,7 @@ public class DiscordNotificationJob
|
||||
}
|
||||
|
||||
// Find all the subscriptions for that source
|
||||
var allSubscriptions = _subs.ListBySourceId(sourceDetails.Id);
|
||||
var allSubscriptions = _subs.ListBySourceID(sourceDetails.Id);
|
||||
|
||||
foreach (var sub in allSubscriptions)
|
||||
SendSubscriptionNotification(request.Id, articleDetails, sourceDetails, sourceIcon, sub);
|
||||
@ -121,7 +121,7 @@ public class DiscordNotificationJob
|
||||
_queue.Delete(request.Id);
|
||||
}
|
||||
|
||||
public void SendSubscriptionNotification(Guid requestId, ArticlesEntity articleDetails, SourceEntity sourceDetails, IconEntity sourceIcon, SubscriptionEntity sub)
|
||||
public void SendSubscriptionNotification(Guid requestId, ArticlesEntity articleDetails, SourceEntity sourceDetails, IconEntity sourceIcon, SubscriptionModel sub)
|
||||
{
|
||||
// Check if the subscription code flags
|
||||
// If the article is a code commit and the subscription does not want them, skip.
|
||||
|
@ -7,10 +7,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.8">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Selenium.WebDriver" Version="4.8.1" />
|
||||
<PackageReference Include="Selenium.WebDriver.GeckoDriver" Version="0.32.2" />
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Newsbot.Collector.Domain.Entities;
|
||||
using Newsbot.Collector.Domain.Models;
|
||||
using Newsbot.Collector.Services.Jobs;
|
||||
using Newsbot.Collector.Services.Notifications.Discord;
|
||||
|
||||
@ -78,7 +79,7 @@ public class DiscordNotificationJobTest
|
||||
Id = Guid.NewGuid(),
|
||||
FileName = "https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png"
|
||||
},
|
||||
new SubscriptionEntity
|
||||
new SubscriptionModel
|
||||
{
|
||||
CodeAllowCommits = false,
|
||||
CodeAllowReleases = true
|
||||
@ -87,7 +88,6 @@ public class DiscordNotificationJobTest
|
||||
}
|
||||
catch (MessageTypeNotRequestedException)
|
||||
{
|
||||
|
||||
Console.Write($"Message did not send as expected");
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class RssWatcherJobTest
|
||||
[Fact]
|
||||
public void CanReadHtmlDrivenFeedPage()
|
||||
{
|
||||
//var url = "https://www.howtogeek.com/feed/";
|
||||
var url = "https://www.howtogeek.com/feed/";
|
||||
var client = new RssWatcherJob();
|
||||
client.InitAndExecute(new RssWatcherJobOptions
|
||||
{
|
||||
|
@ -9,10 +9,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.8">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||
|
26
README.md
26
README.md
@ -1,26 +1,2 @@
|
||||
# Newsbot.Collector
|
||||
|
||||
C# API Server to collect news from around the world.
|
||||
|
||||
## Features
|
||||
|
||||
- YouTube
|
||||
- Github
|
||||
- Should support other source control services but untested
|
||||
- RSS
|
||||
|
||||
## Notifications
|
||||
|
||||
- Discord Webhooks
|
||||
|
||||
## Legacy Features No longer support
|
||||
|
||||
- Twitter
|
||||
- API Changes
|
||||
- Reddit
|
||||
- API Changes
|
||||
- Could come back as long as the json dump is still available
|
||||
- Instagram
|
||||
- No plans to attempt to get this working again.
|
||||
|
||||
|
||||
C# API Server to collect news from around the world
|
||||
|
2
makefile
2
makefile
@ -22,7 +22,7 @@ docker-migrate: ## Runs the migrations stored in the Docker image
|
||||
docker run -it --env-file .env ghcr.io/jtom38/newsbot.collector:master /app/goose --dir "/app/migrations" up
|
||||
|
||||
ef-build: ## Builds migration artifact
|
||||
dotnet ef migrations bundle --project "Newsbot.Collector.Database" --force
|
||||
dotnet ef migrations bundle --project "Newsbot.Collector.Database"
|
||||
|
||||
ef-migrate: ## Runs migrations based on the newest artifact
|
||||
dotnet ef migrations bundle --project "Newsbot.Collector.Database" --force
|
||||
|
Loading…
Reference in New Issue
Block a user