Skip to content

Commit

Permalink
Merge pull request #3 from dominikus1993/webapp
Browse files Browse the repository at this point in the history
add web app
  • Loading branch information
dominikus1993 authored Apr 23, 2021
2 parents 59f10f7 + 46c0b75 commit 8d70b17
Show file tree
Hide file tree
Showing 50 changed files with 1,934 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"paket": {
"version": "6.0.0-beta8",
"version": "6.0.0-beta9",
"commands": [
"paket"
]
Expand Down
30 changes: 30 additions & 0 deletions dev-news-bot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevNews.Cli", "src\DevNews.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevNews.Infrastructure.Notifications.UnitTests", "tests\DevNews.Infrastructure.Notifications.UnitTests\DevNews.Infrastructure.Notifications.UnitTests.csproj", "{747B0D0B-DDA4-4B0E-A599-CF753326589E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevNews.WebApp", "src\DevNews.WebApp\DevNews.WebApp.csproj", "{7E1CE898-544A-44F2-9BCD-D6265F975A0B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevNews.Persistence.UnitTests", "tests\DevNews.Persistence.UnitTests\DevNews.Persistence.UnitTests.csproj", "{5376EC5C-151B-4D27-8BB7-FBD71F83CE02}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -44,6 +48,8 @@ Global
{1885D88D-0ED0-401A-8678-BDCAECA6CF8C} = {152813B7-DF24-4443-942C-CD2955C61CA9}
{524117F9-B49E-4AFF-9873-4C4B1B6AFC3C} = {93F0838E-B38F-4821-866A-964E5CDF781D}
{747B0D0B-DDA4-4B0E-A599-CF753326589E} = {152813B7-DF24-4443-942C-CD2955C61CA9}
{7E1CE898-544A-44F2-9BCD-D6265F975A0B} = {93F0838E-B38F-4821-866A-964E5CDF781D}
{5376EC5C-151B-4D27-8BB7-FBD71F83CE02} = {152813B7-DF24-4443-942C-CD2955C61CA9}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{104B95DB-F722-4E44-8E94-E283E8B1312C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -142,5 +148,29 @@ Global
{747B0D0B-DDA4-4B0E-A599-CF753326589E}.Release|x64.Build.0 = Release|Any CPU
{747B0D0B-DDA4-4B0E-A599-CF753326589E}.Release|x86.ActiveCfg = Release|Any CPU
{747B0D0B-DDA4-4B0E-A599-CF753326589E}.Release|x86.Build.0 = Release|Any CPU
{7E1CE898-544A-44F2-9BCD-D6265F975A0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E1CE898-544A-44F2-9BCD-D6265F975A0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E1CE898-544A-44F2-9BCD-D6265F975A0B}.Debug|x64.ActiveCfg = Debug|Any CPU
{7E1CE898-544A-44F2-9BCD-D6265F975A0B}.Debug|x64.Build.0 = Debug|Any CPU
{7E1CE898-544A-44F2-9BCD-D6265F975A0B}.Debug|x86.ActiveCfg = Debug|Any CPU
{7E1CE898-544A-44F2-9BCD-D6265F975A0B}.Debug|x86.Build.0 = Debug|Any CPU
{7E1CE898-544A-44F2-9BCD-D6265F975A0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E1CE898-544A-44F2-9BCD-D6265F975A0B}.Release|Any CPU.Build.0 = Release|Any CPU
{7E1CE898-544A-44F2-9BCD-D6265F975A0B}.Release|x64.ActiveCfg = Release|Any CPU
{7E1CE898-544A-44F2-9BCD-D6265F975A0B}.Release|x64.Build.0 = Release|Any CPU
{7E1CE898-544A-44F2-9BCD-D6265F975A0B}.Release|x86.ActiveCfg = Release|Any CPU
{7E1CE898-544A-44F2-9BCD-D6265F975A0B}.Release|x86.Build.0 = Release|Any CPU
{5376EC5C-151B-4D27-8BB7-FBD71F83CE02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5376EC5C-151B-4D27-8BB7-FBD71F83CE02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5376EC5C-151B-4D27-8BB7-FBD71F83CE02}.Debug|x64.ActiveCfg = Debug|Any CPU
{5376EC5C-151B-4D27-8BB7-FBD71F83CE02}.Debug|x64.Build.0 = Debug|Any CPU
{5376EC5C-151B-4D27-8BB7-FBD71F83CE02}.Debug|x86.ActiveCfg = Debug|Any CPU
{5376EC5C-151B-4D27-8BB7-FBD71F83CE02}.Debug|x86.Build.0 = Debug|Any CPU
{5376EC5C-151B-4D27-8BB7-FBD71F83CE02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5376EC5C-151B-4D27-8BB7-FBD71F83CE02}.Release|Any CPU.Build.0 = Release|Any CPU
{5376EC5C-151B-4D27-8BB7-FBD71F83CE02}.Release|x64.ActiveCfg = Release|Any CPU
{5376EC5C-151B-4D27-8BB7-FBD71F83CE02}.Release|x64.Build.0 = Release|Any CPU
{5376EC5C-151B-4D27-8BB7-FBD71F83CE02}.Release|x86.ActiveCfg = Release|Any CPU
{5376EC5C-151B-4D27-8BB7-FBD71F83CE02}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ nuget MongoDB.Driver
nuget Microsoft.Extensions.Http
nuget Microsoft.AspNetCore.Http.Features
nuget Microsoft.Extensions.Logging.Abstractions
nuget Moq

nuget Serilog.AspNetCore
nuget Serilog.Enrichers.Environment
Expand Down
113 changes: 104 additions & 9 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ NUGET
Argu (6.1.1)
FSharp.Core (>= 4.3.2)
System.Configuration.ConfigurationManager (>= 4.4)
Castle.Core (4.4.1)
NETStandard.Library (>= 1.6.1)
System.Collections.Specialized (>= 4.3)
System.ComponentModel (>= 4.3)
System.ComponentModel.TypeConverter (>= 4.3)
System.Diagnostics.TraceSource (>= 4.3)
System.Dynamic.Runtime (>= 4.3)
System.Reflection (>= 4.3)
System.Reflection.Emit (>= 4.3)
System.Reflection.TypeExtensions (>= 4.3)
System.Xml.XmlDocument (>= 4.3)
Cocona (1.5)
Cocona.Core (>= 1.5)
Microsoft.Extensions.DependencyInjection (>= 3.1.1)
Expand Down Expand Up @@ -32,7 +43,7 @@ NUGET
NETStandard.Library (>= 2.0.3)
NHamcrest (>= 2.0.1 < 2.1)
xunit (>= 2.4.1 < 2.5)
HtmlAgilityPack (1.11.32)
HtmlAgilityPack (1.11.33)
LanguageExt.Core (3.4.15)
Microsoft.CSharp (>= 4.5)
System.Diagnostics.Contracts (>= 4.3)
Expand Down Expand Up @@ -189,25 +200,28 @@ NUGET
System.Security.Principal.Windows (>= 5.0)
Microsoft.Win32.SystemEvents (5.0)
Microsoft.NETCore.Platforms (>= 5.0)
MongoDB.Bson (2.12.1)
MongoDB.Bson (2.12.2)
System.Runtime.CompilerServices.Unsafe (>= 5.0)
MongoDB.Driver (2.12.1)
MongoDB.Bson (>= 2.12.1)
MongoDB.Driver.Core (>= 2.12.1)
MongoDB.Driver (2.12.2)
MongoDB.Bson (>= 2.12.2)
MongoDB.Driver.Core (>= 2.12.2)
MongoDB.Libmongocrypt (>= 1.2.1)
MongoDB.Driver.Core (2.12.1)
MongoDB.Driver.Core (2.12.2)
DnsClient (>= 1.4)
MongoDB.Bson (>= 2.12.1)
MongoDB.Bson (>= 2.12.2)
MongoDB.Libmongocrypt (>= 1.2.1)
SharpCompress (>= 0.23)
System.Buffers (>= 4.5.1)
MongoDB.Libmongocrypt (1.2.1)
Moq (4.16.1)
Castle.Core (>= 4.4)
System.Threading.Tasks.Extensions (>= 4.5.4)
NETStandard.Library (2.0.3)
Microsoft.NETCore.Platforms (>= 1.1)
Newtonsoft.Json (13.0.1)
NHamcrest (2.0.1)
NETStandard.Library (>= 1.6.1)
NuGet.Frameworks (5.9)
NuGet.Frameworks (5.9.1)
Open.ChannelExtensions (3.5)
System.Threading.Channels (>= 4.7.1)
runtime.native.System (4.3.1)
Expand Down Expand Up @@ -270,7 +284,7 @@ NUGET
Serilog (>= 2.0)
System.Collections.Concurrent (>= 4.0.12)
System.Threading.Timer (>= 4.0.1)
Serilog.Sinks.Seq (5.0)
Serilog.Sinks.Seq (5.0.1)
Serilog (>= 2.10)
Serilog.Formatting.Compact (>= 1.1)
Serilog.Sinks.File (>= 4.0)
Expand All @@ -296,7 +310,44 @@ NUGET
System.Threading (>= 4.3)
System.Threading.Tasks (>= 4.3)
System.Collections.Immutable (5.0)
System.Collections.NonGeneric (4.3)
System.Diagnostics.Debug (>= 4.3)
System.Globalization (>= 4.3)
System.Resources.ResourceManager (>= 4.3)
System.Runtime (>= 4.3)
System.Runtime.Extensions (>= 4.3)
System.Threading (>= 4.3)
System.Collections.Specialized (4.3)
System.Collections.NonGeneric (>= 4.3)
System.Globalization (>= 4.3)
System.Globalization.Extensions (>= 4.3)
System.Resources.ResourceManager (>= 4.3)
System.Runtime (>= 4.3)
System.Runtime.Extensions (>= 4.3)
System.Threading (>= 4.3)
System.ComponentModel (4.3)
System.Runtime (>= 4.3)
System.ComponentModel.Annotations (5.0)
System.ComponentModel.Primitives (4.3)
System.ComponentModel (>= 4.3)
System.Resources.ResourceManager (>= 4.3)
System.Runtime (>= 4.3)
System.ComponentModel.TypeConverter (4.3)
System.Collections (>= 4.3)
System.Collections.NonGeneric (>= 4.3)
System.Collections.Specialized (>= 4.3)
System.ComponentModel (>= 4.3)
System.ComponentModel.Primitives (>= 4.3)
System.Globalization (>= 4.3)
System.Linq (>= 4.3)
System.Reflection (>= 4.3)
System.Reflection.Extensions (>= 4.3)
System.Reflection.Primitives (>= 4.3)
System.Reflection.TypeExtensions (>= 4.3)
System.Resources.ResourceManager (>= 4.3)
System.Runtime (>= 4.3)
System.Runtime.Extensions (>= 4.3)
System.Threading (>= 4.3)
System.Configuration.ConfigurationManager (5.0)
System.Security.Cryptography.ProtectedData (>= 5.0)
System.Security.Permissions (>= 5.0)
Expand Down Expand Up @@ -354,6 +405,21 @@ NUGET
System.Runtime (>= 4.3)
System.Drawing.Common (5.0.2)
Microsoft.Win32.SystemEvents (>= 5.0)
System.Dynamic.Runtime (4.3)
System.Collections (>= 4.3)
System.Diagnostics.Debug (>= 4.3)
System.Linq (>= 4.3)
System.Linq.Expressions (>= 4.3)
System.ObjectModel (>= 4.3)
System.Reflection (>= 4.3)
System.Reflection.Emit (>= 4.3)
System.Reflection.Emit.ILGeneration (>= 4.3)
System.Reflection.Primitives (>= 4.3)
System.Reflection.TypeExtensions (>= 4.3)
System.Resources.ResourceManager (>= 4.3)
System.Runtime (>= 4.3)
System.Runtime.Extensions (>= 4.3)
System.Threading (>= 4.3)
System.Globalization (4.3)
Microsoft.NETCore.Platforms (>= 1.1)
Microsoft.NETCore.Targets (>= 1.1)
Expand Down Expand Up @@ -506,6 +572,8 @@ NUGET
System.Runtime (>= 4.3)
System.Text.Encoding (>= 4.3)
System.Text.Json (5.0.2)
System.Text.RegularExpressions (4.3.1)
System.Runtime (>= 4.3.1)
System.Threading (4.3)
System.Runtime (>= 4.3)
System.Threading.Tasks (>= 4.3)
Expand All @@ -527,6 +595,33 @@ NUGET
System.ValueTuple (4.5)
System.Windows.Extensions (5.0)
System.Drawing.Common (>= 5.0)
System.Xml.ReaderWriter (4.3.1)
System.Collections (>= 4.3)
System.Diagnostics.Debug (>= 4.3)
System.Globalization (>= 4.3)
System.IO (>= 4.3)
System.IO.FileSystem (>= 4.3)
System.IO.FileSystem.Primitives (>= 4.3)
System.Resources.ResourceManager (>= 4.3)
System.Runtime (>= 4.3)
System.Runtime.Extensions (>= 4.3)
System.Runtime.InteropServices (>= 4.3)
System.Text.Encoding (>= 4.3)
System.Text.Encoding.Extensions (>= 4.3)
System.Text.RegularExpressions (>= 4.3)
System.Threading.Tasks (>= 4.3)
System.Threading.Tasks.Extensions (>= 4.3)
System.Xml.XmlDocument (4.3)
System.Collections (>= 4.3)
System.Diagnostics.Debug (>= 4.3)
System.Globalization (>= 4.3)
System.IO (>= 4.3)
System.Resources.ResourceManager (>= 4.3)
System.Runtime (>= 4.3)
System.Runtime.Extensions (>= 4.3)
System.Text.Encoding (>= 4.3)
System.Threading (>= 4.3)
System.Xml.ReaderWriter (>= 4.3)
xunit (2.4.1)
xunit.analyzers (>= 0.10)
xunit.assert (2.4.1)
Expand Down
2 changes: 2 additions & 0 deletions src/DevNews.Core/DependencyInjection/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public static IServiceCollection AddCore(this IServiceCollection services)
services.AddTransient<IArticlesProvider, ChannelArticlesProvider>();
services.AddTransient<ParseArticlesAndSendItUseCase>();
services.AddTransient<INotificationBroadcaster, ChannelsNotificationBroadcaster>();
services.AddTransient<GetArticles>();
services.AddTransient<GetArticlesPagesQuantity>();
return services;
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/DevNews.Core/Dto/ArticleDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using DevNews.Core.Model;

namespace DevNews.Core.Dto
{
public record ArticleDto(string Title, string? Content, string Link)
{
public ArticleDto(Article article) : this(article.Title, article.Content, article.Link)
{

}
}
}
2 changes: 1 addition & 1 deletion src/DevNews.Core/Repository/IArticlesRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IArticlesRepository
{
Task<bool> Exists(Article article);
Task<Either<Exception, Unit>> InsertMany(IEnumerable<Article> articles);

IAsyncEnumerable<Article> Get(int page, int pageSize);
Task<long> Count();
}
}
37 changes: 37 additions & 0 deletions src/DevNews.Core/UseCases/GetArticles.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DevNews.Core.Dto;
using DevNews.Core.Model;
using DevNews.Core.Repository;

namespace DevNews.Core.UseCases
{
public record GetArticlesQuery(int Page, int PageSize);

public class GetArticles
{
private readonly IArticlesRepository _articlesRepository;

public GetArticles(IArticlesRepository articlesRepository)
{
_articlesRepository = articlesRepository;
}

public async Task<List<ArticleDto>> Execute(GetArticlesQuery query)
{
if (query.Page < 0)
{
throw new ArgumentOutOfRangeException(nameof(query.Page));
}

if (query.PageSize <= 0)
{
throw new ArgumentOutOfRangeException(nameof(query.PageSize));
}

return await _articlesRepository.Get(query.Page, query.PageSize).Select(article => new ArticleDto(article)).ToListAsync();
}
}
}
32 changes: 32 additions & 0 deletions src/DevNews.Core/UseCases/GetArticlesPagesQuantity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Threading.Tasks;
using DevNews.Core.Repository;

namespace DevNews.Core.UseCases
{
public class GetArticlesPagesQuantity
{
private IArticlesRepository _articlesRepository;

public GetArticlesPagesQuantity(IArticlesRepository articlesRepository)
{
_articlesRepository = articlesRepository;
}

public async Task<long> Execute(int pageSize)
{
if (pageSize <= 0)
{
throw new ArgumentOutOfRangeException(nameof(pageSize), "Page Size should be greater or equal 1");
}

var count = await _articlesRepository.Count();
if (count == 0)
{
return 0;
}

return (long) Math.Ceiling((double) count / (double) pageSize);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace DevNews.Infrastructure.Persistence.Config
{
public class PersistenceConfiguration
internal class PersistenceConfiguration
{
public string? MongoConnectionString { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace DevNews.Infrastructure.Persistence.Model
{
public class MongoArticle
internal class MongoArticle
{
[BsonId, BsonRepresentation(BsonType.String)]
public string? Title { get; init; }
Expand Down
Loading

0 comments on commit 8d70b17

Please sign in to comment.