mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
feat(directory): ✨ wire up ef to postgres container
This commit is contained in:
parent
cf50e024bf
commit
22d7b2c129
14 changed files with 83 additions and 71 deletions
4
.env
Normal file
4
.env
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
DIRECTORY_CONNECTION_STRING=Server=filterlists.directory.db;Database=filterlists;Uid=filterlists;Pwd=filterlists;
|
||||
DIRECTORY_DB_USER=filterlists
|
||||
DIRECTORY_DB_PASSWORD=filterlists
|
||||
DIRECTORY_DB_DATABASE=filterlists
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
|
||||
using FilterLists.Directory.Infrastructure.Persistence.Queries.Facade;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FilterLists.Directory.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("lists")]
|
||||
public class FilterListsController : ControllerBase
|
||||
{
|
||||
private readonly IQueryDirectory _queryContext;
|
||||
|
||||
public FilterListsController(IQueryDirectory queryContext)
|
||||
{
|
||||
_queryContext = queryContext;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IEnumerable<FilterList>> Get(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _queryContext.FilterLists.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FilterLists.Directory.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries =
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
private readonly ILogger<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
var rng = new Random();
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateTime.Now.AddDays(index),
|
||||
TemperatureC = rng.Next(-20, 55),
|
||||
Summary = Summaries[rng.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,4 +22,8 @@
|
|||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FilterLists.Directory.Infrastructure\FilterLists.Directory.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace FilterLists.Directory.Api
|
||||
{
|
||||
public class Program
|
||||
public static class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "weatherforecast",
|
||||
"launchUrl": "lists",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
"FilterLists.Directory.Api": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "weatherforecast",
|
||||
"launchUrl": "lists",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
"Docker": {
|
||||
"commandName": "Docker",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/weatherforecast",
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/lists",
|
||||
"publishAllPorts": true,
|
||||
"useSSL": true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
using FilterLists.Directory.Infrastructure.Persistence.Queries;
|
||||
using FilterLists.Directory.Infrastructure.Persistence.Queries.Facade;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
|
@ -15,24 +17,19 @@ public Startup(IConfiguration configuration)
|
|||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllers();
|
||||
services.RegisterQueryFacade(Configuration);
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace FilterLists.Directory.Api
|
||||
{
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string Summary { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities.Contracts
|
||||
{
|
||||
public interface IHaveSurrogateKey
|
||||
internal interface IHaveSurrogateKey
|
||||
{
|
||||
ushort Id { get; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,12 @@
|
|||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Facade
|
||||
{
|
||||
public class DirectoryQueryDbContext : DbContext
|
||||
internal class DirectoryQueryDbContext : DbContext
|
||||
{
|
||||
public DirectoryQueryDbContext(DbContextOptions<DirectoryQueryDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<FilterList> FilterLists => Set<FilterList>();
|
||||
public DbSet<Language> Languages => Set<Language>();
|
||||
public DbSet<License> Licenses => Set<License>();
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Facade
|
||||
{
|
||||
public class DirectoryQueryFacade : IQueryDirectory, IAsyncDisposable
|
||||
internal class DirectoryQueryFacade : IQueryDirectory, IAsyncDisposable
|
||||
{
|
||||
private readonly DirectoryQueryDbContext _dbContext;
|
||||
|
||||
public DirectoryQueryFacade()
|
||||
public DirectoryQueryFacade(DirectoryQueryDbContext dbContext)
|
||||
{
|
||||
_dbContext = new DirectoryQueryDbContext();
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Facade
|
||||
{
|
||||
public static class QueryFacadeExtension
|
||||
{
|
||||
public static void RegisterQueryFacade(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContextPool<DirectoryQueryDbContext>(o =>
|
||||
o.UseNpgsql(configuration.GetConnectionString("DirectoryConnection")));
|
||||
services.AddScoped<IQueryDirectory, DirectoryQueryFacade>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
version: '3.4'
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
filterlists.directory.api:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
version: '3.4'
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
filterlists.directory.api:
|
||||
|
|
@ -6,3 +6,15 @@ services:
|
|||
build:
|
||||
context: .
|
||||
dockerfile: directory/src/FilterLists.Directory.Api/Dockerfile
|
||||
depends_on:
|
||||
- filterlists.directory.db
|
||||
environment:
|
||||
ConnectionStrings__DirectoryConnection: ${DIRECTORY_CONNECTION_STRING}
|
||||
|
||||
filterlists.directory.db:
|
||||
image: postgres:alpine
|
||||
restart: always
|
||||
environment:
|
||||
POSTGRES_USER: ${DIRECTORY_DB_USER}
|
||||
POSTGRES_PASSWORD: ${DIRECTORY_DB_PASSWORD}
|
||||
POSTGRES_DB: ${DIRECTORY_DB_DATABASE}
|
||||
Loading…
Reference in a new issue