mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
convert new repo to handle flattening urls into single collection to validate
This commit is contained in:
parent
a0e0a0e610
commit
fea435db4b
11 changed files with 40 additions and 30 deletions
|
|
@ -6,7 +6,6 @@ namespace FilterLists.Agent.Core.Entities
|
|||
[UsedImplicitly]
|
||||
public class LicenseUrls : IEntityUrls
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Uri DescriptionUrl { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@ namespace FilterLists.Agent.Core.Entities
|
|||
[UsedImplicitly]
|
||||
public class ListUrls : IEntityUrls
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public Uri ChatUrl { get; private set; }
|
||||
public Uri DescriptionSourceUrl { get; private set; }
|
||||
public Uri DonateUrl { get; private set; }
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Agent.Core.Entities
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class MaintainerUrls : IEntityUrls
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string HomeUrl { get; set; }
|
||||
public Uri HomeUrl { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Agent.Core.Entities
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SoftwareUrls : IEntityUrls
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string DownloadUrl { get; set; }
|
||||
public string HomeUrl { get; set; }
|
||||
public Uri DownloadUrl { get; set; }
|
||||
public Uri HomeUrl { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Agent.Core.Entities
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SyntaxUrls : IEntityUrls
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string DefinitionUrl { get; set; }
|
||||
public Uri DefinitionUrl { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Core.Entities;
|
||||
|
||||
namespace FilterLists.Agent.Core.Interfaces
|
||||
{
|
||||
public interface IEntityUrlsRepository
|
||||
{
|
||||
Task<IEnumerable<TEntityUrls>> GetAllAsync<TEntityUrls>() where TEntityUrls : IEntityUrls, new();
|
||||
}
|
||||
}
|
||||
12
src/FilterLists.Agent/Core/Interfaces/IUrlsRepository.cs
Normal file
12
src/FilterLists.Agent/Core/Interfaces/IUrlsRepository.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Core.Entities;
|
||||
|
||||
namespace FilterLists.Agent.Core.Interfaces
|
||||
{
|
||||
public interface IUrlsRepository
|
||||
{
|
||||
Task<IEnumerable<Uri>> GetAllAsync<TEntityUrls>() where TEntityUrls : IEntityUrls, new();
|
||||
}
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ public static void RegisterAgentServices(this IServiceCollection services)
|
|||
services.AddHttpClient<AgentHttpClient>();
|
||||
services.AddSingleton<IFilterListsApiClient, FilterListsApiClient>();
|
||||
services.AddTransient<IListInfoRepository, ListInfoRepository>();
|
||||
services.AddTransient<IEntityUrlsRepository, EntityUrlsRepository>();
|
||||
services.AddTransient<IUrlsRepository, UrlsRepository>();
|
||||
}
|
||||
|
||||
private static void AddConfiguration(this IServiceCollection services)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Core.Entities;
|
||||
using FilterLists.Agent.Core.Interfaces;
|
||||
using MediatR;
|
||||
|
||||
namespace FilterLists.Agent.Features.Urls
|
||||
|
|
@ -14,14 +16,17 @@ public class Command : IRequest
|
|||
public class Handler : AsyncRequestHandler<Command>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IUrlsRepository _repo;
|
||||
|
||||
public Handler(IMediator mediator)
|
||||
public Handler(IMediator mediator, IUrlsRepository urlsRepository)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_repo = urlsRepository;
|
||||
}
|
||||
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
var listUrls = await _repo.GetAllAsync<ListUrls>();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Core.Entities;
|
||||
using FilterLists.Agent.Core.Interfaces;
|
||||
|
|
@ -7,20 +9,22 @@
|
|||
|
||||
namespace FilterLists.Agent.Infrastructure.Repositories
|
||||
{
|
||||
public class EntityUrlsRepository : IEntityUrlsRepository
|
||||
public class UrlsRepository : IUrlsRepository
|
||||
{
|
||||
private readonly IFilterListsApiClient _apiClient;
|
||||
|
||||
public EntityUrlsRepository(IFilterListsApiClient apiClient)
|
||||
public UrlsRepository(IFilterListsApiClient apiClient)
|
||||
{
|
||||
_apiClient = apiClient;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TEntityUrls>> GetAllAsync<TEntityUrls>() where TEntityUrls : IEntityUrls, new()
|
||||
public async Task<IEnumerable<Uri>> GetAllAsync<TEntityUrls>() where TEntityUrls : IEntityUrls, new()
|
||||
{
|
||||
var endpoint = BuildEndpoint<TEntityUrls>();
|
||||
var request = new RestRequest(endpoint);
|
||||
return await _apiClient.ExecuteAsync<IEnumerable<TEntityUrls>>(request);
|
||||
var response = await _apiClient.ExecuteAsync<IEnumerable<TEntityUrls>>(request);
|
||||
return response.SelectMany(r => r.GetType().GetProperties().Select(p => (Uri)p.GetValue(r)))
|
||||
.Where(u => u != null);
|
||||
}
|
||||
|
||||
private static string BuildEndpoint<TEntityUrls>() where TEntityUrls : IEntityUrls, new()
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Extensions;
|
||||
using FilterLists.Agent.Features.Lists;
|
||||
using FilterLists.Agent.Features.Urls;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ public static async Task Main()
|
|||
BuildServiceProvider();
|
||||
var mediator = _serviceProvider.GetService<IMediator>();
|
||||
await mediator.Send(new CaptureLists.Command());
|
||||
await mediator.Send(new ValidateUrls.Command());
|
||||
}
|
||||
|
||||
private static void BuildServiceProvider()
|
||||
|
|
|
|||
Loading…
Reference in a new issue