wip
This commit is contained in:
parent
1ecaf64dea
commit
cb9d5e332e
11 changed files with 72 additions and 69 deletions
|
@ -1,4 +1,5 @@
|
||||||
using Femto.Api.Controllers.Media.Dto;
|
using Femto.Api.Controllers.Media.Dto;
|
||||||
|
using Femto.Modules.Media.Application;
|
||||||
using Femto.Modules.Media.Contracts;
|
using Femto.Modules.Media.Contracts;
|
||||||
using Femto.Modules.Media.Contracts.LoadFile;
|
using Femto.Modules.Media.Contracts.LoadFile;
|
||||||
using Femto.Modules.Media.Contracts.SaveFile;
|
using Femto.Modules.Media.Contracts.SaveFile;
|
||||||
|
@ -9,7 +10,7 @@ namespace Femto.Api.Controllers.Media;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("media")]
|
[Route("media")]
|
||||||
public class MediaController(IMediator mediator) : ControllerBase
|
public class MediaController(IMediaModule mediaModule) : ControllerBase
|
||||||
{
|
{
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ActionResult<UploadMediaResponse>> UploadMedia(
|
public async Task<ActionResult<UploadMediaResponse>> UploadMedia(
|
||||||
|
@ -18,7 +19,7 @@ public class MediaController(IMediator mediator) : ControllerBase
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
await using var data = file.OpenReadStream();
|
await using var data = file.OpenReadStream();
|
||||||
var id = await mediator.Send(
|
var id = await mediaModule.PostCommand(
|
||||||
new SaveFileCommand(data, file.ContentType, file.Length),
|
new SaveFileCommand(data, file.ContentType, file.Length),
|
||||||
cancellationToken
|
cancellationToken
|
||||||
);
|
);
|
||||||
|
@ -30,7 +31,7 @@ public class MediaController(IMediator mediator) : ControllerBase
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public async Task GetMedia(Guid id, CancellationToken cancellationToken)
|
public async Task GetMedia(Guid id, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var res = await mediator.Send(new LoadFileQuery(id), cancellationToken);
|
var res = await mediaModule.PostQuery(new LoadFileQuery(id), cancellationToken);
|
||||||
|
|
||||||
HttpContext.Response.ContentType = res.Type;
|
HttpContext.Response.ContentType = res.Type;
|
||||||
HttpContext.Response.ContentLength = res.Size;
|
HttpContext.Response.ContentLength = res.Size;
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
using Femto.Modules.Authentication.Data;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
|
namespace Femto.Modules.Authentication.Application;
|
||||||
|
|
||||||
|
internal class AuthenticationModule(IHost host) : IAuthenticationModule
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
using Femto.Common.Infrastructure.Outbox;
|
||||||
|
using Femto.Modules.Authentication.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
|
namespace Femto.Modules.Authentication.Application;
|
||||||
|
|
||||||
|
public static class AuthenticationStartup
|
||||||
|
{
|
||||||
|
public static void InitializeAuthenticationModule(this IServiceCollection rootContainer, string connectionString)
|
||||||
|
{
|
||||||
|
var hostBuilder = Host.CreateDefaultBuilder();
|
||||||
|
hostBuilder.ConfigureServices(services => ConfigureServices(services, connectionString));
|
||||||
|
|
||||||
|
var host = hostBuilder.Build();
|
||||||
|
|
||||||
|
rootContainer.AddScoped<IAuthenticationModule>(_ => new AuthenticationModule(host));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConfigureServices(IServiceCollection services, string connectionString)
|
||||||
|
{
|
||||||
|
services.AddDbContext<AuthenticationContext>(
|
||||||
|
builder =>
|
||||||
|
{
|
||||||
|
builder.UseNpgsql(connectionString);
|
||||||
|
builder.UseSnakeCaseNamingConvention();
|
||||||
|
});
|
||||||
|
|
||||||
|
services.AddMediatR(c => c.RegisterServicesFromAssembly(typeof(AuthenticationStartup).Assembly));
|
||||||
|
|
||||||
|
services.AddDbContext<AuthenticationContext>(builder =>
|
||||||
|
{
|
||||||
|
builder.UseNpgsql();
|
||||||
|
builder.UseSnakeCaseNamingConvention();
|
||||||
|
builder.EnableSensitiveDataLogging();
|
||||||
|
});
|
||||||
|
|
||||||
|
services.AddMediatR(c =>
|
||||||
|
{
|
||||||
|
c.RegisterServicesFromAssembly(typeof(AuthenticationStartup).Assembly);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
namespace Femto.Modules.Authentication.Application;
|
||||||
|
|
||||||
|
public interface IAuthenticationModule
|
||||||
|
{
|
||||||
|
}
|
|
@ -1,57 +0,0 @@
|
||||||
using Femto.Common.Infrastructure.Outbox;
|
|
||||||
using Femto.Modules.Authentication.Data;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace Femto.Modules.Authentication;
|
|
||||||
|
|
||||||
public static class Module
|
|
||||||
{
|
|
||||||
public static void UseIdentityModule(this IServiceCollection services, string connectionString)
|
|
||||||
{
|
|
||||||
services.AddDbContext<AuthenticationContext>(
|
|
||||||
builder =>
|
|
||||||
{
|
|
||||||
builder.UseNpgsql(connectionString);
|
|
||||||
builder.UseSnakeCaseNamingConvention();
|
|
||||||
});
|
|
||||||
|
|
||||||
services.AddMediatR(c => c.RegisterServicesFromAssembly(typeof(Module).Assembly));
|
|
||||||
|
|
||||||
services.AddDbContext<AuthenticationContext>(builder =>
|
|
||||||
{
|
|
||||||
builder.UseNpgsql(
|
|
||||||
connectionString,
|
|
||||||
o =>
|
|
||||||
{
|
|
||||||
o.MapEnum<OutboxEntryStatus>("outbox_status");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
builder.UseSnakeCaseNamingConvention();
|
|
||||||
|
|
||||||
var loggerFactory = LoggerFactory.Create(b =>
|
|
||||||
{
|
|
||||||
// b.AddConsole();
|
|
||||||
// .AddFilter(
|
|
||||||
// (category, level) =>
|
|
||||||
// category == DbLoggerCategory.Database.Command.Name
|
|
||||||
// && level == LogLevel.Debug
|
|
||||||
// );
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.UseLoggerFactory(loggerFactory);
|
|
||||||
builder.EnableSensitiveDataLogging();
|
|
||||||
});
|
|
||||||
|
|
||||||
// services.AddOutbox<AuthenticationContext>();
|
|
||||||
|
|
||||||
services.AddMediatR(c =>
|
|
||||||
{
|
|
||||||
c.RegisterServicesFromAssembly(typeof(Module).Assembly);
|
|
||||||
});
|
|
||||||
|
|
||||||
services.AddTransient<Outbox<AuthenticationContext>, Outbox<AuthenticationContext>>();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,6 +4,6 @@ namespace Femto.Modules.Media.Application;
|
||||||
|
|
||||||
public interface IMediaModule
|
public interface IMediaModule
|
||||||
{
|
{
|
||||||
Task<TResult> PostCommand<TResult>(ICommand<TResult> command);
|
Task<TResult> PostCommand<TResult>(ICommand<TResult> command, CancellationToken cancellationToken = default);
|
||||||
Task<TResult> PostQuery<TResult>(IQuery<TResult> query);
|
Task<TResult> PostQuery<TResult>(IQuery<TResult> query, CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
|
@ -5,21 +5,21 @@ using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace Femto.Modules.Media.Application;
|
namespace Femto.Modules.Media.Application;
|
||||||
|
|
||||||
public class MediaModule(IHost host) : IMediaModule
|
internal class MediaModule(IHost host) : IMediaModule
|
||||||
{
|
{
|
||||||
public async Task<TResult> PostCommand<TResult>(ICommand<TResult> command)
|
public async Task<TResult> PostCommand<TResult>(ICommand<TResult> command, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
using var scope = host.Services.CreateScope();
|
using var scope = host.Services.CreateScope();
|
||||||
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
|
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
|
||||||
var response = await mediator.Send(command);
|
var response = await mediator.Send(command, cancellationToken);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<TResult> PostQuery<TResult>(IQuery<TResult> query)
|
public async Task<TResult> PostQuery<TResult>(IQuery<TResult> query, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
using var scope = host.Services.CreateScope();
|
using var scope = host.Services.CreateScope();
|
||||||
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
|
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
|
||||||
var response = await mediator.Send(query);
|
var response = await mediator.Send(query, cancellationToken);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
|
using Femto.Common.Domain;
|
||||||
using Femto.Modules.Media.Contracts.LoadFile.Dto;
|
using Femto.Modules.Media.Contracts.LoadFile.Dto;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
|
|
||||||
namespace Femto.Modules.Media.Contracts.LoadFile;
|
namespace Femto.Modules.Media.Contracts.LoadFile;
|
||||||
|
|
||||||
public record LoadFileQuery(Guid FileId) : IRequest<LoadFileQueryResult>;
|
public record LoadFileQuery(Guid FileId) : IQuery<LoadFileQueryResult>;
|
|
@ -1,5 +1,6 @@
|
||||||
|
using Femto.Common.Domain;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
|
|
||||||
namespace Femto.Modules.Media.Contracts.SaveFile;
|
namespace Femto.Modules.Media.Contracts.SaveFile;
|
||||||
|
|
||||||
public record SaveFileCommand(Stream Data, string ContentType, long? ContentLength) : IRequest<Guid>;
|
public record SaveFileCommand(Stream Data, string ContentType, long? ContentLength) : ICommand<Guid>;
|
Loading…
Add table
Add a link
Reference in a new issue