mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-15 22:04:05 +08:00
Merge remote-tracking branch 'origin/main'
# Conflicts: # src/Services/Booking/src/Booking/Extensions/CoreExtensions.cs # src/Services/Flight/src/Flight/Extensions/CoreExtensions.cs # src/Services/Identity/src/Identity/Extensions/CoreExtensions.cs # src/Services/Passenger/src/Passenger/Extensions/CoreExtensions.cs
This commit is contained in:
commit
5209765de4
@ -17,10 +17,6 @@ public static class Extensions
|
||||
{
|
||||
public static WebApplicationBuilder AddCustomSerilog(this WebApplicationBuilder builder)
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Console()
|
||||
.CreateBootstrapLogger();
|
||||
|
||||
builder.Host.UseSerilog((context, loggerConfiguration) =>
|
||||
{
|
||||
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
||||
@ -32,11 +28,11 @@ public static class Extensions
|
||||
: LogEventLevel.Information;
|
||||
|
||||
loggerConfiguration
|
||||
.WriteTo.Console()
|
||||
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(loggOptions.ElasticUri))
|
||||
{
|
||||
AutoRegisterTemplate = true,
|
||||
IndexFormat = $"{appOptions.Name}-{environment?.ToLower().Replace(".", "-")}-{DateTime.UtcNow:yyyy-MM}"
|
||||
IndexFormat =
|
||||
$"{appOptions.Name}-{environment?.ToLower().Replace(".", "-")}-{DateTime.UtcNow:yyyy-MM}"
|
||||
})
|
||||
.WriteTo.SpectreConsole(loggOptions.LogTemplate, logLevel)
|
||||
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Error)
|
||||
|
||||
@ -2,10 +2,7 @@ using Booking;
|
||||
using Booking.Configuration;
|
||||
using Booking.Data;
|
||||
using Booking.Extensions;
|
||||
using BuildingBlocks.Core;
|
||||
using BuildingBlocks.EFCore;
|
||||
using BuildingBlocks.EventStoreDB;
|
||||
using BuildingBlocks.EventStoreDB.Projections;
|
||||
using BuildingBlocks.HealthCheck;
|
||||
using BuildingBlocks.IdsGenerator;
|
||||
using BuildingBlocks.Jwt;
|
||||
@ -37,7 +34,7 @@ builder.Services.AddPersistMessage(configuration);
|
||||
builder.Services.AddMongoDbContext<BookingReadDbContext>(configuration);
|
||||
|
||||
builder.AddCustomSerilog();
|
||||
builder.Services.AddCore();
|
||||
builder.Services.AddCore(configuration);
|
||||
builder.Services.AddJwt();
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
|
||||
@ -40,7 +40,7 @@ builder.Services.AddMongoDbContext<FlightReadDbContext>(configuration);
|
||||
builder.Services.AddPersistMessage(configuration);
|
||||
|
||||
builder.AddCustomSerilog();
|
||||
builder.Services.AddCore();
|
||||
builder.Services.AddCore(configuration);
|
||||
builder.Services.AddJwt();
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddCustomSwagger(configuration, typeof(FlightRoot).Assembly);
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using MassTransit;
|
||||
|
||||
namespace Flight;
|
||||
|
||||
public class FlightConsumer : IConsumer<FlightCreated>
|
||||
{
|
||||
public Task Consume(ConsumeContext<FlightCreated> context)
|
||||
{
|
||||
Console.WriteLine("This consumer is for test");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
using System.Threading.Tasks;
|
||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using BuildingBlocks.Web;
|
||||
using Humanizer;
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Flight.Identity.Consumers.RegisterNewUser;
|
||||
|
||||
public class RegisterNewUserConsumerHandler : IConsumer<UserCreated>
|
||||
{
|
||||
private readonly AppOptions _options;
|
||||
private readonly ILogger<RegisterNewUserConsumerHandler> _logger;
|
||||
|
||||
public RegisterNewUserConsumerHandler(IOptions<AppOptions> options,
|
||||
ILogger<RegisterNewUserConsumerHandler> logger)
|
||||
{
|
||||
_options = options.Value;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Consume(ConsumeContext<UserCreated> context)
|
||||
{
|
||||
_logger.LogInformation($"this is a test consumer for {nameof(UserCreated).Underscore()} in {_options.Name}");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@ -31,7 +31,7 @@ Console.WriteLine(FiggleFonts.Standard.Render(appOptions.Name));
|
||||
builder.Services.AddPersistMessage(configuration);
|
||||
builder.Services.AddCustomDbContext<IdentityContext>(configuration);
|
||||
builder.Services.AddScoped<IDataSeeder, IdentityDataSeeder>();
|
||||
builder.Services.AddCore();
|
||||
builder.Services.AddCore(configuration);
|
||||
builder.AddCustomSerilog();
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddCustomSwagger(configuration, typeof(IdentityRoot).Assembly);
|
||||
|
||||
@ -34,7 +34,7 @@ builder.Services.AddMongoDbContext<PassengerReadDbContext>(configuration);
|
||||
builder.Services.AddPersistMessage(configuration);
|
||||
|
||||
builder.AddCustomSerilog();
|
||||
builder.Services.AddCore();
|
||||
builder.Services.AddCore(configuration);
|
||||
builder.Services.AddJwt();
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddCustomSwagger(configuration, typeof(PassengerRoot).Assembly);
|
||||
|
||||
@ -3,30 +3,43 @@ using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using BuildingBlocks.Core;
|
||||
using BuildingBlocks.Core.Event;
|
||||
using BuildingBlocks.IdsGenerator;
|
||||
using BuildingBlocks.Web;
|
||||
using Humanizer;
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Passenger.Data;
|
||||
using Passenger.Passengers.Events.Domain;
|
||||
|
||||
namespace Passenger.Identity.RegisterNewUser;
|
||||
namespace Passenger.Identity.Consumers.RegisterNewUser;
|
||||
|
||||
public class RegisterNewUserConsumerHandler : IConsumer<UserCreated>
|
||||
{
|
||||
private readonly PassengerDbContext _passengerDbContext;
|
||||
private readonly IEventDispatcher _eventDispatcher;
|
||||
private readonly ILogger<RegisterNewUserConsumerHandler> _logger;
|
||||
private readonly AppOptions _options;
|
||||
|
||||
public RegisterNewUserConsumerHandler(PassengerDbContext passengerDbContext,
|
||||
IEventDispatcher eventDispatcher)
|
||||
IEventDispatcher eventDispatcher,
|
||||
ILogger<RegisterNewUserConsumerHandler> logger,
|
||||
IOptions<AppOptions> options)
|
||||
{
|
||||
_passengerDbContext = passengerDbContext;
|
||||
_eventDispatcher = eventDispatcher;
|
||||
_logger = logger;
|
||||
_options = options.Value;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<UserCreated> context)
|
||||
{
|
||||
Guard.Against.Null(context.Message, nameof(UserCreated));
|
||||
|
||||
var passengerExist = await _passengerDbContext.Passengers.AnyAsync(x => x.PassportNumber == context.Message.PassportNumber);
|
||||
_logger.LogInformation($"consumer for {nameof(UserCreated).Underscore()} in {_options.Name}");
|
||||
|
||||
var passengerExist =
|
||||
await _passengerDbContext.Passengers.AnyAsync(x => x.PassportNumber == context.Message.PassportNumber);
|
||||
|
||||
if (passengerExist)
|
||||
return;
|
||||
@ -14,6 +14,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Data\Migrations" />
|
||||
<Folder Include="Identity\Consumers" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user