[FA-55] User service should be done
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using FictionArchive.Service.Shared.Services.EventBus;
|
||||||
using FictionArchive.Service.UserService.Models.Database;
|
using FictionArchive.Service.UserService.Models.Database;
|
||||||
using FictionArchive.Service.UserService.Services;
|
using FictionArchive.Service.UserService.Services;
|
||||||
using FictionArchive.Service.UserService.Services.AuthenticationClient;
|
using FictionArchive.Service.UserService.Services.AuthenticationClient;
|
||||||
@@ -25,12 +26,14 @@ public class UserManagementServiceTests
|
|||||||
|
|
||||||
private static UserManagementService CreateService(
|
private static UserManagementService CreateService(
|
||||||
UserServiceDbContext dbContext,
|
UserServiceDbContext dbContext,
|
||||||
IAuthenticationServiceClient authClient)
|
IAuthenticationServiceClient authClient,
|
||||||
|
IEventBus? eventBus = null)
|
||||||
{
|
{
|
||||||
return new UserManagementService(
|
return new UserManagementService(
|
||||||
dbContext,
|
dbContext,
|
||||||
NullLogger<UserManagementService>.Instance,
|
NullLogger<UserManagementService>.Instance,
|
||||||
authClient);
|
authClient,
|
||||||
|
eventBus ?? Substitute.For<IEventBus>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static User CreateTestUser(string username, string email, int availableInvites = 5)
|
private static User CreateTestUser(string username, string email, int availableInvites = 5)
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
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; }
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
|
using FictionArchive.Service.Shared.Services.EventBus;
|
||||||
using FictionArchive.Service.UserService.Models.Database;
|
using FictionArchive.Service.UserService.Models.Database;
|
||||||
|
using FictionArchive.Service.UserService.Models.IntegrationEvents;
|
||||||
using FictionArchive.Service.UserService.Services.AuthenticationClient;
|
using FictionArchive.Service.UserService.Services.AuthenticationClient;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
@@ -9,15 +11,18 @@ public class UserManagementService
|
|||||||
private readonly ILogger<UserManagementService> _logger;
|
private readonly ILogger<UserManagementService> _logger;
|
||||||
private readonly UserServiceDbContext _dbContext;
|
private readonly UserServiceDbContext _dbContext;
|
||||||
private readonly IAuthenticationServiceClient _authClient;
|
private readonly IAuthenticationServiceClient _authClient;
|
||||||
|
private readonly IEventBus _eventBus;
|
||||||
|
|
||||||
public UserManagementService(
|
public UserManagementService(
|
||||||
UserServiceDbContext dbContext,
|
UserServiceDbContext dbContext,
|
||||||
ILogger<UserManagementService> logger,
|
ILogger<UserManagementService> logger,
|
||||||
IAuthenticationServiceClient authClient)
|
IAuthenticationServiceClient authClient,
|
||||||
|
IEventBus eventBus)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_authClient = authClient;
|
_authClient = authClient;
|
||||||
|
_eventBus = eventBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -94,6 +99,17 @@ public class UserManagementService
|
|||||||
|
|
||||||
await _dbContext.SaveChangesAsync();
|
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
|
||||||
|
});
|
||||||
|
|
||||||
_logger.LogInformation(
|
_logger.LogInformation(
|
||||||
"User {Username} was successfully invited by {InviterId}. New user id: {NewUserId}",
|
"User {Username} was successfully invited by {InviterId}. New user id: {NewUserId}",
|
||||||
username, inviter.Id, newUser.Id);
|
username, inviter.Id, newUser.Id);
|
||||||
|
|||||||
Reference in New Issue
Block a user