[FA-misc] Initial MassTransit implementation seems to work
This commit is contained in:
12
FictionArchive.Service.UserService/Contracts/UserInvited.cs
Normal file
12
FictionArchive.Service.UserService/Contracts/UserInvited.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
namespace FictionArchive.Service.UserService.Contracts;
|
||||
|
||||
public record UserInvited(
|
||||
string InvitedUserId,
|
||||
string InvitedUsername,
|
||||
string InvitedEmail,
|
||||
string InvitedOAuthProviderId,
|
||||
string InviterId,
|
||||
string InviterUsername,
|
||||
string InviterOAuthProviderId) : IUserInvited;
|
||||
@@ -1,17 +0,0 @@
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.UserService.Models.IntegrationEvents;
|
||||
|
||||
public class UserInvitedEvent : IIntegrationEvent
|
||||
{
|
||||
// Invited user info
|
||||
public Guid InvitedUserId { get; set; }
|
||||
public required string InvitedUsername { get; set; }
|
||||
public required string InvitedEmail { get; set; }
|
||||
public required string InvitedOAuthProviderId { get; set; }
|
||||
|
||||
// Inviter info
|
||||
public Guid InviterId { get; set; }
|
||||
public required string InviterUsername { get; set; }
|
||||
public required string InviterOAuthProviderId { get; set; }
|
||||
}
|
||||
@@ -2,7 +2,6 @@ using System.Net.Http.Headers;
|
||||
using FictionArchive.Common.Extensions;
|
||||
using FictionArchive.Service.Shared;
|
||||
using FictionArchive.Service.Shared.Extensions;
|
||||
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
||||
using FictionArchive.Service.UserService.GraphQL;
|
||||
using FictionArchive.Service.UserService.Services;
|
||||
using FictionArchive.Service.UserService.Services.AuthenticationClient;
|
||||
@@ -19,15 +18,9 @@ public class Program
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.AddLocalAppsettings();
|
||||
|
||||
#region Event Bus
|
||||
#region MassTransit
|
||||
|
||||
if (!isSchemaExport)
|
||||
{
|
||||
builder.Services.AddRabbitMQ(opt =>
|
||||
{
|
||||
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
||||
});
|
||||
}
|
||||
builder.Services.AddFictionArchiveMassTransit(builder.Configuration);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using FictionArchive.Service.UserService.Contracts;
|
||||
using FictionArchive.Service.UserService.Models.Database;
|
||||
using FictionArchive.Service.UserService.Models.IntegrationEvents;
|
||||
using FictionArchive.Service.UserService.Services.AuthenticationClient;
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FictionArchive.Service.UserService.Services;
|
||||
@@ -11,18 +12,18 @@ public class UserManagementService
|
||||
private readonly ILogger<UserManagementService> _logger;
|
||||
private readonly UserServiceDbContext _dbContext;
|
||||
private readonly IAuthenticationServiceClient _authClient;
|
||||
private readonly IEventBus _eventBus;
|
||||
private readonly IPublishEndpoint _publishEndpoint;
|
||||
|
||||
public UserManagementService(
|
||||
UserServiceDbContext dbContext,
|
||||
ILogger<UserManagementService> logger,
|
||||
IAuthenticationServiceClient authClient,
|
||||
IEventBus eventBus)
|
||||
IPublishEndpoint publishEndpoint)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_logger = logger;
|
||||
_authClient = authClient;
|
||||
_eventBus = eventBus;
|
||||
_publishEndpoint = publishEndpoint;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -99,16 +100,14 @@ public class UserManagementService
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
await _eventBus.Publish(new UserInvitedEvent
|
||||
{
|
||||
InvitedUserId = newUser.Id,
|
||||
InvitedUsername = newUser.Username,
|
||||
InvitedEmail = newUser.Email,
|
||||
InvitedOAuthProviderId = newUser.OAuthProviderId,
|
||||
InviterId = inviter.Id,
|
||||
InviterUsername = inviter.Username,
|
||||
InviterOAuthProviderId = inviter.OAuthProviderId
|
||||
});
|
||||
await _publishEndpoint.Publish<IUserInvited>(new UserInvited(
|
||||
InvitedUserId: newUser.Id.ToString(),
|
||||
InvitedUsername: newUser.Username,
|
||||
InvitedEmail: newUser.Email,
|
||||
InvitedOAuthProviderId: newUser.OAuthProviderId,
|
||||
InviterId: inviter.Id.ToString(),
|
||||
InviterUsername: inviter.Username,
|
||||
InviterOAuthProviderId: inviter.OAuthProviderId));
|
||||
|
||||
_logger.LogInformation(
|
||||
"User {Username} was successfully invited by {InviterId}. New user id: {NewUserId}",
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
|
||||
Reference in New Issue
Block a user