mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
remove csv, rename List, other misc. cleanup
This commit is contained in:
parent
15ef23944a
commit
6a85642124
27 changed files with 46 additions and 644 deletions
|
|
@ -9,11 +9,11 @@ namespace FilterLists.Api.Controllers
|
|||
[Produces("application/json")]
|
||||
public class ListsController : Controller
|
||||
{
|
||||
private readonly IListService listService;
|
||||
private readonly IFilterListService filterListService;
|
||||
|
||||
public ListsController(IListService listService)
|
||||
public ListsController(IFilterListService filterListService)
|
||||
{
|
||||
this.listService = listService;
|
||||
this.filterListService = filterListService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -23,7 +23,7 @@ public ListsController(IListService listService)
|
|||
[HttpGet]
|
||||
public IActionResult Get()
|
||||
{
|
||||
return Json(listService.GetAll());
|
||||
return Json(filterListService.GetAll());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,6 @@ public FilterListsDbContext(DbContextOptions options)
|
|||
{
|
||||
}
|
||||
|
||||
public DbSet<List> List { get; set; }
|
||||
public DbSet<TableCsv> TableCsv { get; set; }
|
||||
public DbSet<FilterList> FilterList { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@ namespace FilterLists.Data.Contexts
|
|||
{
|
||||
public interface IFilterListsDbContext
|
||||
{
|
||||
DbSet<List> List { get; set; }
|
||||
DbSet<TableCsv> TableCsv { get; set; }
|
||||
DbSet<FilterList> FilterList { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ public static void WriteSampleToFile()
|
|||
|
||||
private static JObject GetSampleList()
|
||||
{
|
||||
return (JObject) JToken.FromObject(new List
|
||||
return (JObject) JToken.FromObject(new FilterList
|
||||
{
|
||||
Author = "John Doe",
|
||||
Description = "A sample list to filter out advertisements.",
|
||||
|
|
@ -28,7 +28,7 @@ private static JObject GetSampleList()
|
|||
ForumUrl = "https://mysample.list/forum/",
|
||||
HomeUrl = "https://mysample.list/",
|
||||
IssuesUrl = "https://github.com/mysamplelist/issues",
|
||||
Name = "My Sample List",
|
||||
Name = "My Sample Filter List",
|
||||
ViewUrl = "https://mysample.list/list.txt"
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public static void WriteSchemaToFile()
|
|||
{
|
||||
File.WriteAllText(
|
||||
Path.GetFullPath(Path.Combine(AppContext.BaseDirectory + @"\", @"..\..\..\..\..\data\")) +
|
||||
"ListSchema.json", new JSchemaGenerator().Generate(typeof(List)).ToString());
|
||||
"ListSchema.json", new JSchemaGenerator().Generate(typeof(FilterList)).ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using FilterLists.Data.Contexts;
|
||||
|
||||
namespace FilterLists.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(FilterListsDbContext))]
|
||||
[Migration("20170410220415_Initial")]
|
||||
partial class Initial
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "1.1.1");
|
||||
|
||||
modelBuilder.Entity("FilterLists.Models.List", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<DateTime>("AddedDateUtc")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(512);
|
||||
|
||||
b.Property<string>("DescriptionSourceUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("DonateUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasMaxLength(254);
|
||||
|
||||
b.Property<string>("ForumUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("HomeUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("IssuesUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<DateTime>("ModifiedDateUtc")
|
||||
.ValueGeneratedOnAddOrUpdate();
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(64);
|
||||
|
||||
b.Property<string>("ViewUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("List");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace FilterLists.Data.Migrations
|
||||
{
|
||||
public partial class Initial : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
"List",
|
||||
table => new
|
||||
{
|
||||
Id = table.Column<long>(nullable: false)
|
||||
.Annotation("MySQL:AutoIncrement", true),
|
||||
AddedDateUtc = table.Column<DateTime>(nullable: false),
|
||||
Description = table.Column<string>(maxLength: 512, nullable: true),
|
||||
DescriptionSourceUrl = table.Column<string>(maxLength: 2083, nullable: true),
|
||||
DonateUrl = table.Column<string>(maxLength: 2083, nullable: true),
|
||||
Email = table.Column<string>(maxLength: 254, nullable: true),
|
||||
ForumUrl = table.Column<string>(maxLength: 2083, nullable: true),
|
||||
HomeUrl = table.Column<string>(maxLength: 2083, nullable: true),
|
||||
IssuesUrl = table.Column<string>(maxLength: 2083, nullable: true),
|
||||
ModifiedDateUtc = table.Column<DateTime>(nullable: false),
|
||||
Name = table.Column<string>(maxLength: 64, nullable: true),
|
||||
ViewUrl = table.Column<string>(maxLength: 2083, nullable: false)
|
||||
},
|
||||
constraints: table => { table.PrimaryKey("PK_List", x => x.Id); });
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
"List");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using FilterLists.Data.Contexts;
|
||||
|
||||
namespace FilterLists.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(FilterListsDbContext))]
|
||||
[Migration("20170625164836_AddAuthor")]
|
||||
partial class AddAuthor
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "1.1.2");
|
||||
|
||||
modelBuilder.Entity("FilterLists.Data.Models.List", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<DateTime>("AddedDateUtc")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("Author")
|
||||
.HasMaxLength(126);
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(1022);
|
||||
|
||||
b.Property<string>("DescriptionSourceUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("DonateUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasMaxLength(126);
|
||||
|
||||
b.Property<string>("ForumUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("HomeUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("IssuesUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<DateTime?>("ModifiedDateUtc")
|
||||
.ValueGeneratedOnAddOrUpdate();
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(126);
|
||||
|
||||
b.Property<string>("ViewUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("List");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace FilterLists.Data.Migrations
|
||||
{
|
||||
public partial class AddAuthor : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
"Name",
|
||||
"List",
|
||||
maxLength: 126,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldMaxLength: 64,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
"ModifiedDateUtc",
|
||||
"List",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime));
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
"Email",
|
||||
"List",
|
||||
maxLength: 126,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldMaxLength: 254,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
"Description",
|
||||
"List",
|
||||
maxLength: 1022,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldMaxLength: 512,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
"Author",
|
||||
"List",
|
||||
maxLength: 126,
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
"Author",
|
||||
"List");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
"Name",
|
||||
"List",
|
||||
maxLength: 64,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldMaxLength: 126,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
"ModifiedDateUtc",
|
||||
"List",
|
||||
nullable: false,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
"Email",
|
||||
"List",
|
||||
maxLength: 254,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldMaxLength: 126,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
"Description",
|
||||
"List",
|
||||
maxLength: 512,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldMaxLength: 1022,
|
||||
oldNullable: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using FilterLists.Data.Contexts;
|
||||
|
||||
namespace FilterLists.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(FilterListsDbContext))]
|
||||
[Migration("20170625223511_addTableCsvEntity")]
|
||||
partial class addTableCsvEntity
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "1.1.2");
|
||||
|
||||
modelBuilder.Entity("FilterLists.Data.Models.List", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<DateTime>("AddedDateUtc")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("Author")
|
||||
.HasMaxLength(126);
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(1022);
|
||||
|
||||
b.Property<string>("DescriptionSourceUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("DonateUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasMaxLength(126);
|
||||
|
||||
b.Property<string>("ForumUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("HomeUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("IssuesUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<DateTime?>("ModifiedDateUtc")
|
||||
.ValueGeneratedOnAddOrUpdate();
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(126);
|
||||
|
||||
b.Property<string>("ViewUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("List");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FilterLists.Data.Models.TableCsv", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<DateTime>("AddedDateUtc")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<DateTime?>("ModifiedDateUtc")
|
||||
.ValueGeneratedOnAddOrUpdate();
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(126);
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("TableCsv");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace FilterLists.Data.Migrations
|
||||
{
|
||||
public partial class addTableCsvEntity : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
"TableCsv",
|
||||
table => new
|
||||
{
|
||||
Id = table.Column<long>(nullable: false)
|
||||
.Annotation("MySQL:AutoIncrement", true),
|
||||
AddedDateUtc = table.Column<DateTime>(nullable: false),
|
||||
ModifiedDateUtc = table.Column<DateTime>(nullable: true),
|
||||
Name = table.Column<string>(maxLength: 126, nullable: false),
|
||||
Url = table.Column<string>(maxLength: 2083, nullable: false)
|
||||
},
|
||||
constraints: table => { table.PrimaryKey("PK_TableCsv", x => x.Id); });
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
"TableCsv");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
using System;
|
||||
using FilterLists.Data.Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
|
||||
namespace FilterLists.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(FilterListsDbContext))]
|
||||
internal class FilterListsDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "1.1.2");
|
||||
|
||||
modelBuilder.Entity("FilterLists.Data.Models.List", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<DateTime>("AddedDateUtc")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("Author")
|
||||
.HasMaxLength(126);
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(1022);
|
||||
|
||||
b.Property<string>("DescriptionSourceUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("DonateUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasMaxLength(126);
|
||||
|
||||
b.Property<string>("ForumUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("HomeUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<string>("IssuesUrl")
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.Property<DateTime?>("ModifiedDateUtc")
|
||||
.ValueGeneratedOnAddOrUpdate();
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(126);
|
||||
|
||||
b.Property<string>("ViewUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("List");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FilterLists.Data.Models.TableCsv", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<DateTime>("AddedDateUtc")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<DateTime?>("ModifiedDateUtc")
|
||||
.ValueGeneratedOnAddOrUpdate();
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(126);
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasMaxLength(2083);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("TableCsv");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace FilterLists.Data.Models.Contracts
|
||||
{
|
||||
public interface IList
|
||||
public interface IFilterList
|
||||
{
|
||||
string Author { get; set; }
|
||||
string Description { get; set; }
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace FilterLists.Data.Models.Contracts
|
||||
{
|
||||
public interface ITableCsv
|
||||
{
|
||||
string Name { get; set; }
|
||||
string Url { get; set; }
|
||||
long Id { get; set; }
|
||||
DateTime AddedDateUtc { get; set; }
|
||||
DateTime? ModifiedDateUtc { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace FilterLists.Data.Models.Implementations
|
||||
{
|
||||
public class List : BaseEntity, IList
|
||||
public class FilterList : BaseEntity, IFilterList
|
||||
{
|
||||
[Description(@"The author (person or group) who maintains the list.")]
|
||||
[MaxLength(126)]
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using FilterLists.Data.Models.Contracts;
|
||||
|
||||
namespace FilterLists.Data.Models.Implementations
|
||||
{
|
||||
public class TableCsv : BaseEntity, ITableCsv
|
||||
{
|
||||
[Required]
|
||||
[MaxLength(126)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(2083)]
|
||||
[MinLength(6)]
|
||||
public string Url { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
namespace FilterLists.Data.Repositories.Contracts
|
||||
{
|
||||
public interface IListRepository
|
||||
public interface IFilterListRepository
|
||||
{
|
||||
IEnumerable<IList> GetAll();
|
||||
IList GetByName(string listName);
|
||||
IEnumerable<IFilterList> GetAll();
|
||||
IFilterList GetByName(string filterListName);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using FilterLists.Data.Models.Contracts;
|
||||
|
||||
namespace FilterLists.Data.Repositories.Contracts
|
||||
{
|
||||
public interface ITableCsvRepository
|
||||
{
|
||||
IEnumerable<ITableCsv> GetAll();
|
||||
string GetUrlByName(string name);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,23 +6,23 @@
|
|||
|
||||
namespace FilterLists.Data.Repositories.Implementations
|
||||
{
|
||||
public class TableCsvRepository : ITableCsvRepository
|
||||
public class FilterListRepository : IFilterListRepository
|
||||
{
|
||||
private readonly IFilterListsDbContext filterListsDbContext;
|
||||
|
||||
public TableCsvRepository(FilterListsDbContext filterListsDbContext)
|
||||
public FilterListRepository(FilterListsDbContext filterListsDbContext)
|
||||
{
|
||||
this.filterListsDbContext = filterListsDbContext;
|
||||
}
|
||||
|
||||
public IEnumerable<ITableCsv> GetAll()
|
||||
public IEnumerable<IFilterList> GetAll()
|
||||
{
|
||||
return filterListsDbContext.TableCsv.AsEnumerable();
|
||||
return filterListsDbContext.FilterList.AsEnumerable();
|
||||
}
|
||||
|
||||
public string GetUrlByName(string name)
|
||||
public IFilterList GetByName(string filterListName)
|
||||
{
|
||||
return filterListsDbContext.TableCsv.FirstOrDefault(x => x.Name == name).Url;
|
||||
return filterListsDbContext.FilterList.First(x => x.Name == filterListName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FilterLists.Data.Contexts;
|
||||
using FilterLists.Data.Models.Contracts;
|
||||
using FilterLists.Data.Repositories.Contracts;
|
||||
|
||||
namespace FilterLists.Data.Repositories.Implementations
|
||||
{
|
||||
public class ListRepository : IListRepository
|
||||
{
|
||||
private readonly IFilterListsDbContext filterListsDbContext;
|
||||
|
||||
public ListRepository(FilterListsDbContext filterListsDbContext)
|
||||
{
|
||||
this.filterListsDbContext = filterListsDbContext;
|
||||
}
|
||||
|
||||
public IEnumerable<IList> GetAll()
|
||||
{
|
||||
return filterListsDbContext.List.AsEnumerable();
|
||||
}
|
||||
|
||||
public IList GetByName(string listName)
|
||||
{
|
||||
return filterListsDbContext.List.First(x => x.Name == listName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
namespace FilterLists.Services.Contracts
|
||||
{
|
||||
public interface IListService
|
||||
public interface IFilterListService
|
||||
{
|
||||
IEnumerable<IList> GetAll();
|
||||
IEnumerable<IFilterList> GetAll();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
namespace FilterLists.Services.Contracts
|
||||
{
|
||||
public interface ITableService
|
||||
{
|
||||
void UpdateTables();
|
||||
}
|
||||
}
|
||||
|
|
@ -17,10 +17,8 @@ public static void AddFilterListsServices(this IServiceCollection services, ICon
|
|||
services.AddSingleton(c => configuration);
|
||||
services.AddEntityFrameworkMySql().AddDbContext<FilterListsDbContext>(options =>
|
||||
options.UseMySql(configuration.GetConnectionString("FilterListsConnection")));
|
||||
services.TryAddScoped<IListRepository, ListRepository>();
|
||||
services.TryAddScoped<ITableCsvRepository, TableCsvRepository>();
|
||||
services.TryAddScoped<IListService, ListService>();
|
||||
services.TryAddScoped<ITableService, TableService>();
|
||||
services.TryAddScoped<IFilterListRepository, FilterListRepository>();
|
||||
services.TryAddScoped<IFilterListService, FilterListService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CsvHelper" Version="4.0.3" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
using System.Collections.Generic;
|
||||
using FilterLists.Data.Models.Contracts;
|
||||
using FilterLists.Data.Repositories.Contracts;
|
||||
using FilterLists.Services.Contracts;
|
||||
|
||||
namespace FilterLists.Services.Implementations
|
||||
{
|
||||
public class FilterListService : IFilterListService
|
||||
{
|
||||
private readonly IFilterListRepository filterListRepository;
|
||||
|
||||
public FilterListService(IFilterListRepository filterListRepository)
|
||||
{
|
||||
this.filterListRepository = filterListRepository;
|
||||
}
|
||||
|
||||
public IEnumerable<IFilterList> GetAll()
|
||||
{
|
||||
return filterListRepository.GetAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using FilterLists.Data.Models.Contracts;
|
||||
using FilterLists.Data.Repositories.Contracts;
|
||||
using FilterLists.Services.Contracts;
|
||||
|
||||
namespace FilterLists.Services.Implementations
|
||||
{
|
||||
public class ListService : IListService
|
||||
{
|
||||
private readonly IListRepository listRepository;
|
||||
|
||||
public ListService(IListRepository listRepository)
|
||||
{
|
||||
this.listRepository = listRepository;
|
||||
}
|
||||
|
||||
public IEnumerable<IList> GetAll()
|
||||
{
|
||||
return listRepository.GetAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using CsvHelper;
|
||||
using FilterLists.Data.Models.Implementations;
|
||||
using FilterLists.Data.Repositories.Contracts;
|
||||
using FilterLists.Services.Contracts;
|
||||
|
||||
namespace FilterLists.Services.Implementations
|
||||
{
|
||||
public class TableService : ITableService
|
||||
{
|
||||
private readonly ITableCsvRepository tableCsvRepository;
|
||||
|
||||
public TableService(ITableCsvRepository tableCsvRepository)
|
||||
{
|
||||
this.tableCsvRepository = tableCsvRepository;
|
||||
}
|
||||
|
||||
public void UpdateTables()
|
||||
{
|
||||
UpdateListTable();
|
||||
}
|
||||
|
||||
public void UpdateListTable()
|
||||
{
|
||||
var localCsvFilePath = FetchFile(tableCsvRepository.GetUrlByName("List"), "List").Result;
|
||||
TextReader textReader = File.OpenText(localCsvFilePath);
|
||||
var csv = new CsvReader(textReader);
|
||||
csv.Configuration.MissingFieldFound = null;
|
||||
var records = csv.GetRecords<List>();
|
||||
//TODO: delete file when finished
|
||||
}
|
||||
|
||||
private static async Task<string> FetchFile(string url, string fileName)
|
||||
{
|
||||
var response = await new HttpClient().GetAsync(url);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var path = Path.Combine(Directory.GetCurrentDirectory(), "csv");
|
||||
Directory.CreateDirectory(path);
|
||||
var file = Path.Combine(path, fileName + ".csv");
|
||||
using (var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
{
|
||||
await response.Content.CopyToAsync(fileStream);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue