Compare commits

..

1 Commits

Author SHA1 Message Date
a3b33e4772 loading password from drone secret
Some checks failed
continuous-integration/drone/pr Build is failing
2023-06-13 22:20:15 -07:00
137 changed files with 1161 additions and 7378 deletions

View File

@ -1,4 +1,3 @@
appsettings.json
**/bin/**
**/obj/**
**/efbundle
**/bin/
**/obj/

View File

@ -1,53 +1,34 @@
---
kind: pipeline
type: docker
name: buildLatestImage
name: build
steps:
- name: buildLatestImage
- name: build image
image: plugins/docker
environment:
PAT:
from_secret: GiteaPat
settings:
repo: jtom38/newsbot-collector
repo: git.jamestombleson.com/jtom38/newsbot-collector
registry: git.jamestombleson.com
username: jtom38
password:
from_secret: DockerPushPat
password: $PAT
tags:
- latest
- master
trigger:
branch:
include:
- main
event:
exclude:
- pull_request
---
kind: pipeline
type: docker
name: buildReleaseImage
steps:
- name: buildReleaseImage
image: plugins/docker
settings:
repo: jtom38/newsbot-collector
username: jtom38
password:
from_secret: DockerPushPat
trigger:
branch:
include:
- releases/*
ref:
include:
- refs/tags/**
- master
event:
exclude:
- pull_request
---
kind: pipeline
type: docker
name: PullRequestCompileTest
name: compile
steps:
- name: Compile project
image: mcr.microsoft.com/dotnet/sdk:7.0.103

2
.gitignore vendored
View File

@ -4,8 +4,6 @@
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
seed.secrects.json
efbundle
efbundle.exe
out/
#Docker Compose Secrets

View File

@ -1,6 +1,6 @@
#FROM golang:latest as goose
FROM golang:latest as goose
#RUN go install github.com/pressly/goose/v3/cmd/goose@latest
RUN go install github.com/pressly/goose/v3/cmd/goose@latest
FROM mcr.microsoft.com/dotnet/sdk:7.0.103 as build
@ -14,20 +14,21 @@ FROM build AS publish
RUN dotnet publish -c Release -o /app/publish
RUN dotnet publish -o build
#--self-contained true -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true
RUN ls build
FROM build as ef
RUN dotnet tool install dotnet-ef --tool-path /usr/bin --version 7.0.8
RUN dotnet ef migrations bundle --project "Newsbot.Collector.Database" --force
FROM mcr.microsoft.com/dotnet/aspnet:7.0.3 as app
ENV ASPNETCORE_URLS=http://*:5000
ENV DOTNET_URLS=http://*:5000
#RUN apt-get install chromium -y
WORKDIR /app
RUN mkdir /migrations
COPY --from=publish /app/build /app
COPY --from=ef /app/efbundle /app
COPY --from=build ./app/Newsbot.Collector.Database/Migrations /app/migrations
COPY --from=goose /go/bin/goose /app
CMD [ "dotnet", "Newsbot.Collector.Api.dll" ]

View File

@ -3,7 +3,7 @@ using Newsbot.Collector.Domain.Consts;
using Newsbot.Collector.Domain.Models.Config;
using Newsbot.Collector.Services.Jobs;
namespace Newsbot.Collector.Api.Startup;
namespace Newsbot.Collector.Api;
public static class BackgroundJobs
{

View File

@ -0,0 +1,58 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Newsbot.Collector.Database.Repositories;
using Newsbot.Collector.Domain.Dto;
using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Api.Controllers;
[ApiController]
[Route("api/articles")]
public class ArticlesController : ControllerBase
{
private readonly IArticlesRepository _articles;
private readonly ILogger<ArticlesController> _logger;
private readonly ISourcesRepository _sources;
public ArticlesController(ILogger<ArticlesController> logger, IOptions<ConnectionStrings> settings)
{
_logger = logger;
_articles = new ArticlesTable(settings.Value.Database);
_sources = new SourcesTable(settings.Value.Database);
}
[HttpGet(Name = "GetArticles")]
public IEnumerable<ArticleDto> Get()
{
var res = new List<ArticleDto>();
var items = _articles.List(0, 25);
foreach (var item in items) res.Add(ArticleDto.Convert(item));
return res;
}
[HttpGet("{id:guid}")]
[EndpointDescription("Returns the article based on the Id value given.")]
public ArticleDto GetById(Guid id)
{
var item = _articles.GetById(id);
return ArticleDto.Convert(item);
}
[HttpGet("{id:guid}/details")]
public ArticleDetailsDto GetDetailsById(Guid id)
{
var item = _articles.GetById(id);
var sourceItem = _sources.GetByID(item.SourceID);
return ArticleDetailsDto.Convert(item, sourceItem);
}
[HttpGet("by/{sourceId:guid}")]
public IEnumerable<ArticleDto> GetBySourceId(Guid sourceId, int page = 0, int count = 25)
{
var res = new List<ArticleDto>();
var items = _articles.ListBySourceId(sourceId, page, count);
foreach (var item in items) res.Add(ArticleDto.Convert(item));
return res;
}
}

View File

@ -1,17 +1,13 @@
using Hangfire;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Newsbot.Collector.Api.Domain.Consts;
using Newsbot.Collector.Domain.Models.Config;
using Newsbot.Collector.Services.Jobs;
namespace Newsbot.Collector.Api.Controllers.v1;
namespace Newsbot.Collector.Api.Controllers;
[ApiController]
[Route("api/v1/codeprojects")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Route("api/codeprojects")]
public class CodeProjectController
{
private readonly ConfigSectionConnectionStrings _connectionStrings;
@ -25,8 +21,7 @@ public class CodeProjectController
}
[HttpPost("check")]
[Authorize(Roles = Authorization.AdministratorsRole)]
public ActionResult PullNow()
public void PullNow()
{
BackgroundJob.Enqueue<CodeProjectWatcherJob>(x => x.InitAndExecute(new CodeProjectWatcherJobOptions
{
@ -34,7 +29,5 @@ public class CodeProjectController
FeaturePullReleases = true,
FeaturePullCommits = true
}));
return new AcceptedResult();
}
}

View File

@ -0,0 +1,90 @@
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Newsbot.Collector.Database.Repositories;
using Newsbot.Collector.Domain.Dto;
using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Api.Controllers;
[ApiController]
[Route("api/discord/webhooks")]
public class DiscordWebHookController : ControllerBase
{
private readonly ILogger<DiscordWebHookController> _logger;
private readonly ConnectionStrings _settings;
private readonly IDiscordWebHooksRepository _webhooks;
public DiscordWebHookController(ILogger<DiscordWebHookController> logger, IOptions<ConnectionStrings> settings)
{
_logger = logger;
_settings = settings.Value;
_webhooks = new DiscordWebhooksTable(_settings.Database);
}
[HttpGet(Name = "GetDiscordWebhooks")]
public IEnumerable<DiscordWebHookDto> Get(int page)
{
var items = new List<DiscordWebHookDto>();
var res = _webhooks.List(page);
foreach (var item in res)
{
items.Add(DiscordWebHookDto.Convert(item));
}
return items;
}
[HttpPost(Name = "New")]
public DiscordWebHookDto New(string url, string server, string channel)
{
var exists = _webhooks.GetByUrl(url);
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (exists.ID != Guid.Empty)
{
return DiscordWebHookDto.Convert(exists);
}
var res = _webhooks.New(new DiscordWebHookModel
{
Url = url,
Server = server,
Channel = channel,
Enabled = true,
});
return DiscordWebHookDto.Convert(res);
}
[HttpGet("by/serverAndChannel")]
public IEnumerable<DiscordWebHookDto> GetByServerAndChannel(string server, string channel)
{
var items = new List<DiscordWebHookDto>();
var res = _webhooks.ListByServerAndChannel(server, channel, 25);
foreach (var item in res)
{
items.Add(DiscordWebHookDto.Convert(item));
}
return items;
}
[HttpGet("{id}")]
public DiscordWebHookDto GetById(Guid id)
{
var res = _webhooks.GetByID(id);
return DiscordWebHookDto.Convert(res);
}
[HttpPost("{id}/disable")]
public void DisableById(Guid id)
{
_webhooks.Disable(id);
}
[HttpPost("{id}/enable")]
public void EnableById(Guid id)
{
_webhooks.Enable(id);
}
}

View File

@ -1,18 +1,13 @@
using Hangfire;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Newsbot.Collector.Api.Domain.Consts;
using Newsbot.Collector.Domain.Models.Config;
using Newsbot.Collector.Domain.Models.Config.Sources;
using Newsbot.Collector.Services.Jobs;
namespace Newsbot.Collector.Api.Controllers.v1;
namespace Newsbot.Collector.Api.Controllers;
[ApiController]
[Route("api/v1/rss")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Route("api/rss")]
public class RssController
{
private readonly ConfigSectionConnectionStrings _connectionStrings;
@ -28,7 +23,6 @@ public class RssController
}
[HttpPost("check")]
[Authorize(Roles = Authorization.AdministratorsRole)]
public void CheckReddit()
{
BackgroundJob.Enqueue<RssWatcherJob>(x => x.InitAndExecute(new RssWatcherJobOptions

View File

@ -1,29 +1,32 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newsbot.Collector.Api.Domain.Consts;
using Microsoft.Extensions.Options;
using Newsbot.Collector.Database.Repositories;
using Newsbot.Collector.Domain.Consts;
using Newsbot.Collector.Domain.Dto;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Models;
using Newsbot.Collector.Services.HtmlParser;
namespace Newsbot.Collector.Api.Controllers.v1;
namespace Newsbot.Collector.Api.Controllers;
[ApiController]
[Route("api/sources")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class SourcesController : ControllerBase
{
private readonly ILogger<SourcesController> _logger;
private readonly IArticlesRepository _articles;
//private readonly ConnectionStrings _settings;
private readonly IIconsRepository _icons;
private readonly ILogger<SourcesController> _logger;
private readonly ISourcesRepository _sources;
public SourcesController(ILogger<SourcesController> logger, IIconsRepository icons, ISourcesRepository sources)
public SourcesController(ILogger<SourcesController> logger, IOptions<ConnectionStrings> settings)
{
_logger = logger;
_icons = icons;
_sources = sources;
//_settings = settings.Value;
_sources = new SourcesTable(settings.Value.Database);
_icons = new IconsTable(settings.Value.Database);
_articles = new ArticlesTable(settings.Value.Database);
}
[HttpGet(Name = "GetSources")]
@ -36,10 +39,10 @@ public class SourcesController : ControllerBase
}
[HttpGet("by/type")]
public IEnumerable<SourceDto> GetByType(string type, int page)
public IEnumerable<SourceDto> GetByType(string type)
{
var res = new List<SourceDto>();
var temp = _sources.ListByType(type, page);
var temp = _sources.ListByType(type);
foreach (var item in temp) res.Add(SourceDto.Convert(item));
return res;
}
@ -48,7 +51,7 @@ public class SourcesController : ControllerBase
public SourceDto NewReddit(string name)
{
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}");
@ -58,7 +61,7 @@ public class SourcesController : ControllerBase
});
pageReader.Parse();
var item = _sources.New(new SourceEntity
var item = _sources.New(new SourceModel
{
Site = SourceTypes.Reddit,
Name = name,
@ -71,11 +74,11 @@ public class SourcesController : ControllerBase
// Not all subreddits have an Icon, so we only want to add a record when it has one.
if (pageReader.Data.Header.Image != "")
_icons.New(new IconEntity()
_icons.New(new IconModel
{
Id = Guid.NewGuid(),
FileName = pageReader.Data.Header.Image,
SourceId = item.Id
SourceId = item.ID
});
return SourceDto.Convert(item);
}
@ -84,9 +87,9 @@ public class SourcesController : ControllerBase
public SourceDto NewRss(string name, string url)
{
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 SourceEntity
var m = new SourceModel
{
Site = SourceTypes.Rss,
Name = name,
@ -104,7 +107,7 @@ public class SourcesController : ControllerBase
public SourceDto NewYoutube(string 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
{
@ -112,7 +115,7 @@ public class SourcesController : ControllerBase
});
htmlClient.Parse();
var item = _sources.New(new SourceEntity
var item = _sources.New(new SourceModel
{
Site = SourceTypes.YouTube,
Type = SourceTypes.YouTube,
@ -124,11 +127,11 @@ public class SourcesController : ControllerBase
YoutubeId = htmlClient.Data.Header.YoutubeChannelID ?? ""
});
_icons.New(new IconEntity()
_icons.New(new IconModel
{
Id = Guid.NewGuid(),
FileName = htmlClient.Data.Header.Image,
SourceId = item.Id
SourceId = item.ID
});
return SourceDto.Convert(item);
@ -138,9 +141,9 @@ public class SourcesController : ControllerBase
public SourceDto NewTwitch(string name)
{
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 SourceEntity
var item = _sources.New(new SourceModel
{
Site = SourceTypes.Twitch,
Type = SourceTypes.Twitch,
@ -159,7 +162,7 @@ public class SourcesController : ControllerBase
//if (!url.Contains("github.com")) return new SourceDto();
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('/');
@ -169,7 +172,7 @@ public class SourcesController : ControllerBase
});
pageReader.Parse();
var item = _sources.New(new SourceEntity
var item = _sources.New(new SourceModel
{
Site = SourceTypes.CodeProject,
Type = SourceTypes.CodeProject,
@ -180,11 +183,11 @@ public class SourcesController : ControllerBase
Tags = $"{slice[2]},{slice[3]},{slice[4]}"
});
_icons.New(new IconEntity()
_icons.New(new IconModel
{
Id = Guid.NewGuid(),
FileName = pageReader.Data.Header.Image,
SourceId = item.Id
SourceId = item.ID
});
return SourceDto.Convert(item);
@ -193,18 +196,16 @@ public class SourcesController : ControllerBase
[HttpGet("{id}")]
public SourceDto GetById(Guid id)
{
var item = _sources.GetById(id);
var item = _sources.GetByID(id);
return SourceDto.Convert(item);
}
[Authorize(Roles = Authorization.AdministratorsRole)]
[HttpPost("{id}/disable")]
public void Disable(Guid id)
{
_sources.Disable(id);
}
[Authorize(Roles = Authorization.AdministratorsRole)]
[HttpPost("{id}/enable")]
public void Enable(Guid id)
{
@ -212,7 +213,6 @@ public class SourcesController : ControllerBase
}
[HttpDelete("{id}")]
[Authorize(Roles = Authorization.AdministratorsRole)]
public void Delete(Guid id, bool purgeOrphanedRecords)
{
_sources.Delete(id);

View File

@ -0,0 +1,129 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Newsbot.Collector.Database.Repositories;
using Newsbot.Collector.Domain.Dto;
using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Api.Controllers;
[ApiController]
[Route("api/subscriptions")]
public class SubscriptionsController : ControllerBase
{
private readonly IDiscordWebHooksRepository _discord;
private readonly ILogger<SubscriptionsController> _logger;
private readonly ISourcesRepository _sources;
private readonly ISubscriptionRepository _subscription;
public SubscriptionsController(ILogger<SubscriptionsController> logger, IOptions<ConnectionStrings> settings)
{
_logger = logger;
_subscription = new SubscriptionsTable(settings.Value.Database);
_discord = new DiscordWebhooksTable(settings.Value.Database);
_sources = new SourcesTable(settings.Value.Database);
}
[HttpGet(Name = "ListSubscriptions")]
public IEnumerable<SubscriptionDto> List(int page)
{
var res = new List<SubscriptionDto>();
var items = _subscription.List(page);
foreach (var item in items) res.Add(SubscriptionDto.Convert(item));
return res;
}
[HttpGet("{id}")]
public SubscriptionDto GetById(Guid id)
{
return SubscriptionDto.Convert(_subscription.GetById(id));
}
[HttpGet("{id}/details")]
public SubscriptionDetailsDto GetDetailsById(Guid id)
{
var sub = _subscription.GetById(id);
var webhook = _discord.GetByID(sub.DiscordWebHookId);
var source = _sources.GetByID(sub.SourceId);
return SubscriptionDetailsDto.Convert(sub, source, webhook);
}
[HttpPost("{id}/delete")]
public void DeleteById(Guid id)
{
_subscription.Delete(id);
}
[HttpGet("by/discordid/{id}")]
public IEnumerable<SubscriptionDto> GetByDiscordId(Guid id)
{
var res = new List<SubscriptionDto>();
var items = _subscription.ListByWebhook(id);
foreach (var item in items) res.Add(SubscriptionDto.Convert(item));
return res;
}
[HttpGet("by/sourceId/{id}")]
public IEnumerable<SubscriptionDto> GetBySourceId(Guid id)
{
var res = new List<SubscriptionDto>();
var items = _subscription.ListBySourceID(id);
foreach (var item in items) res.Add(SubscriptionDto.Convert(item));
return res;
}
[HttpPost(Name = "New Subscription")]
public ActionResult<SubscriptionDto> New(Guid sourceId, Guid discordId)
{
if (sourceId == Guid.Empty) return new BadRequestResult();
if (discordId == Guid.Empty) return new BadRequestResult();
var exists = _subscription.GetByWebhookAndSource(discordId, sourceId);
if (exists.Id != Guid.Empty) return SubscriptionDto.Convert(exists);
var discord = _discord.GetByID(discordId);
if (discord.ID == Guid.Empty) return new BadRequestResult();
var source = _sources.GetByID(sourceId);
if (source.ID == Guid.Empty) return new BadRequestResult();
var item = _subscription.New(new SubscriptionModel
{
Id = Guid.NewGuid(),
SourceId = sourceId,
DiscordWebHookId = discordId,
CodeAllowCommits = false,
CodeAllowReleases = false
});
return SubscriptionDto.Convert(item);
}
[HttpPost("new/codeproject")]
public ActionResult<SubscriptionDto> NewCodeProjectSubscription(Guid sourceId, Guid discordId, bool allowReleases,
bool allowCommits)
{
if (sourceId == Guid.Empty) return new BadRequestResult();
if (discordId == Guid.Empty) return new BadRequestResult();
var exists = _subscription.GetByWebhookAndSource(discordId, sourceId);
if (exists.Id != Guid.Empty) return SubscriptionDto.Convert(exists);
var discord = _discord.GetByID(discordId);
if (discord.ID == Guid.Empty) return new BadRequestResult();
var source = _sources.GetByID(sourceId);
if (source.ID == Guid.Empty) return new BadRequestResult();
var sub = _subscription.New(new SubscriptionModel
{
DiscordWebHookId = discordId,
SourceId = sourceId,
CodeAllowCommits = allowCommits,
CodeAllowReleases = allowReleases
});
return new SubscriptionDto();
}
}

View File

@ -1,18 +1,14 @@
using Hangfire;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Newsbot.Collector.Api.Domain.Consts;
using Newsbot.Collector.Domain.Models.Config;
using Newsbot.Collector.Domain.Models.Config.Sources;
using Newsbot.Collector.Services.Jobs;
using ILogger = Grpc.Core.Logging.ILogger;
namespace Newsbot.Collector.Api.Controllers.v1;
namespace Newsbot.Collector.Api.Controllers;
[ApiController]
[Route("api/v1/youtube")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Route("api/youtube")]
public class YoutubeController
{
private readonly ILogger<YoutubeController> _logger;
@ -27,7 +23,6 @@ public class YoutubeController
}
[HttpPost("check")]
[Authorize(Policy = Authorization.AdministratorsRole)]
public void CheckYoutube()
{
BackgroundJob.Enqueue<YoutubeWatcherJob>(x => x.InitAndExecute(new YoutubeWatcherJobOptions

View File

@ -1,89 +0,0 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newsbot.Collector.Domain.Dto;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Results;
namespace Newsbot.Collector.Api.Controllers.v1;
[ApiController]
[Route("api/v1/articles")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class ArticlesController : ControllerBase
{
//private readonly ILogger<ArticlesController> _logger;
private readonly IArticlesRepository _articles;
private readonly ISourcesRepository _sources;
private readonly IAuthorTable _author;
public ArticlesController(IArticlesRepository articles, ISourcesRepository sources, IAuthorTable author)
{
_articles = articles;
_sources = sources;
_author = author;
}
[HttpGet(Name = "GetArticles")]
public ActionResult<ArticleResult> Get()
{
var res = new List<ArticleDto>();
var items = _articles.List(0);
foreach (var item in items)
{
res.Add(ArticleDto.Convert(item));
}
return new OkObjectResult(new ArticleResult
{
IsSuccessful = true,
Items = res
});
}
[HttpGet("{id:guid}")]
[EndpointDescription("Returns the article based on the Id value given.")]
public ActionResult<ArticleResult> GetById(Guid id)
{
var item = _articles.GetById(id);
return new OkObjectResult(new ArticleResult
{
IsSuccessful = true,
Items = new List<ArticleDto>
{
ArticleDto.Convert(item)
}
});
}
[HttpGet("{id:guid}/details")]
public ActionResult<ArticleDetailsResult> GetDetailsById(Guid id)
{
var item = _articles.GetById(id);
var sourceItem = _sources.GetById(item.SourceId);
var author = _author.GetBySourceIdAndNameAsync(sourceItem.Id, sourceItem.Name);
author.Wait();
return new OkObjectResult(new ArticleDetailsResult
{
IsSuccessful = true,
Item = ArticleDetailsDto.Convert(item, sourceItem, author.Result)
});
}
[HttpGet("by/{sourceId:guid}")]
public ActionResult<ArticleResult> GetBySourceId(Guid sourceId, int page = 0)
{
var res = new List<ArticleDto>();
var items = _articles.ListBySourceId(sourceId, page);
foreach (var item in items) res.Add(ArticleDto.Convert(item));
return new OkObjectResult(new ArticleResult
{
IsSuccessful = true,
Items = res
});
}
}

View File

@ -1,239 +0,0 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newsbot.Collector.Api.Middleware;
using Newsbot.Collector.Domain.Dto;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Requests;
using Newsbot.Collector.Domain.Results;
namespace Newsbot.Collector.Api.Controllers.v1;
[ApiController]
[Route("api/v1/subscriptions")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class DiscordNotificationController : ControllerBase
{
private readonly ILogger<DiscordNotificationController> _logger;
private readonly IDiscordWebHooksRepository _discord;
private readonly ISourcesRepository _sources;
private readonly IDiscordNotificationRepository _discordNotification;
public DiscordNotificationController(ILogger<DiscordNotificationController> logger, IDiscordWebHooksRepository discord, ISourcesRepository sources, IDiscordNotificationRepository discordNotification)
{
_logger = logger;
_discord = discord;
_sources = sources;
_discordNotification = discordNotification;
}
[HttpGet(Name = "ListSubscriptions")]
public ActionResult<DiscordNotificationResult> List(int page)
{
var userId = HttpContext.GetUserId();
if (userId.Equals(string.Empty))
{
return new BadRequestObjectResult(new DiscordNotificationResult
{
IsSuccessful = false,
ErrorMessage = new List<string> { "User Id is missing from the request." }
});
}
var res = new List<DiscordNotificationDto>();
var items = _discordNotification.List(userId, page);
foreach (var item in items) res.Add(DiscordNotificationDto.Convert(item));
return new OkObjectResult(new DiscordNotificationResult
{
IsSuccessful = true,
Items = res
});
}
[HttpGet("{id}")]
public ActionResult<DiscordNotificationResult> GetById(Guid id)
{
var userId = HttpContext.GetUserId();
if (userId.Equals(string.Empty))
{
return new BadRequestObjectResult(new DiscordNotificationResult
{
IsSuccessful = false,
ErrorMessage = new List<string> { "User Id is missing from the request." }
});
}
var res = DiscordNotificationDto.Convert(_discordNotification.GetById(userId, id));
return new OkObjectResult(new DiscordNotificationResult
{
IsSuccessful = true,
Items = new List<DiscordNotificationDto>
{
res
}
});
}
[HttpGet("{id}/details")]
public ActionResult<DiscordNotificationDetailsResult> GetDetailsById(Guid id)
{
var userId = HttpContext.GetUserId();
if (userId.Equals(string.Empty))
{
return new BadRequestObjectResult(new DiscordNotificationResult
{
IsSuccessful = false,
ErrorMessage = new List<string> { "User Id is missing from the request." }
});
}
var sub = _discordNotification.GetById(userId, id);
var webhook = _discord.GetById(userId, sub.DiscordWebHookId);
var source = _sources.GetById(sub.SourceId);
return new OkObjectResult(new DiscordNotificationDetailsResult
{
IsSuccessful = true,
Item = DiscordNotificationDetailsDto.Convert(sub, source, webhook)
});
}
[HttpPost("{id}/delete")]
public ActionResult<DiscordNotificationResult> DeleteById(Guid id)
{
var userId = HttpContext.GetUserId();
if (userId.Equals(string.Empty))
{
return new BadRequestObjectResult(new DiscordNotificationResult
{
IsSuccessful = false,
ErrorMessage = new List<string> { "User Id is missing from the request." }
});
}
var rowsUpdated = _discordNotification.Delete(userId, id);
if (rowsUpdated == -1)
{
return new OkObjectResult(new DiscordNotificationResult
{
IsSuccessful = false,
ErrorMessage = new List<string> { "Record was not own by requested user." }
});
}
return new OkObjectResult(new DiscordNotificationResult
{
IsSuccessful = true
});
}
[HttpGet("by/discordId/{id}")]
public ActionResult<DiscordNotificationResult> GetByDiscordId(Guid id)
{
var userId = HttpContext.GetUserId();
if (userId.Equals(string.Empty))
{
return new BadRequestObjectResult(new DiscordNotificationResult
{
IsSuccessful = false,
ErrorMessage = new List<string> { "User Id is missing from the request." }
});
}
var res = new List<DiscordNotificationDto>();
var items = _discordNotification.ListByWebhook(userId, id);
foreach (var item in items) res.Add(DiscordNotificationDto.Convert(item));
return new OkObjectResult(new DiscordNotificationResult
{
IsSuccessful = true,
Items = res
});
}
[HttpGet("by/sourceId/{id}")]
public ActionResult<DiscordNotificationResult> GetBySourceId(Guid id)
{
var userId = HttpContext.GetUserId();
if (userId.Equals(string.Empty))
{
return new BadRequestObjectResult(new DiscordNotificationResult
{
IsSuccessful = false,
ErrorMessage = new List<string> { "User Id is missing from the request." }
});
}
var res = new List<DiscordNotificationDto>();
var items = _discordNotification.ListBySourceId(userId, id);
foreach (var item in items) res.Add(DiscordNotificationDto.Convert(item));
return new OkObjectResult(new DiscordNotificationResult
{
IsSuccessful = true,
Items = res
});
}
[HttpPost(Name = "New Subscription")]
public ActionResult<DiscordNotificationDto> New([FromBody] NewDiscordNotificationRequest request)
{
var userId = HttpContext.GetUserId();
if (userId.Equals(string.Empty))
{
return new BadRequestObjectResult(new DiscordNotificationResult
{
IsSuccessful = false,
ErrorMessage = new List<string> { "User Id is missing from the request." }
});
}
if (request.SourceId == Guid.Empty) return new BadRequestObjectResult(new DiscordNotificationResult
{
IsSuccessful = false,
ErrorMessage = new List<string> { "SourceId is missing from the request." }
});
if (request.DiscordId == Guid.Empty) return new BadRequestObjectResult(new DiscordNotificationResult
{
IsSuccessful = false,
ErrorMessage = new List<string> { "DiscordId is missing from the request." }
});
var exists = _discordNotification.GetByWebhookAndSource(userId, request.DiscordId, request.SourceId);
if (exists.Id != Guid.Empty) return DiscordNotificationDto.Convert(exists);
var discord = _discord.GetById(userId, request.DiscordId);
if (discord.Id == Guid.Empty) return new BadRequestObjectResult(new DiscordNotificationResult
{
IsSuccessful = false,
ErrorMessage = new List<string> { "Unable to find the requested DiscordId in the database." }
});
var source = _sources.GetById(request.SourceId);
if (source.Id == Guid.Empty) return new BadRequestObjectResult(new DiscordNotificationResult
{
IsSuccessful = false,
ErrorMessage = new List<string> { "Unable to find the requested SourceId in the database." }
});
var item = _discordNotification.New(new DiscordNotificationEntity
{
Id = Guid.NewGuid(),
SourceId = request.SourceId,
DiscordWebHookId = request.DiscordId,
CodeAllowCommits = request.AllowCommits,
CodeAllowReleases = request.AllowReleases,
UserId = userId
});
return new OkObjectResult(new DiscordNotificationResult
{
IsSuccessful = true,
Items = new List<DiscordNotificationDto> { DiscordNotificationDto.Convert(item) }
});
}
}

View File

@ -1,114 +0,0 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Newsbot.Collector.Api.Middleware;
using Newsbot.Collector.Domain.Dto;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Models;
using Newsbot.Collector.Domain.Requests;
using Newsbot.Collector.Domain.Results;
namespace Newsbot.Collector.Api.Controllers.v1;
[ApiController]
[Route("api/v1/discord/webhooks")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class DiscordWebHookController : ControllerBase
{
private readonly ILogger<DiscordWebHookController> _logger;
private readonly IDiscordWebHooksRepository _webhooks;
public DiscordWebHookController(ILogger<DiscordWebHookController> logger, IOptions<ConnectionStrings> settings, IDiscordWebHooksRepository webhooks)
{
_logger = logger;
_webhooks = webhooks;
}
[HttpGet(Name = "GetDiscordWebhooks")]
public ActionResult<IEnumerable<DiscordWebHookDto>> Get(int page)
{
var userId = HttpContext.GetUserId();
if (userId.Equals(string.Empty))
{
_logger.LogWarning("Unable to find the user ID in the JWD Token");
return new BadRequestResult();
}
var items = new List<DiscordWebHookDto>();
var res = _webhooks.ListByUserId(userId, page);
foreach (var item in res)
{
items.Add(DiscordWebHookDto.Convert(item));
}
return new OkObjectResult(items);
}
[HttpPost(Name = "New")]
public ActionResult<DiscordWebhookResult> New([FromBody] NewDiscordWebhookRequest request)
{
var userId = HttpContext.GetUserId();
var exists = _webhooks.GetByUrl(request.Url ?? "");
if (exists.Id != Guid.Empty)
{
return new BadRequestObjectResult(new DiscordWebhookResult
{
IsSuccessful = true,
Items = new List<DiscordWebHookDto> { DiscordWebHookDto.Convert(exists) }
});
}
var res = _webhooks.New(new DiscordWebhookEntity
{
UserId = userId,
Url = request.Url ?? "",
Server = request.Server ?? "",
Channel = request.Channel ?? "",
Enabled = true,
});
return new OkObjectResult(new DiscordWebhookResult
{
IsSuccessful = true,
Items = new List<DiscordWebHookDto>
{
DiscordWebHookDto.Convert(res)
}
});
}
[HttpGet("by/serverAndChannel")]
public IEnumerable<DiscordWebHookDto> GetByServerAndChannel(string server, string channel)
{
var items = new List<DiscordWebHookDto>();
var res = _webhooks.ListByServerAndChannel(HttpContext.GetUserId(), server, channel, 25);
foreach (var item in res)
{
items.Add(DiscordWebHookDto.Convert(item));
}
return items;
}
[HttpGet("{id}")]
public DiscordWebHookDto GetById(string userId, Guid id)
{
var res = _webhooks.GetById(userId, id);
return DiscordWebHookDto.Convert(res);
}
[HttpPost("{id}/disable")]
public void DisableById(Guid id)
{
_webhooks.Disable(HttpContext.GetUserId(), id);
}
[HttpPost("{id}/enable")]
public void EnableById(Guid id)
{
_webhooks.Enable(HttpContext.GetUserId(), id);
}
}

View File

@ -1,107 +0,0 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newsbot.Collector.Api.Domain.Consts;
using Newsbot.Collector.Domain.Requests;
using Newsbot.Collector.Domain.Response;
using Newsbot.Collector.Domain.Results;
using Newsbot.Collector.Services;
namespace Newsbot.Collector.Api.Controllers.v1;
[ApiController]
[Route("/api/v1/account")]
public class IdentityController : ControllerBase
{
private readonly ILogger<IdentityController> _logger;
private readonly IIdentityService _identityService;
public IdentityController(IIdentityService identityService, ILogger<IdentityController> logger)
{
_identityService = identityService;
_logger = logger;
}
[HttpPost("register")]
public IActionResult Register([FromBody] RegisterUserRequest user)
{
if (!ModelState.IsValid)
{
return new BadRequestObjectResult(new AuthFailedResponse
{
Errors = ModelState.Values
.Select(x => x.Errors
.Select(y => y.ErrorMessage).FirstOrDefault())
});
}
if (user.Email is null)
{
return new BadRequestResult();
}
if (user.Password is null)
{
return new BadRequestResult();
}
var response = _identityService.Register(user.Email, user.Password);
return CheckIfSuccessful(response);
}
[HttpPost("login")]
public IActionResult Login([FromBody] UserLoginRequest request)
{
if (request.Email is null)
{
return new BadRequestResult();
}
if (request.Password is null)
{
return new BadRequestResult();
}
var response = _identityService.Login(request.Email, request.Password);
return CheckIfSuccessful(response);
}
[HttpPost("refresh")]
public ActionResult RefreshToken([FromBody] UserRefreshTokenRequest request)
{
var response = _identityService.RefreshToken(request.Token ?? "", request.RefreshToken ?? "");
return CheckIfSuccessful(response);
}
[HttpPost("addRole")]
[Authorize(Roles = Authorization.AdministratorsRole)]
public ActionResult AddRole([FromBody] AddRoleRequest request)
{
try
{
_identityService.AddRole(request.RoleName ?? "", request.UserId ?? "");
return new OkResult();
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Failed to add role to user");
return new BadRequestResult();
}
}
private ActionResult CheckIfSuccessful(AuthenticationResult result)
{
if (!result.IsSuccessful)
{
return new BadRequestObjectResult( new AuthFailedResponse
{
Errors = result.ErrorMessage
});
}
return new OkObjectResult(new AuthSuccessfulResponse
{
Token = result.Token,
RefreshToken = result.RefreshToken
});
}
}

View File

@ -1,49 +0,0 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newsbot.Collector.Api.Authentication;
using Newsbot.Collector.Api.Middleware;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces;
namespace Newsbot.Collector.Api.Controllers.v1;
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[ApiController]
[Route("api/v1/user")]
public class UserController : Controller
{
private readonly ILogger<UserController> _logger;
private readonly IUserSourceSubscription _subscription;
public UserController(ILogger<UserController> logger, IUserSourceSubscription subscription)
{
_logger = logger;
_subscription = subscription;
}
[HttpPost("listSubscriptions")]
public ActionResult ListSubscriptions()
{
_logger.LogInformation("'/api/v1/user/listSubscriptions' was requested");
var userId = HttpContext.GetUserId();
if (userId.Equals(string.Empty))
{
_logger.LogWarning("Unable to find the user ID in the JWD Token");
return new BadRequestResult();
}
try
{
var results = _subscription.ListUserSubscriptions(Guid.Parse(userId));
return new OkObjectResult(results);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to pull subscriptions for userId \'{UserId}\'", userId);
return new NoContentResult();
}
}
}

View File

@ -1,32 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Newsbot.Collector.Domain.Consts;
namespace Newsbot.Collector.Api.Filters;
[AttributeUsage(AttributeTargets.Class| AttributeTargets.Method)]
public class ApiKeyAuthAttribute : Attribute, IAsyncActionFilter
{
private const string ApiKeyHeaderName = "X-API-KEY";
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
if (!context.HttpContext.Request.Headers.TryGetValue(ApiKeyHeaderName, out var foundKey))
{
context.Result = new BadRequestResult();
return;
}
var config = context.HttpContext.RequestServices.GetRequiredService<IConfiguration>();
var apiKeys = config.GetValue<string[]>(ConfigConst.ApiKeys);
foreach (var key in apiKeys ?? Array.Empty<string?>())
{
if (key != foundKey) continue;
await next();
return;
}
context.Result = new BadRequestResult();
}
}

View File

@ -1,9 +0,0 @@
namespace Newsbot.Collector.Api.Middleware;
public static class JwtUserIdExtension
{
public static string GetUserId(this HttpContext context)
{
return context.User.Claims.Single(x => x.Type == "id").Value;
}
}

View File

@ -4,8 +4,6 @@
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
@ -15,13 +13,7 @@
<PackageReference Include="AspNetCore.HealthChecks.UI.Core" Version="6.0.5" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.33" />
<PackageReference Include="Hangfire.MemoryStorage" Version="1.7.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.8" />
<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" />

View File

@ -2,12 +2,14 @@ using Hangfire;
using Hangfire.MemoryStorage;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Newsbot.Collector.Api.Startup;
using Microsoft.OpenApi.Models;
using Newsbot.Collector.Api;
using Newsbot.Collector.Api.Authentication;
using Newsbot.Collector.Domain.Consts;
using Newsbot.Collector.Domain.Models;
using Newsbot.Collector.Domain.Models.Config;
using Newsbot.Collector.Domain.Models.Config.Sources;
using Serilog;
using Serilog.Events;
using ILogger = Serilog.ILogger;
var builder = WebApplication.CreateBuilder(args);
@ -20,41 +22,59 @@ var config = GetConfiguration();
builder.Configuration.AddConfiguration(config);
Log.Logger = GetLogger(config);
Log.Information("Starting up");
// configure Entity Framework
// Allow the controllers to access all the table repositories based on the interface
DatabaseStartup.BuildDatabase(builder.Services, config);
DatabaseStartup.InjectTableClasses(builder.Services);
DatabaseStartup.InjectIdentityService(builder.Services);
// Configure Hangfire
builder.Services.AddHangfire(f => f.UseMemoryStorage());
builder.Services.AddHangfireServer();
GlobalConfiguration.Configuration.UseSerilogLogProvider();
// Build Health Checks
builder.Services.AddHealthChecks()
.AddNpgSql(config.GetValue<string>(ConfigConst.ConnectionStringDatabase) ?? "");
.AddNpgSql(config.GetValue<string>(ConfigConnectionStringConst.Database) ?? "");
builder.Services.AddControllers();
SwaggerStartup.ConfigureSwagger(builder.Services);
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.Configure<ConnectionStrings>(config.GetSection("ConnectionStrings"));
builder.Services.Configure<ConfigSectionConnectionStrings>(config.GetSection(ConfigSectionsConst.ConnectionStrings));
builder.Services.Configure<ConfigSectionRssModel>(config.GetSection(ConfigSectionsConst.Rss));
builder.Services.Configure<ConfigSectionYoutubeModel>(config.GetSection(ConfigSectionsConst.Youtube));
//builder.Services.Configure<
IdentityStartup.DefineJwtRequirements(builder.Services, config);
builder.Services.AddSwaggerGen(cfg =>
{
cfg.AddSecurityDefinition("ApiKey", new OpenApiSecurityScheme
{
Description = "The API key to access the API",
Type = SecuritySchemeType.ApiKey,
Name = "x-api-key",
In = ParameterLocation.Header,
Scheme = "ApiKeyScheme"
});
var scheme = new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "ApiKey"
},
In = ParameterLocation.Header
};
var requirement = new OpenApiSecurityRequirement
{
{ scheme, new List<string>() }
};
cfg.AddSecurityRequirement(requirement);
});
var app = builder.Build();
// Configure the HTTP request pipeline.
// Enable Swagger if requested based on config
if (config.GetValue<bool>(ConfigConst.EnableSwagger))
if (config.GetValue<bool>("EnableSwagger"))
{
app.UseSwagger();
app.UseSwaggerUI();
@ -62,17 +82,13 @@ if (config.GetValue<bool>(ConfigConst.EnableSwagger))
app.UseHttpsRedirection();
// Enable Hangfire background jobs
app.UseHangfireDashboard();
BackgroundJobs.SetupRecurringJobs(config);
app.UseAuthorization();
app.UseAuthentication();
// Add middleware
//app.UseMiddleware<ApiKeyAuthAuthentication>();
app.UseMiddleware<ApiKeyAuthAuthentication>();
// Add HealthChecks
app.MapHealthChecks("/health", new HealthCheckOptions
{
Predicate = _ => true,
@ -80,21 +96,6 @@ app.MapHealthChecks("/health", new HealthCheckOptions
});
app.MapControllers();
// Run Database Migrations if requested
using var serviceScope = app.Services.CreateScope();
if (config.GetValue<bool>(ConfigConst.RunDatabaseMigrationsOnStartup))
{
await DatabaseStartup.RunDatabaseMigrationsAsync(serviceScope);
}
else
{
Log.Warning("Database Migrations have been skipped. Make sure you run them on your own");
}
// Inject the roles
await DatabaseStartup.InjectIdentityRolesAsync(serviceScope);
// Start the application
app.Run();
@ -102,14 +103,13 @@ static IConfiguration GetConfiguration()
{
return new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true)
.AddJsonFile("config/appsettings.json", true)
.AddEnvironmentVariables()
.Build();
}
static ILogger GetLogger(IConfiguration configuration)
{
var otel = configuration.GetValue<string>(ConfigConst.ConnectionStringOpenTelemetry) ?? "";
var otel = configuration.GetValue<string>(ConfigConnectionStringConst.OpenTelemetry) ?? "";
if (otel == "")
return Log.Logger = new LoggerConfiguration()
@ -128,4 +128,4 @@ static ILogger GetLogger(IConfiguration configuration)
{ "service.name", "newsbot-collector-api" }
})
.CreateLogger();
}
}

View File

@ -1,62 +0,0 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Newsbot.Collector.Api.Domain.Consts;
using Newsbot.Collector.Database;
using Newsbot.Collector.Database.Repositories;
using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Services;
namespace Newsbot.Collector.Api.Startup;
public class DatabaseStartup
{
public static void BuildDatabase(IServiceCollection services, IConfiguration config)
{
var dbconn = config.GetConnectionString("Database");
services.AddDbContext<DatabaseContext>(o => o.UseNpgsql(dbconn ?? ""));
// Add identity to our ef connection
services.AddIdentity<IdentityUser, IdentityRole>()
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<DatabaseContext>();
}
public static void InjectTableClasses(IServiceCollection services)
{
services.AddScoped<IArticlesRepository, ArticlesTable>();
services.AddScoped<IDiscordQueueRepository, DiscordQueueTable>();
services.AddScoped<IDiscordWebHooksRepository, DiscordWebhooksTable>();
services.AddScoped<IIconsRepository, IconsTable>();
services.AddScoped<ISourcesRepository, SourcesTable>();
services.AddScoped<IDiscordNotificationRepository, DiscordNotificationTable>();
services.AddScoped<IUserSourceSubscription, UserSourceSubscriptionTable>();
services.AddScoped<IRefreshTokenRepository, RefreshTokenTable>();
services.AddScoped<IAuthorTable, AuthorsTable>();
}
public static void InjectIdentityService(IServiceCollection services)
{
// Configure Identity
services.AddScoped<IIdentityService, IdentityService>();
}
public static async Task RunDatabaseMigrationsAsync(IServiceScope serviceScope)
{
var dbContext = serviceScope.ServiceProvider.GetRequiredService<DatabaseContext>();
await dbContext.Database.MigrateAsync();
}
public static async Task InjectIdentityRolesAsync(IServiceScope serviceScope)
{
var roleManager = serviceScope.ServiceProvider.GetRequiredService<RoleManager<IdentityRole>>();
if (!await roleManager.RoleExistsAsync(Authorization.AdministratorsRole))
{
await roleManager.CreateAsync(new IdentityRole(Authorization.AdministratorsRole));
}
if (!await roleManager.RoleExistsAsync(Authorization.UsersRole))
{
await roleManager.CreateAsync(new IdentityRole(Authorization.UsersRole));
}
}
}

View File

@ -1,52 +0,0 @@
using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using Newsbot.Collector.Api.Domain.Consts;
using Newsbot.Collector.Domain.Models.Config;
namespace Newsbot.Collector.Api.Startup;
public static class IdentityStartup
{
public static void DefineJwtRequirements(IServiceCollection services, IConfiguration config)
{
// Configure JWT for auth and load it into DI so we can use it in the controllers
var jwtSettings = new JwtSettings();
config.Bind(nameof(jwtSettings), jwtSettings);
services.AddSingleton(jwtSettings);
// Configure how the Token Validation will be handled
var tokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtSettings.Secret ?? "")),
ValidateIssuer = false,
ValidateAudience = false,
RequireExpirationTime = false,
ValidateLifetime = true
};
services.AddSingleton(tokenValidationParameters);
// Build the Authentication that will be used
services.AddAuthentication(x =>
{
x.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(x =>
{
x.SaveToken = true;
x.TokenValidationParameters = tokenValidationParameters;
});
// Build the Authorization Policy that the users will conform to.
services.AddAuthorization(options =>
{
options.AddPolicy(Authorization.AdministratorPolicy,
b => b.RequireRole(Authorization.AdministratorsRole, "true"));
options.AddPolicy(Authorization.UserPolicy,
b => b.RequireRole(Authorization.UsersRole, "true"));
});
}
}

View File

@ -1,67 +0,0 @@
using Microsoft.OpenApi.Models;
namespace Newsbot.Collector.Api.Startup;
public static class SwaggerStartup
{
public static void ConfigureSwagger(IServiceCollection services)
{
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();
// Configure swagger authentication
services.AddSwaggerGen(cfg =>
{
cfg.AddSecurityDefinition("ApiKey", new OpenApiSecurityScheme
{
Description = "The API key to access the API",
Type = SecuritySchemeType.ApiKey,
Name = "x-api-key",
In = ParameterLocation.Header,
Scheme = "ApiKeyScheme"
});
cfg.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description = "JWT Authorization Header using the bearer scheme",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey
});
cfg.AddSecurityRequirement(new OpenApiSecurityRequirement
{
//{
// new OpenApiSecurityScheme
// {
// Reference = new OpenApiReference
// {
// Type = ReferenceType.SecurityScheme,
// Id = "ApiKey"
// },
// In = ParameterLocation.Header
// },
// new List<string>()
//},
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
},
Scheme = "oauth2",
Name = "Bearer",
In = ParameterLocation.Header
},
new List<string>()
}
});
});
}
}

View File

@ -1,68 +0,0 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newsbot.Collector.Domain.Consts;
using Newsbot.Collector.Domain.Entities;
namespace Newsbot.Collector.Database;
public class DatabaseContext : IdentityDbContext
{
public DbSet<ArticlesEntity> Articles { get; set; } = null!;
public DbSet<DiscordNotificationEntity> DiscordNotification { get; set; } = null!;
public DbSet<DiscordQueueEntity> DiscordQueue { get; set; } = null!;
public DbSet<DiscordWebhookEntity> DiscordWebhooks { get; set; } = null!;
public DbSet<IconEntity> Icons { get; set; } = null!;
public DbSet<SourceEntity> Sources { get; set; } = null!;
public DbSet<AuthorEntity> Authors { get; set; } = null!;
public DbSet<UserSourceSubscriptionEntity> UserSourceSubscription { get; set; } = null!;
public DbSet<RefreshTokenEntity> RefreshTokens { get; set; } = null!;
private string ConnectionString { get; set; } = "";
//public DatabaseContext(IConfiguration appsettings, string connectionString)
//{
// var connString = appsettings.GetConnectionString(ConfigConnectionStringConst.Database);
// ConnectionString = connString ?? "";
//}
public DatabaseContext(string connectionString)
{
ConnectionString = connectionString;
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (ConnectionString != "")
{
options.UseNpgsql(ConnectionString);
}
}
//public DatabaseContext(DbContextOptions<DatabaseContext> connectionString)
//{
// ConnectionString = "";
//}
//public DatabaseContext()
//{
// ConnectionString = "";
//}
public DatabaseContext(DbContextOptions<DatabaseContext> options)
: base(options)
{
//ConnectionString = "";
}
public DatabaseContext(DbContextOptions<DatabaseContext> options, string connectionString)
: base(options)
{
//ConnectionString = connectionString;
}
}

View File

@ -1,16 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
namespace Newsbot.Collector.Database;
public class DesignTimeContext :IDesignTimeDbContextFactory<DatabaseContext>
{
public DatabaseContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
// pass your design time connection string here
optionsBuilder.UseNpgsql("<connection_string>");
return new DatabaseContext(optionsBuilder.Options);
}
}

View File

@ -1,223 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Newsbot.Collector.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
[DbContext(typeof(DatabaseContext))]
[Migration("20230619043102_MigrationFromGoose")]
partial class MigrationFromGoose
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.ArticlesEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AuthorImage")
.HasColumnType("text");
b.Property<string>("AuthorName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("CodeIsCommit")
.HasColumnType("boolean");
b.Property<bool>("CodeIsRelease")
.HasColumnType("boolean");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("PubDate")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Thumbnail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<string>("Video")
.IsRequired()
.HasColumnType("text");
b.Property<int>("VideoHeight")
.HasColumnType("integer");
b.Property<int>("VideoWidth")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Articles");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordQueueEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("DiscordQueue");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordWebhookEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Channel")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Server")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DiscordWebhooks");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.IconEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FileName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("Icons");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.SourceEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("Deleted")
.HasColumnType("boolean");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Source")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.Property<string>("YoutubeId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Sources");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.SubscriptionEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("CodeAllowCommits")
.HasColumnType("boolean");
b.Property<bool>("CodeAllowReleases")
.HasColumnType("boolean");
b.Property<Guid>("DiscordWebHookId")
.HasColumnType("uuid");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("Subscriptions");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,140 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.Extensions.Configuration;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
/// <inheritdoc />
public partial class MigrationFromGoose : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Articles",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
SourceId = table.Column<Guid>(type: "uuid", nullable: false),
Tags = table.Column<string>(type: "text", nullable: false),
Title = table.Column<string>(type: "text", nullable: false),
Url = table.Column<string>(type: "text", nullable: true),
PubDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Video = table.Column<string>(type: "text", nullable: false),
VideoHeight = table.Column<int>(type: "integer", nullable: false),
VideoWidth = table.Column<int>(type: "integer", nullable: false),
Thumbnail = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: false),
AuthorName = table.Column<string>(type: "text", nullable: false),
AuthorImage = table.Column<string>(type: "text", nullable: true),
CodeIsRelease = table.Column<bool>(type: "boolean", nullable: false),
CodeIsCommit = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Articles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "DiscordQueue",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
ArticleId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DiscordQueue", x => x.Id);
});
migrationBuilder.CreateTable(
name: "DiscordWebhooks",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Url = table.Column<string>(type: "text", nullable: false),
Server = table.Column<string>(type: "text", nullable: false),
Channel = table.Column<string>(type: "text", nullable: false),
Enabled = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DiscordWebhooks", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Icons",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
FileName = table.Column<string>(type: "text", nullable: false),
Site = table.Column<string>(type: "text", nullable: false),
SourceId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Icons", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Sources",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Site = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Source = table.Column<string>(type: "text", nullable: false),
Type = table.Column<string>(type: "text", nullable: false),
Value = table.Column<string>(type: "text", nullable: false),
Enabled = table.Column<bool>(type: "boolean", nullable: false),
Url = table.Column<string>(type: "text", nullable: false),
Tags = table.Column<string>(type: "text", nullable: false),
Deleted = table.Column<bool>(type: "boolean", nullable: false),
YoutubeId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Sources", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Subscriptions",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
CodeAllowReleases = table.Column<bool>(type: "boolean", nullable: false),
CodeAllowCommits = table.Column<bool>(type: "boolean", nullable: false),
SourceId = table.Column<Guid>(type: "uuid", nullable: false),
DiscordWebHookId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Subscriptions", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Articles");
migrationBuilder.DropTable(
name: "DiscordQueue");
migrationBuilder.DropTable(
name: "DiscordWebhooks");
migrationBuilder.DropTable(
name: "Icons");
migrationBuilder.DropTable(
name: "Sources");
migrationBuilder.DropTable(
name: "Subscriptions");
}
}
}

View File

@ -1,470 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Newsbot.Collector.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
[DbContext(typeof(DatabaseContext))]
[Migration("20230629222603_identity")]
partial class identity
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.ArticlesEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AuthorImage")
.HasColumnType("text");
b.Property<string>("AuthorName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("CodeIsCommit")
.HasColumnType("boolean");
b.Property<bool>("CodeIsRelease")
.HasColumnType("boolean");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("PubDate")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Thumbnail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<string>("Video")
.IsRequired()
.HasColumnType("text");
b.Property<int>("VideoHeight")
.HasColumnType("integer");
b.Property<int>("VideoWidth")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Articles");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordQueueEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("DiscordQueue");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordWebhookEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Channel")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Server")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DiscordWebhooks");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.IconEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FileName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("Icons");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.SourceEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("Deleted")
.HasColumnType("boolean");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Source")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.Property<string>("YoutubeId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Sources");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.SubscriptionEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("CodeAllowCommits")
.HasColumnType("boolean");
b.Property<bool>("CodeAllowReleases")
.HasColumnType("boolean");
b.Property<Guid>("DiscordWebHookId")
.HasColumnType("uuid");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,223 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
/// <inheritdoc />
public partial class identity : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AspNetRoles",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
NormalizedName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
UserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
Email = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(type: "boolean", nullable: false),
PasswordHash = table.Column<string>(type: "text", nullable: true),
SecurityStamp = table.Column<string>(type: "text", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true),
PhoneNumber = table.Column<string>(type: "text", nullable: true),
PhoneNumberConfirmed = table.Column<bool>(type: "boolean", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "boolean", nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
LockoutEnabled = table.Column<bool>(type: "boolean", nullable: false),
AccessFailedCount = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUsers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetRoleClaims",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
RoleId = table.Column<string>(type: "text", nullable: false),
ClaimType = table.Column<string>(type: "text", nullable: true),
ClaimValue = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserClaims",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<string>(type: "text", nullable: false),
ClaimType = table.Column<string>(type: "text", nullable: true),
ClaimValue = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserLogins",
columns: table => new
{
LoginProvider = table.Column<string>(type: "text", nullable: false),
ProviderKey = table.Column<string>(type: "text", nullable: false),
ProviderDisplayName = table.Column<string>(type: "text", nullable: true),
UserId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
table.ForeignKey(
name: "FK_AspNetUserLogins_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserRoles",
columns: table => new
{
UserId = table.Column<string>(type: "text", nullable: false),
RoleId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserTokens",
columns: table => new
{
UserId = table.Column<string>(type: "text", nullable: false),
LoginProvider = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Value = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
table.ForeignKey(
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_AspNetRoleClaims_RoleId",
table: "AspNetRoleClaims",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "RoleNameIndex",
table: "AspNetRoles",
column: "NormalizedName",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_AspNetUserClaims_UserId",
table: "AspNetUserClaims",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserLogins_UserId",
table: "AspNetUserLogins",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserRoles_RoleId",
table: "AspNetUserRoles",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "EmailIndex",
table: "AspNetUsers",
column: "NormalizedEmail");
migrationBuilder.CreateIndex(
name: "UserNameIndex",
table: "AspNetUsers",
column: "NormalizedUserName",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AspNetRoleClaims");
migrationBuilder.DropTable(
name: "AspNetUserClaims");
migrationBuilder.DropTable(
name: "AspNetUserLogins");
migrationBuilder.DropTable(
name: "AspNetUserRoles");
migrationBuilder.DropTable(
name: "AspNetUserTokens");
migrationBuilder.DropTable(
name: "AspNetRoles");
migrationBuilder.DropTable(
name: "AspNetUsers");
}
}
}

View File

@ -1,501 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Newsbot.Collector.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
[DbContext(typeof(DatabaseContext))]
[Migration("20230710050618_SourcesRenamed")]
partial class SourcesRenamed
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.ArticlesEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AuthorImage")
.HasColumnType("text");
b.Property<string>("AuthorName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("CodeIsCommit")
.HasColumnType("boolean");
b.Property<bool>("CodeIsRelease")
.HasColumnType("boolean");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("PubDate")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Thumbnail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<string>("Video")
.IsRequired()
.HasColumnType("text");
b.Property<int>("VideoHeight")
.HasColumnType("integer");
b.Property<int>("VideoWidth")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Articles");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordNotificationEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("CodeAllowCommits")
.HasColumnType("boolean");
b.Property<bool>("CodeAllowReleases")
.HasColumnType("boolean");
b.Property<Guid>("DiscordWebHookId")
.HasColumnType("uuid");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("DiscordNotification");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordQueueEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("DiscordQueue");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordWebhookEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Channel")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Server")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DiscordWebhooks");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.IconEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FileName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("Icons");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.SourceEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("Deleted")
.HasColumnType("boolean");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Source")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.Property<string>("YoutubeId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Sources");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.UserSourceSubscriptionEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateAdded")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("UserSourceSubscription");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.UserSourceSubscriptionEntity", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,82 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
/// <inheritdoc />
public partial class SourcesRenamed : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Subscriptions");
migrationBuilder.CreateTable(
name: "DiscordNotification",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
CodeAllowReleases = table.Column<bool>(type: "boolean", nullable: false),
CodeAllowCommits = table.Column<bool>(type: "boolean", nullable: false),
SourceId = table.Column<Guid>(type: "uuid", nullable: false),
DiscordWebHookId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DiscordNotification", x => x.Id);
});
migrationBuilder.CreateTable(
name: "UserSourceSubscription",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
SourceId = table.Column<Guid>(type: "uuid", nullable: false),
DateAdded = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
UserId = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_UserSourceSubscription", x => x.Id);
table.ForeignKey(
name: "FK_UserSourceSubscription_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_UserSourceSubscription_UserId",
table: "UserSourceSubscription",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DiscordNotification");
migrationBuilder.DropTable(
name: "UserSourceSubscription");
migrationBuilder.CreateTable(
name: "Subscriptions",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
CodeAllowCommits = table.Column<bool>(type: "boolean", nullable: false),
CodeAllowReleases = table.Column<bool>(type: "boolean", nullable: false),
DiscordWebHookId = table.Column<Guid>(type: "uuid", nullable: false),
SourceId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Subscriptions", x => x.Id);
});
}
}
}

View File

@ -1,504 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Newsbot.Collector.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
[DbContext(typeof(DatabaseContext))]
[Migration("20230710050913_DiscordNotificationOwnerAdded")]
partial class DiscordNotificationOwnerAdded
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.ArticlesEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AuthorImage")
.HasColumnType("text");
b.Property<string>("AuthorName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("CodeIsCommit")
.HasColumnType("boolean");
b.Property<bool>("CodeIsRelease")
.HasColumnType("boolean");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("PubDate")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Thumbnail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<string>("Video")
.IsRequired()
.HasColumnType("text");
b.Property<int>("VideoHeight")
.HasColumnType("integer");
b.Property<int>("VideoWidth")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Articles");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordNotificationEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("CodeAllowCommits")
.HasColumnType("boolean");
b.Property<bool>("CodeAllowReleases")
.HasColumnType("boolean");
b.Property<Guid>("DiscordWebHookId")
.HasColumnType("uuid");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DiscordNotification");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordQueueEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("DiscordQueue");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordWebhookEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Channel")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Server")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DiscordWebhooks");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.IconEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FileName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("Icons");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.SourceEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("Deleted")
.HasColumnType("boolean");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Source")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.Property<string>("YoutubeId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Sources");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.UserSourceSubscriptionEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateAdded")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("UserSourceSubscription");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.UserSourceSubscriptionEntity", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,28 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
/// <inheritdoc />
public partial class DiscordNotificationOwnerAdded : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "UserId",
table: "DiscordNotification",
type: "text",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "UserId",
table: "DiscordNotification");
}
}
}

View File

@ -1,543 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Newsbot.Collector.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
[DbContext(typeof(DatabaseContext))]
[Migration("20230711033558_add_jwt_token_refresh_table")]
partial class add_jwt_token_refresh_table
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.ArticlesEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AuthorImage")
.HasColumnType("text");
b.Property<string>("AuthorName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("CodeIsCommit")
.HasColumnType("boolean");
b.Property<bool>("CodeIsRelease")
.HasColumnType("boolean");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("PubDate")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Thumbnail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<string>("Video")
.IsRequired()
.HasColumnType("text");
b.Property<int>("VideoHeight")
.HasColumnType("integer");
b.Property<int>("VideoWidth")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Articles");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordNotificationEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("CodeAllowCommits")
.HasColumnType("boolean");
b.Property<bool>("CodeAllowReleases")
.HasColumnType("boolean");
b.Property<Guid>("DiscordWebHookId")
.HasColumnType("uuid");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DiscordNotification");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordQueueEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("DiscordQueue");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordWebhookEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Channel")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Server")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DiscordWebhooks");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.IconEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FileName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("Icons");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.RefreshTokenEntity", b =>
{
b.Property<string>("Token")
.HasColumnType("text");
b.Property<DateTime>("CreatedDate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("ExpiryDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("Invalidated")
.HasColumnType("boolean");
b.Property<string>("JwtId")
.HasColumnType("text");
b.Property<bool>("Used")
.HasColumnType("boolean");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Token");
b.HasIndex("UserId");
b.ToTable("RefreshTokens");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.SourceEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("Deleted")
.HasColumnType("boolean");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Source")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.Property<string>("YoutubeId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Sources");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.UserSourceSubscriptionEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateAdded")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("UserSourceSubscription");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.RefreshTokenEntity", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.UserSourceSubscriptionEntity", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,49 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
/// <inheritdoc />
public partial class add_jwt_token_refresh_table : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "RefreshTokens",
columns: table => new
{
Token = table.Column<string>(type: "text", nullable: false),
JwtId = table.Column<string>(type: "text", nullable: true),
CreatedDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
ExpiryDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Used = table.Column<bool>(type: "boolean", nullable: false),
Invalidated = table.Column<bool>(type: "boolean", nullable: false),
UserId = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_RefreshTokens", x => x.Token);
table.ForeignKey(
name: "FK_RefreshTokens_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_RefreshTokens_UserId",
table: "RefreshTokens",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "RefreshTokens");
}
}
}

View File

@ -1,579 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Newsbot.Collector.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
[DbContext(typeof(DatabaseContext))]
[Migration("20230729170139_Adding Author Table")]
partial class AddingAuthorTable
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.ArticlesEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AuthorImage")
.HasColumnType("text");
b.Property<string>("AuthorName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("CodeIsCommit")
.HasColumnType("boolean");
b.Property<bool>("CodeIsRelease")
.HasColumnType("boolean");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("PubDate")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Thumbnail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<string>("Video")
.IsRequired()
.HasColumnType("text");
b.Property<int>("VideoHeight")
.HasColumnType("integer");
b.Property<int>("VideoWidth")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Articles");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.AuthorEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("Authors");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordNotificationEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("CodeAllowCommits")
.HasColumnType("boolean");
b.Property<bool>("CodeAllowReleases")
.HasColumnType("boolean");
b.Property<Guid>("DiscordWebHookId")
.HasColumnType("uuid");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DiscordNotification");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordQueueEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("DiscordQueue");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordWebhookEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Channel")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Server")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("DiscordWebhooks");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.IconEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FileName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("Icons");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.RefreshTokenEntity", b =>
{
b.Property<string>("Token")
.HasColumnType("text");
b.Property<DateTime>("CreatedDate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("ExpiryDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("Invalidated")
.HasColumnType("boolean");
b.Property<string>("JwtId")
.HasColumnType("text");
b.Property<bool>("Used")
.HasColumnType("boolean");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Token");
b.HasIndex("UserId");
b.ToTable("RefreshTokens");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.SourceEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("Deleted")
.HasColumnType("boolean");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Source")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.Property<string>("YoutubeId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Sources");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.UserSourceSubscriptionEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateAdded")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("UserSourceSubscription");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordWebhookEntity", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.RefreshTokenEntity", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.UserSourceSubscriptionEntity", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,66 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
/// <inheritdoc />
public partial class AddingAuthorTable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "UserId",
table: "DiscordWebhooks",
type: "text",
nullable: true);
migrationBuilder.CreateTable(
name: "Authors",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
SourceId = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Image = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Authors", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_DiscordWebhooks_UserId",
table: "DiscordWebhooks",
column: "UserId");
migrationBuilder.AddForeignKey(
name: "FK_DiscordWebhooks_AspNetUsers_UserId",
table: "DiscordWebhooks",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_DiscordWebhooks_AspNetUsers_UserId",
table: "DiscordWebhooks");
migrationBuilder.DropTable(
name: "Authors");
migrationBuilder.DropIndex(
name: "IX_DiscordWebhooks_UserId",
table: "DiscordWebhooks");
migrationBuilder.DropColumn(
name: "UserId",
table: "DiscordWebhooks");
}
}
}

View File

@ -1,575 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Newsbot.Collector.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
[DbContext(typeof(DatabaseContext))]
[Migration("20230805060324_add author table")]
partial class addauthortable
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.ArticlesEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("AuthorId")
.HasColumnType("uuid");
b.Property<bool>("CodeIsCommit")
.HasColumnType("boolean");
b.Property<bool>("CodeIsRelease")
.HasColumnType("boolean");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("PubDate")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Thumbnail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<string>("Video")
.IsRequired()
.HasColumnType("text");
b.Property<int>("VideoHeight")
.HasColumnType("integer");
b.Property<int>("VideoWidth")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Articles");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.AuthorEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("Authors");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordNotificationEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("CodeAllowCommits")
.HasColumnType("boolean");
b.Property<bool>("CodeAllowReleases")
.HasColumnType("boolean");
b.Property<Guid>("DiscordWebHookId")
.HasColumnType("uuid");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DiscordNotification");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordQueueEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("DiscordQueue");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordWebhookEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Channel")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Server")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("DiscordWebhooks");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.IconEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FileName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("Icons");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.RefreshTokenEntity", b =>
{
b.Property<string>("Token")
.HasColumnType("text");
b.Property<DateTime>("CreatedDate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("ExpiryDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("Invalidated")
.HasColumnType("boolean");
b.Property<string>("JwtId")
.HasColumnType("text");
b.Property<bool>("Used")
.HasColumnType("boolean");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Token");
b.HasIndex("UserId");
b.ToTable("RefreshTokens");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.SourceEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("Deleted")
.HasColumnType("boolean");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Source")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.Property<string>("YoutubeId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Sources");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.UserSourceSubscriptionEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateAdded")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("UserSourceSubscription");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordWebhookEntity", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.RefreshTokenEntity", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.UserSourceSubscriptionEntity", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,51 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
/// <inheritdoc />
public partial class addauthortable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "AuthorImage",
table: "Articles");
migrationBuilder.DropColumn(
name: "AuthorName",
table: "Articles");
migrationBuilder.AddColumn<Guid>(
name: "AuthorId",
table: "Articles",
type: "uuid",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "AuthorId",
table: "Articles");
migrationBuilder.AddColumn<string>(
name: "AuthorImage",
table: "Articles",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "AuthorName",
table: "Articles",
type: "text",
nullable: false,
defaultValue: "");
}
}
}

View File

@ -1,572 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Newsbot.Collector.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Newsbot.Collector.Database.Migrations
{
[DbContext(typeof(DatabaseContext))]
partial class DatabaseContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.ArticlesEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("AuthorId")
.HasColumnType("uuid");
b.Property<bool>("CodeIsCommit")
.HasColumnType("boolean");
b.Property<bool>("CodeIsRelease")
.HasColumnType("boolean");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("PubDate")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Thumbnail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<string>("Video")
.IsRequired()
.HasColumnType("text");
b.Property<int>("VideoHeight")
.HasColumnType("integer");
b.Property<int>("VideoWidth")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Articles");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.AuthorEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("Authors");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordNotificationEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("CodeAllowCommits")
.HasColumnType("boolean");
b.Property<bool>("CodeAllowReleases")
.HasColumnType("boolean");
b.Property<Guid>("DiscordWebHookId")
.HasColumnType("uuid");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("DiscordNotification");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordQueueEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("DiscordQueue");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordWebhookEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Channel")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Server")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("DiscordWebhooks");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.IconEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FileName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("Icons");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.RefreshTokenEntity", b =>
{
b.Property<string>("Token")
.HasColumnType("text");
b.Property<DateTime>("CreatedDate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("ExpiryDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("Invalidated")
.HasColumnType("boolean");
b.Property<string>("JwtId")
.HasColumnType("text");
b.Property<bool>("Used")
.HasColumnType("boolean");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Token");
b.HasIndex("UserId");
b.ToTable("RefreshTokens");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.SourceEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<bool>("Deleted")
.HasColumnType("boolean");
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Site")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Source")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Tags")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.Property<string>("YoutubeId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Sources");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.UserSourceSubscriptionEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateAdded")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SourceId")
.HasColumnType("uuid");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("UserSourceSubscription");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.DiscordWebhookEntity", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.RefreshTokenEntity", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("Newsbot.Collector.Domain.Entities.UserSourceSubscriptionEntity", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -6,24 +6,14 @@
<ItemGroup>
<PackageReference Include="dapper" Version="2.0.123" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.8">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Npgsql" Version="7.0.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
<PackageReference Include="Npgsql" Version="7.0.2" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>8981</NoWarn>
</PropertyGroup>
</Project>

View File

@ -1,8 +1,6 @@
using System.Data;
using Dapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Models;
using Npgsql;
@ -11,78 +9,68 @@ namespace Newsbot.Collector.Database.Repositories;
public class ArticlesTable : IArticlesRepository
{
//private readonly string _connectionString;
private DatabaseContext _context;
private readonly string _connectionString;
public ArticlesTable(string connectionString)
{
//_connectionString = connectionString;
_context = new DatabaseContext(connectionString);
_connectionString = connectionString;
}
public ArticlesTable(DatabaseContext context)
public ArticlesTable(IConfiguration configuration)
{
_context = context;
var conn = configuration.GetConnectionString("database");
if (conn is null) conn = "";
_connectionString = conn;
}
//public ArticlesTable(IConfiguration configuration)
//{
// var conn = configuration.GetConnectionString("database");
// if (conn is null) conn = "";
//
// _context = new DatabaseContext(conn);
//}
public List<ArticlesEntity> List(int page = 0, int count = 25)
public List<ArticlesModel> List(int page = 0, int count = 25)
{
//using var context = new DatabaseContext(_connectionString);
var query = _context.Articles
.Skip(page * count)
.OrderBy(d => d.PubDate)
.Take(25);
Console.WriteLine(query.ToQueryString());
return query.ToList();
}
public ArticlesEntity GetById(Guid id)
{
//using var context = new DatabaseContext(_connectionString);
var query = _context.Articles
.FirstOrDefault(d => d.Id.Equals(id));
query ??= new ArticlesEntity();
return query;
}
public ArticlesEntity GetByUrl(string url)
{
//using var context = new DatabaseContext(_connectionString);
var res = _context.Articles.FirstOrDefault(d => d.Url!.Equals(url));
res ??= new ArticlesEntity();
using var conn = OpenConnection(_connectionString);
var res = conn.Query<ArticlesModel>(@"select * from articles
Order By PubDate Desc
Offset @Page
Fetch Next @Count Rows Only", new
{
Page = page * count,
Count = count
})
.ToList();
return res;
}
public List<ArticlesEntity> ListBySourceId(Guid id, int page, int count)
public ArticlesModel GetById(Guid ID)
{
//using var context = new DatabaseContext(_connectionString);
var res = _context.Articles
.Skip(page * count)
.Where(d => d.SourceId.Equals(id));
return res.ToList();
using var conn = OpenConnection(_connectionString);
var res = conn.Query<ArticlesModel>("select * from articles where ID = @ID", new { ID });
if (res.Count() == 0) return new ArticlesModel();
return res.First();
}
public ArticlesEntity New(ArticlesEntity model)
public ArticlesModel GetByUrl(string url)
{
//using var context = new DatabaseContext(_connectionString);
model.Id = new Guid();
var query = _context.Articles.Add(model);
_context.SaveChanges();
return model;
using var conn = OpenConnection(_connectionString);
var res = conn.Query<ArticlesModel>("select * from articles where Url = @Url Limit 1", new { Url = url });
if (res.Count() == 0) return new ArticlesModel();
return res.First();
}
/*
public ArticlesModel NewDapper(ArticlesModel model)
public List<ArticlesModel> ListBySourceId(Guid id, int page, int count)
{
using var conn = OpenConnection(_connectionString);
var query = @"Select * from articles
where sourceid = @sourceid
Offset @page
Fetch next @count rows only";
return conn.Query<ArticlesModel>(query, new
{
sourceid = id,
page = page * count,
count
}).ToList();
}
public ArticlesModel New(ArticlesModel model)
{
model.ID = Guid.NewGuid();
@ -109,27 +97,21 @@ public class ArticlesTable : IArticlesRepository
});
return model;
}
*/
public void DeleteAllBySourceId(Guid sourceId)
{
//using var context = new DatabaseContext(_connectionString);
var res = _context.Articles
.Where(d => d.SourceId.Equals(sourceId))
.ToList();
foreach (var item in res)
using var conn = OpenConnection(_connectionString);
var res = conn.Execute("Delete from articles where sourceid = '@id'", new
{
_context.Articles.Remove(item);
}
_context.SaveChanges();
sourceId
});
if (res == 0) throw new Exception($"No records where deleted that linked to SourceId = '{sourceId}'");
}
//private IDbConnection OpenConnection(string connectionString)
//{
// //var conn = new NpgsqlConnection(_connectionString);
// //conn.Open();
// //return conn;
//}
private IDbConnection OpenConnection(string connectionString)
{
var conn = new NpgsqlConnection(_connectionString);
conn.Open();
return conn;
}
}

View File

@ -1,67 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces;
namespace Newsbot.Collector.Database.Repositories;
public class AuthorsTable : IAuthorTable
{
private readonly DatabaseContext _context;
public AuthorsTable(string connectionString)
{
//_connectionString = connectionString;
_context = new DatabaseContext(connectionString);
}
public AuthorsTable(DatabaseContext context)
{
_context = context;
}
public async Task<AuthorEntity> NewAsync(AuthorEntity entity)
{
entity.Id = Guid.NewGuid();
_context.Authors.Add(entity);
await _context.SaveChangesAsync();
return entity;
}
public async Task<AuthorEntity> CreateIfMissingAsync(AuthorEntity entity)
{
var res = await GetBySourceIdAndNameAsync(entity.SourceId, entity.Name);
if (res is null)
{
entity.Id = Guid.NewGuid();
_context.Authors.Add(entity);
await _context.SaveChangesAsync();
return entity;
}
return res;
}
public async Task<List<AuthorEntity>> ListBySourceIdAsync(Guid sourceId)
{
return await _context.Authors
.Where(s => s.SourceId.Equals(sourceId)).ToListAsync();
}
public async Task<int> TotalPostsAsync(Guid id)
{
return await _context.Authors.CountAsync(x => x.Id.Equals(id));
}
public async Task<AuthorEntity?> GetBySourceIdAndNameAsync(Guid sourceId, string name)
{
return await _context.Authors
.Where(s => s.SourceId.Equals(sourceId))
.FirstOrDefaultAsync(n => n.Name.Equals(name));
}
public async Task<AuthorEntity?> GetById(Guid id)
{
return await _context.Authors.FirstOrDefaultAsync(q => q.Id.Equals(id));
}
}

View File

@ -1,97 +0,0 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces;
namespace Newsbot.Collector.Database.Repositories;
public class DiscordNotificationTable : IDiscordNotificationRepository
{
//private readonly string _connectionString;
private DatabaseContext _context;
public DiscordNotificationTable(string connectionString)
{
//_connectionString = connectionString;
_context = new DatabaseContext(connectionString);
}
public DiscordNotificationTable(DatabaseContext context)
{
_context = context;
}
public DiscordNotificationEntity New(DiscordNotificationEntity model)
{
model.Id = new Guid();
_context.DiscordNotification.Add(model);
_context.SaveChanges();
return model;
}
public List<DiscordNotificationEntity> List(string userId, int page = 0, int count = 25)
{
return _context.DiscordNotification
.Where(x => x.UserId != null && x.UserId.Equals(userId))
.Skip(page * count)
.Take(count)
.ToList();
}
public List<DiscordNotificationEntity> ListBySourceId(string userId, Guid id, int page = 0, int count = 25)
{
return _context.DiscordNotification
.Where(f => f.SourceId.Equals(id))
.Where(f => f.UserId != null && f.UserId.Equals(userId))
.Skip(page * count)
.ToList();
}
public List<DiscordNotificationEntity> ListBySourceId(Guid id, int page = 0, int count = 25)
{
return _context.DiscordNotification
.Where(f => f.SourceId.Equals(id))
.Skip(page * count)
.ToList();
}
public List<DiscordNotificationEntity> ListByWebhook(string userId, Guid id, int page = 0, int count = 25)
{
return _context.DiscordNotification
.Where(f => f.DiscordWebHookId.Equals(id))
.Where(f => f.UserId != null && f.UserId.Equals(userId))
.Skip(page * count)
.ToList();
}
public DiscordNotificationEntity GetById(string userId, Guid id)
{
var res = _context.DiscordNotification
.Where(f => f.UserId != null && f.UserId.Equals(userId))
.FirstOrDefault(f => f.Id.Equals(id));
return res ??= new DiscordNotificationEntity();
}
public DiscordNotificationEntity GetByWebhookAndSource(string userId, Guid webhookId, Guid sourceId)
{
var res = _context.DiscordNotification
.Where(f => f.UserId != null && f.UserId.Equals(userId))
.Where(f => f.DiscordWebHookId.Equals(webhookId))
.FirstOrDefault(f => f.SourceId.Equals(sourceId));
return res ??= new DiscordNotificationEntity();
}
public int Delete(string userId, Guid id)
{
var res = _context.DiscordNotification
.Where(f => f.UserId != null && f.UserId.Equals(userId))
.FirstOrDefault(f => f.Id.Equals(id));
if (res is null)
{
return -1;
}
_context.DiscordNotification.Remove(res);
return _context.SaveChanges();
}
}

View File

@ -1,6 +1,5 @@
using System.Data;
using Dapper;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Models;
using Npgsql;
@ -9,49 +8,47 @@ namespace Newsbot.Collector.Database.Repositories;
public class DiscordQueueTable : IDiscordQueueRepository
{
//private string _connectionString;
private DatabaseContext _context;
private string _connectionString;
public DiscordQueueTable(string connectionString)
{
//_connectionString = connectionString;
_context = new DatabaseContext(connectionString);
_connectionString = connectionString;
}
public DiscordQueueTable(DatabaseContext context)
private IDbConnection OpenConnection(string connectionString)
{
_context = context;
var conn = new NpgsqlConnection(_connectionString);
conn.Open();
return conn;
}
//private IDbConnection OpenConnection(string connectionString)
//{
// var conn = new NpgsqlConnection(_connectionString);
// conn.Open();
// return conn;
//}
public void New(DiscordQueueEntity model)
public void New(DiscordQueueModel model)
{
model.Id = new Guid();
//using var context = new DatabaseContext(_connectionString);
var res = _context.DiscordQueue.Add(model);
_context.SaveChanges();
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
});
}
public void Delete(Guid 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();
using var conn = OpenConnection(_connectionString);
var query = "Delete From DiscordQueue Where ID = @id;";
conn.Execute(query, new
{
id = id
});
}
public List<DiscordQueueEntity> List(int limit = 25)
public List<DiscordQueueModel> List(int limit = 25)
{
//using var context = new DatabaseContext(_connectionString);
var res = _context.DiscordQueue.Take(limit).ToList();
return res;
using var conn = OpenConnection(_connectionString);
var query = "Select * from DiscordQueue LIMIT @limit;";
return conn.Query<DiscordQueueModel>(query, new {
limit = limit
}).ToList();
}
}

View File

@ -1,154 +1,130 @@
using System.Data;
using Dapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models;
using Npgsql;
namespace Newsbot.Collector.Database.Repositories;
public class DiscordWebhooksTable : IDiscordWebHooksRepository
{
//private readonly string _connectionString;
private DatabaseContext _context;
private readonly string _connectionString;
public DiscordWebhooksTable(string connectionString)
{
//_connectionString = connectionString;
_context = new DatabaseContext(connectionString);
_connectionString = connectionString;
}
public DiscordWebhooksTable(DatabaseContext context)
public DiscordWebhooksTable(IConfiguration configuration)
{
_context = context;
var connstr = configuration.GetConnectionString("database") ?? "";
_connectionString = connstr;
}
public DiscordWebhookEntity New(DiscordWebhookEntity model)
public DiscordWebHookModel New(DiscordWebHookModel model)
{
model.Id = new Guid();
//using var context = new DatabaseContext(_connectionString);
_context.DiscordWebhooks.Add(model);
_context.SaveChanges();
var uid = Guid.NewGuid();
using var conn = OpenConnection(_connectionString);
var query =
"Insert Into DiscordWebHooks (ID, Url, Server, Channel, Enabled) Values (@id, @url, @server, @channel, @enabled);";
conn.Execute(query, new
{
id = uid,
url = model.Url,
server = model.Server,
channel = model.Channel,
enabled = model.Enabled
});
model.ID = uid;
return model;
}
public DiscordWebhookEntity GetById(string userId, Guid id)
public DiscordWebHookModel GetByID(Guid id)
{
//using var context = new DatabaseContext(_connectionString);
var res = _context.DiscordWebhooks
.Where(i => i.UserId != null && i.UserId.Equals(userId))
.FirstOrDefault(d => d.Id.Equals(id));
res ??= new DiscordWebhookEntity();
return res;
using var conn = OpenConnection(_connectionString);
var query = "Select * from DiscordWebHooks Where ID = @id LIMIT 1;";
return conn.Query<DiscordWebHookModel>(query, new
{
id
}).First();
}
public DiscordWebhookEntity GetById(Guid id)
public DiscordWebHookModel GetByUrl(string url)
{
var res = _context.DiscordWebhooks
.FirstOrDefault(d => d.Id.Equals(id));
res ??= new DiscordWebhookEntity();
return res;
}
public DiscordWebhookEntity GetByUrl(string url)
{
//using var context = new DatabaseContext(_connectionString);
var res = _context.DiscordWebhooks.FirstOrDefault(d => d.Url.Equals(url));
res ??= new DiscordWebhookEntity();
return res;
}
public List<DiscordWebhookEntity> List(int page, int count = 25)
{
//using var context = new DatabaseContext(_connectionString);
var res = _context.DiscordWebhooks
.Skip(page * count)
.Take(count)
.ToList();
res ??= new List<DiscordWebhookEntity>();
return res;
}
public List<DiscordWebhookEntity> ListByUserId(string userId, int page)
{
var query = _context.DiscordWebhooks
.Where(p => p.UserId != null && p.UserId.Equals(userId))
.Skip(page * 25)
.Take(25)
.ToList();
return query;
}
public List<DiscordWebhookEntity> ListByServer(string server, int limit = 25)
{
//using var context = new DatabaseContext(_connectionString);
var res = _context.DiscordWebhooks
.Where(d => d.Server.Equals(server))
.Take(limit)
.ToList();
res ??= new List<DiscordWebhookEntity>();
return res;
}
public List<DiscordWebhookEntity> ListByServerAndChannel(string userId, string server, string channel, int limit = 25)
{
//using var context = new DatabaseContext(_connectionString);
var res = _context.DiscordWebhooks
.Where(i => i.UserId != null && i.UserId.Equals(userId))
.Where(s => s.Server.Equals(server))
.Where(c => c.Channel.Equals(channel))
.Take(limit)
.ToList();
res ??= new List<DiscordWebhookEntity>();
return res;
}
public int Disable(string userId, Guid id)
{
var res = GetById(userId, id);
//using var context = new DatabaseContext(_connectionString);
res.Enabled = true;
_context.DiscordWebhooks.Update(res);
using var conn = OpenConnection(_connectionString);
var query = "Select * From DiscordWebHooks Where url = @url;";
try
{
_context.SaveChanges();
return 1;
var res = conn.QueryFirst<DiscordWebHookModel>(query, new
{
url
});
return res;
}
catch(Exception ex)
catch
{
Console.WriteLine($"Failed to update DiscordWebhook ID = {id}. {ex.Message}");
return 0;
return new DiscordWebHookModel();
}
}
public int Enable(string userId, Guid id)
public List<DiscordWebHookModel> List(int page, int count = 25)
{
var res = GetById(userId, id);
//using var context = new DatabaseContext(_connectionString);
res.Enabled = false;
_context.DiscordWebhooks.Update(res);
try
using var conn = OpenConnection(_connectionString);
var query = @"Select * From DiscordWebHooks
Offset @offset Fetch Next @count Rows Only;";
return conn.Query<DiscordWebHookModel>(query, new
{
_context.SaveChanges();
return 1;
}
catch(Exception ex)
{
Console.WriteLine($"Failed to update DiscordWebhook ID = {id}. {ex.Message}");
return 0;
}
offset = page * count, count
}).ToList();
}
//private IDbConnection OpenConnection(string connectionString)
//{
// var conn = new NpgsqlConnection(_connectionString);
// conn.Open();
// return conn;
//}
public List<DiscordWebHookModel> ListByServer(string server, int limit = 25)
{
using var conn = OpenConnection(_connectionString);
var query = "Select * From DiscordWebHooks Where Server = @id Limit @limit;";
return conn.Query<DiscordWebHookModel>(query, new
{
server, limit
}).ToList();
}
public List<DiscordWebHookModel> ListByServerAndChannel(string server, string channel, int limit = 25)
{
using var conn = OpenConnection(_connectionString);
var query = "SELECT * FROM DiscordWebHooks WHERE Server = @server and Channel = @channel Limit @limit;";
return conn.Query<DiscordWebHookModel>(query, new
{
server,
channel,
limit
}).ToList();
}
public int Disable(Guid id)
{
using var conn = OpenConnection(_connectionString);
var query = "Update discordwebhooks Set Enabled = FALSE where ID = @id;";
return conn.Execute(query, new
{
id
});
}
public int Enable(Guid id)
{
using var conn = OpenConnection(_connectionString);
var query = "Update discordwebhooks Set Enabled = TRUE where ID = @id;";
return conn.Execute(query, new
{
id
});
}
private IDbConnection OpenConnection(string connectionString)
{
var conn = new NpgsqlConnection(_connectionString);
conn.Open();
return conn;
}
}

View File

@ -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;
@ -10,49 +9,57 @@ namespace Newsbot.Collector.Database.Repositories;
public class IconsTable : IIconsRepository
{
//private readonly string _connectionString;
private DatabaseContext _context;
private readonly string _connectionString;
public IconsTable(string connectionString)
{
//_connectionString = connectionString;
_context = new DatabaseContext(connectionString);
_connectionString = connectionString;
}
public IconsTable(DatabaseContext context)
public IconsTable(IConfiguration configuration)
{
_context = context;
var connstr = configuration.GetConnectionString("database");
if (connstr is null) connstr = "";
_connectionString = connstr;
}
public void New(IconEntity model)
public void New(IconModel model)
{
//using var context = new DatabaseContext(_connectionString);
model.Id = Guid.NewGuid();
_context.Icons.Add(model);
_context.SaveChanges();
using var conn = OpenConnection(_connectionString);
var q = @"Insert Into icons (id, filename, site, sourceid) values (@Id,@FileName, @Site, @SourceId)";
conn.Execute(q, model);
}
public IconEntity GetById(Guid id)
public IconModel GetById(Guid id)
{
//using var context = new DatabaseContext(_connectionString);
var res = _context.Icons.FirstOrDefault(f => f.Id.Equals(id));
res ??= new IconEntity();
return res;
using var conn = OpenConnection(_connectionString);
var query = "Select * From icons where ID = @id Limit 1;";
var res = conn.Query<IconModel>(query, new
{
id
});
if (!res.Any()) return new IconModel();
return res.First();
}
public IconEntity GetBySourceId(Guid id)
public IconModel GetBySourceId(Guid id)
{
//using var context = new DatabaseContext(_connectionString);
var res = _context.Icons.FirstOrDefault(f => f.SourceId.Equals(id));
res ??= new IconEntity();
return res;
using var conn = OpenConnection(_connectionString);
var query = "Select * From icons where sourceid = @id Limit 1;";
var res = conn.Query<IconModel>(query, new
{
id
});
if (!res.Any()) return new IconModel();
return res.First();
}
//private IDbConnection OpenConnection(string connectionString)
//{
// var conn = new NpgsqlConnection(_connectionString);
// conn.Open();
// return conn;
//}
private IDbConnection OpenConnection(string connectionString)
{
var conn = new NpgsqlConnection(_connectionString);
conn.Open();
return conn;
}
}

View File

@ -1,42 +0,0 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces;
namespace Newsbot.Collector.Database.Repositories;
public class RefreshTokenTable : IRefreshTokenRepository
{
private readonly DatabaseContext _context;
public RefreshTokenTable(string connectionString)
{
_context = new DatabaseContext(connectionString);
}
public RefreshTokenTable(DatabaseContext context)
{
_context = context;
}
public void Add(RefreshTokenEntity entity)
{
_context.RefreshTokens.Add(entity);
_context.SaveChanges();
}
public RefreshTokenEntity? Get(string token)
{
return _context.RefreshTokens.SingleOrDefault(x => x.Token == token);
}
public void UpdateTokenIsUsed(string token)
{
var entity = Get(token);
if (entity is null)
{
return;
}
entity.Used = true;
_context.RefreshTokens.Update(entity);
_context.SaveChanges();
}
}

View File

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

View File

@ -0,0 +1,132 @@
using System.Data;
using Dapper;
using Microsoft.Extensions.Configuration;
using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Models;
using Npgsql;
namespace Newsbot.Collector.Database.Repositories;
public class SubscriptionsTable : ISubscriptionRepository
{
private readonly string _connectionString;
public SubscriptionsTable(string connectionString)
{
_connectionString = connectionString;
}
public SubscriptionsTable(IConfiguration configuration)
{
var connstr = configuration.GetConnectionString("database");
if (connstr is null) connstr = "";
_connectionString = connstr;
}
public SubscriptionModel New(SubscriptionModel 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<SubscriptionModel> List(int page = 0, int count = 25)
{
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<SubscriptionModel> ListBySourceID(Guid id, int page = 0, int count = 25)
{
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<SubscriptionModel> ListByWebhook(Guid id, int page = 0, int count = 25)
{
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 SubscriptionModel GetById(Guid id)
{
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 SubscriptionModel GetByWebhookAndSource(Guid webhookId, Guid sourceId)
{
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 conn = OpenConnection(_connectionString);
var query = "Delete From subscriptions Where id = @id;";
conn.Execute(query, new
{
id
});
}
private IDbConnection OpenConnection(string connectionString)
{
var conn = new NpgsqlConnection(_connectionString);
conn.Open();
return conn;
}
}

View File

@ -1,27 +0,0 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Interfaces;
namespace Newsbot.Collector.Database.Repositories;
public class UserSourceSubscriptionTable : IUserSourceSubscription
{
private DatabaseContext _context;
public UserSourceSubscriptionTable(string connectionString)
{
_context = new DatabaseContext(connectionString);
}
public UserSourceSubscriptionTable(DatabaseContext context)
{
_context = context;
}
public List<UserSourceSubscriptionEntity> ListUserSubscriptions(Guid userId)
{
var results =_context.UserSourceSubscription
.Where(i => i.UserId != null && i.UserId.Equals(userId)).ToList();
return results;
}
}

View File

@ -1,13 +0,0 @@
namespace Newsbot.Collector.Api.Domain.Consts;
public static class Authorization
{
public const string AdministratorPolicy = "Administrator";
public const string AdministratorsRole = AdministratorPolicy;
public const string AdministratorClaim = "administrator";
public const string UserPolicy = "User";
public const string UsersRole = UserPolicy;
public const string UserClaim = "user";
}

View File

@ -0,0 +1,10 @@
namespace Newsbot.Collector.Domain.Consts;
/// <summary>
/// This class contains const entries to access keys within IConfiguration.
/// </summary>
public static class ConfigConnectionStringConst
{
public const string Database = "ConnectionStrings:Database";
public const string OpenTelemetry = "ConnectionStrings:OpenTelemetry";
}

View File

@ -2,9 +2,6 @@ namespace Newsbot.Collector.Domain.Consts;
public class ConfigConst
{
public const string RunDatabaseMigrationsOnStartup = "RunDatabaseMigrationsOnStartup";
public const string ApiKeys = "ApiKeys";
public const string LoggingDefault = "Logging:LogLevel:Default";
public const string SectionConnectionStrings = "ConnectionStrings";

View File

@ -0,0 +1,11 @@
namespace Newsbot.Collector.Domain.Consts;
/// <summary>
/// This class contains const entries to access keys within IConfiguration.
/// </summary>
public class ConfigTwitchConst
{
public const string IsEnabled = "Twitch:IsEnabled";
public const string ClientID = "Twitch:ClientID";
public const string ClientSecret = "Twitch:ClientSecret";
}

View File

@ -0,0 +1,10 @@
namespace Newsbot.Collector.Domain.Consts;
/// <summary>
/// This class contains const entries to access keys within IConfiguration.
/// </summary>
public class ConfigYoutubeConst
{
public const string IsEnable = "Youtube:IsEnabled";
public const string Debug = "Youtube:Debug";
}

View File

@ -1,11 +1,10 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Dto;
public class ArticleDetailsDto
{
public Guid Id { get; set; }
public Guid ID { get; set; }
public string[]? Tags { get; set; }
public string? Title { get; set; }
public string? Url { get; set; }
@ -19,24 +18,24 @@ public class ArticleDetailsDto
public string? AuthorImage { get; set; }
public SourceDto? Source { get; set; }
public AuthorEntity? Author { get; set; }
public static ArticleDetailsDto Convert(ArticlesEntity article, SourceEntity source, AuthorEntity? author)
public static ArticleDetailsDto Convert(ArticlesModel article, SourceModel source)
{
return new ArticleDetailsDto
{
Id = article.Id,
ID = article.ID,
Tags = article.Tags.Split(','),
Title = article.Title,
Url = article.Url,
Url = article.URL,
PubDate = article.PubDate,
Video = article.Video,
VideoHeight = article.VideoHeight,
VideoWidth = article.VideoWidth,
Thumbnail = article.Thumbnail,
Description = article.Description,
Source = SourceDto.Convert(source),
AuthorName = article.AuthorName,
AuthorImage = article.AuthorImage,
Source = SourceDto.Convert(source)
};
}
}

View File

@ -1,4 +1,3 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Dto;
@ -7,7 +6,6 @@ public class ArticleDto
{
public Guid ID { get; set; }
public Guid SourceID { get; set; }
public Guid AuthorId { get; set; }
public string[]? Tags { get; set; }
public string? Title { get; set; }
public string? Url { get; set; }
@ -17,7 +15,9 @@ public class ArticleDto
public int VideoWidth { get; set; }
public string? Thumbnail { get; set; }
public string? Description { get; set; }
public static ArticleDto Convert(ArticlesModel article)
public string? AuthorName { get; set; }
public string? AuthorImage { get; set; }
public static ArticleDto Convert(ArticlesModel article)
{
return new ArticleDto
{
@ -32,25 +32,8 @@ public class ArticleDto
VideoWidth = article.VideoWidth,
Thumbnail = article.Thumbnail,
Description = article.Description,
};
}
public static ArticleDto Convert(ArticlesEntity article)
{
return new ArticleDto
{
ID = article.Id,
SourceID = article.SourceId,
AuthorId = article.AuthorId,
Tags = article.Tags.Split(','),
Title = article.Title,
Url = article.Url,
PubDate = article.PubDate,
Video = article.Video,
VideoHeight = article.VideoHeight,
VideoWidth = article.VideoWidth,
Thumbnail = article.Thumbnail,
Description = article.Description
AuthorName = article.AuthorName,
AuthorImage = article.AuthorImage,
};
}
}

View File

@ -1,9 +0,0 @@
namespace Newsbot.Collector.Domain.Dto;
public class AuthorDto
{
public Guid Id { get; set; }
public Guid SourceId { get; set; }
public string? Name { get; set; }
public string? Image { get; set; }
}

View File

@ -1,26 +0,0 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Dto;
public class DiscordNotificationDetailsDto
{
public Guid Id { get; set; }
public bool CodeAllowReleases { get; set; }
public bool CodeAllowCommits { get; set; }
public SourceDto? Source { get; set; }
public DiscordWebHookDto? DiscordWebHook { get; set; }
public static DiscordNotificationDetailsDto Convert(DiscordNotificationEntity discordNotification, SourceEntity source,
DiscordWebhookEntity discord)
{
return new DiscordNotificationDetailsDto
{
Id = discordNotification.Id,
CodeAllowCommits = discordNotification.CodeAllowCommits,
CodeAllowReleases = discordNotification.CodeAllowReleases,
Source = SourceDto.Convert(source),
DiscordWebHook = DiscordWebHookDto.Convert(discord)
};
}
}

View File

@ -1,4 +1,4 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Dto;
@ -10,11 +10,11 @@ public class DiscordWebHookDto
public string? Channel { get; set; }
public bool Enabled { get; set; }
public static DiscordWebHookDto Convert(DiscordWebhookEntity model)
public static DiscordWebHookDto Convert(DiscordWebHookModel model)
{
return new DiscordWebHookDto
{
ID = model.Id,
ID = model.ID,
Url = model.Url,
Server = model.Server,
Channel = model.Channel,

View File

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

View File

@ -0,0 +1,25 @@
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Dto;
public class SubscriptionDetailsDto
{
public Guid Id { get; set; }
public bool CodeAllowReleases { get; set; }
public bool CodeAllowCommits { get; set; }
public SourceDto? Source { get; set; }
public DiscordWebHookDto? DiscordWebHook { get; set; }
public static SubscriptionDetailsDto Convert(SubscriptionModel subscription, SourceModel source,
DiscordWebHookModel discord)
{
return new SubscriptionDetailsDto
{
Id = subscription.Id,
CodeAllowCommits = subscription.CodeAllowCommits,
CodeAllowReleases = subscription.CodeAllowReleases,
Source = SourceDto.Convert(source),
DiscordWebHook = DiscordWebHookDto.Convert(discord)
};
}
}

View File

@ -1,9 +1,8 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Dto;
public class DiscordNotificationDto
public class SubscriptionDto
{
public Guid Id { get; set; }
public Guid SourceId { get; set; }
@ -11,9 +10,9 @@ public class DiscordNotificationDto
public bool CodeAllowReleases { get; set; }
public bool CodeAllowCommits { get; set; }
public static DiscordNotificationDto Convert(DiscordNotificationEntity model)
public static SubscriptionDto Convert(SubscriptionModel model)
{
return new DiscordNotificationDto
return new SubscriptionDto
{
Id = model.Id,
SourceId = model.SourceId,

View File

@ -1,7 +0,0 @@
namespace Newsbot.Collector.Domain.Dto;
public class UserNewDto
{
public string? Username { get; set; }
public string? Password { get; set; }
}

View File

@ -1,19 +0,0 @@
namespace Newsbot.Collector.Domain.Entities;
public class ArticlesEntity
{
public Guid Id { get; set; }
public Guid SourceId { get; set; }
public Guid AuthorId { get; set; }
public string Tags { get; set; } = "";
public string Title { get; set; } = "";
public string? Url { get; set; }
public DateTime PubDate { get; set; } = DateTime.Now;
public string Video { get; set; } = "";
public int VideoHeight { get; set; } = 0;
public int VideoWidth { get; set; } = 0;
public string Thumbnail { get; set; } = "";
public string Description { get; set; } = "";
public bool CodeIsRelease { get; set; }
public bool CodeIsCommit { get; set; }
}

View File

@ -1,9 +0,0 @@
namespace Newsbot.Collector.Domain.Entities;
public class AuthorEntity
{
public Guid Id { get; set; }
public Guid SourceId { get; set; }
public string Name { get; set; } = "";
public string Image { get; set; } = "";
}

View File

@ -1,18 +0,0 @@
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.AspNetCore.Identity;
namespace Newsbot.Collector.Domain.Entities;
public class DiscordNotificationEntity
{
public Guid Id { get; set; }
public bool CodeAllowReleases { get; set; }
public bool CodeAllowCommits { get; set; }
public Guid SourceId { get; set; }
public Guid DiscordWebHookId { get; set; }
public string? UserId { get; set; }
//[ForeignKey(nameof(UserId))]
//public IdentityUser User { get; set; }
}

View File

@ -1,7 +0,0 @@
namespace Newsbot.Collector.Domain.Entities;
public class DiscordQueueEntity
{
public Guid Id { get; set; }
public Guid ArticleId { get; set; }
}

View File

@ -1,17 +0,0 @@
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.AspNetCore.Identity;
namespace Newsbot.Collector.Domain.Entities;
public class DiscordWebhookEntity
{
public Guid Id { get; set; }
public string Url { get; set; } = "";
public string Server { get; set; } = "";
public string Channel { get; set; } = "";
public bool Enabled { get; set; }
public string? UserId { get; set; }
[ForeignKey(nameof(UserId))]
public IdentityUser? User { get; set; }
}

View File

@ -1,10 +0,0 @@
namespace Newsbot.Collector.Domain.Entities;
public class IconEntity
{
public Guid Id { get; set; }
public string FileName { get; set; } = "";
public string Site { get; set; } = "";
public Guid SourceId { get; set; }
}

View File

@ -1,21 +0,0 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.AspNetCore.Identity;
namespace Newsbot.Collector.Domain.Entities;
public class RefreshTokenEntity
{
[Key]
public string? Token { get; set; }
public string? JwtId { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime ExpiryDate { get; set; }
public bool Used { get; set; }
public bool Invalidated { get; set; }
public string? UserId { get; set; }
[ForeignKey(nameof(UserId))]
public IdentityUser? User { get; set; }
}

View File

@ -1,18 +0,0 @@
namespace Newsbot.Collector.Domain.Entities;
public class SourceEntity
{
public Guid Id { get; set; }
public string Site { get; set; } = "";
public string Name { get; set; } = "";
// Source use to define the worker to query with but moving to Type as it was not used really.
public string Source { get; set; } = "";
public string Type { get; set; } = "";
public string Value { get; set; } = "";
public bool Enabled { get; set; }
public string Url { get; set; } = "";
public string Tags { get; set; } = "";
public bool Deleted { get; set; }
public string YoutubeId { get; set; } = "";
}

View File

@ -1,20 +0,0 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.AspNetCore.Identity;
namespace Newsbot.Collector.Domain.Entities;
/// <summary>
/// This defines the sources a user will want to see as a feed.
/// </summary>
public class UserSourceSubscriptionEntity
{
[Key]
public Guid Id { get; set; }
public Guid SourceId { get; set; }
public DateTimeOffset DateAdded { get; set; }
public string? UserId { get; set; }
[ForeignKey(nameof(UserId))]
public IdentityUser? User { get; set; }
}

View File

@ -1,14 +1,13 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Interfaces;
public interface IArticlesRepository : ITableRepository
{
List<ArticlesEntity> List(int page, int count = 25);
List<ArticlesEntity> ListBySourceId(Guid id, int page = 0, int count = 25);
ArticlesEntity GetById(Guid id);
ArticlesEntity GetByUrl(string url);
ArticlesEntity New(ArticlesEntity model);
List<ArticlesModel> List(int page, int count);
List<ArticlesModel> ListBySourceId(Guid id, int page = 0, int count = 25);
ArticlesModel GetById(Guid ID);
ArticlesModel GetByUrl(string url);
ArticlesModel New(ArticlesModel model);
void DeleteAllBySourceId(Guid sourceId);
}

View File

@ -1,14 +0,0 @@
using Newsbot.Collector.Domain.Entities;
namespace Newsbot.Collector.Domain.Interfaces;
public interface IAuthorTable
{
Task<AuthorEntity> NewAsync(AuthorEntity entity);
Task<AuthorEntity> CreateIfMissingAsync(AuthorEntity entity);
Task<List<AuthorEntity>> ListBySourceIdAsync(Guid sourceId);
Task<int> TotalPostsAsync(Guid id);
Task<AuthorEntity?> GetBySourceIdAndNameAsync(Guid sourceId, string name);
Task<AuthorEntity?> GetById(Guid id);
}

View File

@ -0,0 +1,9 @@
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Interfaces;
///
public interface ICollector : IHangfireJob
{
List<ArticlesModel> Collect();
}

View File

@ -2,7 +2,7 @@ using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Interfaces;
public interface IDiscordClient
public interface IDiscordNotificatioClient
{
void SendMessage(DiscordMessage payload);
}

View File

@ -1,28 +0,0 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Interfaces;
public interface IDiscordNotificationRepository
{
DiscordNotificationEntity New(DiscordNotificationEntity model);
List<DiscordNotificationEntity> List(string userId, int page = 0, int count = 25);
List<DiscordNotificationEntity> ListBySourceId(string userId, Guid id, int page = 0, int count = 25);
/// <summary>
/// This will collect all the records based on the SourceId.
/// Background jobs can use this but user facing calls need to define UserId
/// </summary>
/// <param name="id"></param>
/// <param name="page"></param>
/// <param name="count"></param>
/// <returns></returns>
List<DiscordNotificationEntity> ListBySourceId(Guid id, int page = 0, int count = 25);
List<DiscordNotificationEntity> ListByWebhook(string userId, Guid id, int page = 0, int count = 25);
DiscordNotificationEntity GetById(string userId, Guid id);
DiscordNotificationEntity GetByWebhookAndSource(string userId, Guid webhookId, Guid sourceId);
int Delete(string userId, Guid id);
}

View File

@ -1,10 +1,10 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Interfaces;
public interface IDiscordQueueRepository
{
void New(DiscordQueueEntity model);
void New(DiscordQueueModel model);
void Delete(Guid id);
List<DiscordQueueEntity> List(int limit);
List<DiscordQueueModel> List(int limit);
}

View File

@ -1,21 +1,19 @@
using Newsbot.Collector.Domain.Entities;
using Microsoft.VisualBasic;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Interfaces;
public interface IDiscordWebHooksRepository
{
DiscordWebhookEntity New(DiscordWebhookEntity model);
DiscordWebHookModel New(DiscordWebHookModel model);
DiscordWebhookEntity GetById(string userId, Guid id);
DiscordWebhookEntity GetById(Guid id);
DiscordWebhookEntity GetByUrl(string url);
DiscordWebHookModel GetByID(Guid id);
DiscordWebHookModel GetByUrl(string url);
List<DiscordWebhookEntity> List(int page, int count = 25);
List<DiscordWebhookEntity> ListByUserId(string userId, int page);
List<DiscordWebhookEntity> ListByServer(string server, int limit);
List<DiscordWebhookEntity> ListByServerAndChannel(string userId, string server, string channel, int limit);
List<DiscordWebHookModel> List(int page, int count = 25);
List<DiscordWebHookModel> ListByServer(string server, int limit);
List<DiscordWebHookModel> ListByServerAndChannel(string server, string channel, int limit);
int Disable(string userId, Guid id);
int Enable(string userId, Guid id);
int Disable(Guid id);
int Enable(Guid id);
}

View File

@ -1,11 +1,11 @@
using Newsbot.Collector.Domain.Entities;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Interfaces;
public interface IIconsRepository
{
public void New(IconEntity model);
public void New(IconModel model);
public IconEntity GetById(Guid id);
public IconEntity GetBySourceId(Guid id);
public IconModel GetById(Guid id);
public IconModel GetBySourceId(Guid id);
}

View File

@ -1,10 +0,0 @@
using Newsbot.Collector.Domain.Entities;
namespace Newsbot.Collector.Domain.Interfaces;
public interface IRefreshTokenRepository
{
void Add(RefreshTokenEntity entity);
public RefreshTokenEntity? Get(string token);
void UpdateTokenIsUsed(string token);
}

View File

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

View File

@ -0,0 +1,17 @@
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Domain.Interfaces;
public interface ISubscriptionRepository
{
SubscriptionModel New(SubscriptionModel model);
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);
SubscriptionModel GetById(Guid id);
SubscriptionModel GetByWebhookAndSource(Guid webhookId, Guid sourceId);
void Delete(Guid id);
}

View File

@ -1,8 +0,0 @@
using Newsbot.Collector.Domain.Entities;
namespace Newsbot.Collector.Domain.Interfaces;
public interface IUserSourceSubscription
{
List<UserSourceSubscriptionEntity> ListUserSubscriptions(Guid userId);
}

View File

@ -1,24 +1,13 @@
using Newsbot.Collector.Domain.Models.Config;
namespace Newsbot.Collector.Domain.Models;
public class ConfigModel
{
public ConnectionStrings? ConnectionStrings { get; set; }
public RedditConfig? Reddit { get; set; }
public YoutubeConfig? Youtube { get; set; }
public TwitchConfig? Twitch { get; set; }
public BasicSourceConfig? FinalFantasyXiv { get; set; }
public BasicSourceConfig? Rss { get; set; }
public BasicSourceConfig? CodeProjects { get; set; }
public NotificationsConfig? Notifications { get; set; }
public bool EnableSwagger { get; set; }
public bool RunDatabaseMigrationsOnStartup { get; set; }
public List<string>? ApiKeys { get; set; }
public JwtSettings? JwtSettings { get; set; }
public string? ServerAddress { get; set; }
public string? SqlConnectionString { get; set; }
public RedditConfigModel? Reddit { get; set; }
}
public class RedditConfig
public class RedditConfigModel
{
public bool IsEnabled { get; set; }
public bool PullHot { get; set; }
@ -28,29 +17,5 @@ public class RedditConfig
public class ConnectionStrings
{
public string? Database { get; set; }
public string? OpenTelemetry { get; set; }
}
public class BasicSourceConfig
{
public bool IsEnabled { get; set; }
}
public class YoutubeConfig
{
public bool IsEnabled { get; set; }
public bool Debug { get; set; }
}
public class TwitchConfig
{
public bool IsEnabled { get; set; }
public string? ClientId { get; set; }
public string? ClientSecret { get; set; }
}
public class NotificationsConfig
{
public BasicSourceConfig? Discord { get; set; }
}
public string Database { get; set; } = "";
}

View File

@ -0,0 +1,9 @@
namespace Newsbot.Collector.Domain.Models.Config;
public class ConfigSectionRedditModel
{
public bool IsEnabled { get; set; }
public bool PullHot { get; set; }
public bool PullNsfw { get; set; }
public bool PullTop { get; set; }
}

View File

@ -1,4 +1,4 @@
namespace Newsbot.Collector.Domain.Models.Config.Sources;
namespace Newsbot.Collector.Domain.Models.Config;
public class ConfigSectionRssModel
{

View File

@ -1,4 +1,4 @@
namespace Newsbot.Collector.Domain.Models.Config.Sources;
namespace Newsbot.Collector.Domain.Models.Config;
public class ConfigSectionYoutubeModel
{

Some files were not shown because too many files have changed in this diff Show More