Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3013027
Move registration endpoint to new RegisterController
Foqsz Apr 7, 2026
42bcc0f
Update password and email validation in client use cases
Foqsz Apr 7, 2026
54ed0e3
Update login error messages to cover email and password
Foqsz Apr 7, 2026
da1174a
Refactor product use cases to use authenticated user ID
Foqsz Apr 8, 2026
f725125
Add unit tests for UpdateClientUseCase and refactor helpers
Foqsz Apr 8, 2026
b353c73
Integrate RabbitMQ messaging for client creation events
Foqsz Apr 9, 2026
8e76df4
#
Foqsz Apr 11, 2026
7af0a1c
#
Foqsz Apr 13, 2026
b6f1b0b
Merge branch 'master' into develop
Foqsz Apr 13, 2026
03daf8b
#
Foqsz Apr 14, 2026
68f5577
Merge branch 'develop' of https://github.com/Foqsz/ProductClientHub i…
Foqsz Apr 14, 2026
91cba1d
#
Foqsz Apr 15, 2026
f350e18
Merge branch 'master' into develop
Foqsz Apr 15, 2026
a57d179
#
Foqsz Apr 15, 2026
5359eb5
Merge branch 'develop' of https://github.com/Foqsz/ProductClientHub i…
Foqsz Apr 15, 2026
9c4ad17
#
Foqsz Apr 16, 2026
e08b4a6
Merge branch 'master' into develop
Foqsz Apr 16, 2026
8111877
feat: remove open api
Foqsz Apr 19, 2026
1b9657a
feat: update client integration test.
Foqsz Apr 20, 2026
7e38534
feat: Moq realizado para a integração test
Foqsz Apr 20, 2026
fee32f4
feat: teste para caso ja exista um e-mail na tentativa de update.
Foqsz Apr 20, 2026
ffa46d8
Merge branch 'master' into develop
Foqsz Apr 20, 2026
00cb12a
feat: adicionando logged user ao teste
Foqsz Apr 22, 2026
5c6fe04
feat: agora nao preciso mais do clientid no endpoint, ja recebo via l…
Foqsz Apr 22, 2026
dcb366e
Merge branch 'develop' of https://github.com/Foqsz/ProductClientHub i…
Foqsz Apr 22, 2026
adeeacb
fix: fiz esse ajuste pq mesmo se o usuario tentasse trocar seu e-mail…
Foqsz Apr 24, 2026
68a0b64
feat: teste de integração para o update do usuario. Tudo ok, devidame…
Foqsz Apr 24, 2026
7a77730
Merge branch 'master' into develop
Foqsz Apr 24, 2026
c01147c
#
Foqsz Apr 28, 2026
6cbb6e9
Merge branch 'master' into develop
Foqsz Apr 30, 2026
14ca130
##
Foqsz Apr 30, 2026
915a3e1
Merge branch 'develop' of https://github.com/Foqsz/ProductClientHub i…
Foqsz Apr 30, 2026
9324aa2
Refactor delete repo interface; add use case tests
Foqsz Apr 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CommonTestUtilities/Entities/ClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public static (Client client, string password) Build()
.RuleFor(client => client.Id, () => Guid.NewGuid())
.RuleFor(client => client.Name, (f) => f.Person.FirstName)
.RuleFor(client => client.Email, (f, user) => f.Internet.Email(user.Name))
.RuleFor(client => client.Password, (f) => passwordEncripter.Encrypt(password));
.RuleFor(client => client.Password, (f) => passwordEncripter.Encrypt(password))
.RuleFor(client => client.Products, () => new List<Product>());

return (client, password);
}
Expand Down
3 changes: 3 additions & 0 deletions CommonTestUtilities/Entities/ProductBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public static IList<Product> Collection(Client client, uint count = 2)
list.Add(fakeProduct);
}

foreach (var product in list)
client.Products.Add(product);

return list;
}

Expand Down
10 changes: 5 additions & 5 deletions CommonTestUtilities/LoggedUser/LoggedUserBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Moq;
using ProductClientHub.Domain.Entities;
using ProductClientHub.Domain.Services.LoggedUser;
using ProductClientHub.Domain.Services.loggedClient;

namespace CommonTestUtilities.LoggedUser;
namespace CommonTestUtilities.loggedClient;

public class LoggedUserBuilder
public class LoggedClientBuilder
{
public static ILoggedUser Build(Client client)
public static ILoggedClient Build(Client client)
{
var mock = new Mock<ILoggedUser>();
var mock = new Mock<ILoggedClient>();

mock.Setup(c => c.User()).ReturnsAsync(client);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ public ClientReadOnlyRepositoryBuilder()

public ClientReadOnlyRepositoryBuilder EmailAlreadyExists(Client? client)
{
if(client is not null)
if (client is not null)
_repository.Setup(r => r.EmailAlreadyExists(client.Email)).ReturnsAsync(client);

return this;
}

public ClientReadOnlyRepositoryBuilder EmailAlreadyExists(Client? clientEmail, Client? clientReturned)
{
if (clientEmail is not null && clientReturned is not null)
_repository.Setup(r => r.EmailAlreadyExists(clientEmail.Email)).ReturnsAsync(clientReturned);

return this;
}

public ClientReadOnlyRepositoryBuilder GetAll(IList<Client> clients)
{
_repository.Setup(r => r.GetAll()).ReturnsAsync(clients);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Moq;
using ProductClientHub.Domain.Repositories.Product;

namespace CommonTestUtilities.Repositories;

public class DeleteProductWriteOnlyRepositoryBuild
{
public static IDeleteProductWriteOnlyRepository Build(bool deleteResult = true)
{
var mock = new Mock<IDeleteProductWriteOnlyRepository>();
mock.Setup(r => r.Delete(It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(deleteResult);
return mock.Object;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Moq;
using ProductClientHub.Domain.Repositories.Product;

namespace CommonTestUtilities.Repositories;

public class ProductsReadOnlyRepositoryBuild
{
private readonly Mock<IProductsReadOnlyRepository> _repository;

public ProductsReadOnlyRepositoryBuild()
{
_repository = new Mock<IProductsReadOnlyRepository>();
}

public ProductsReadOnlyRepositoryBuild GetAll(IList<ProductClientHub.Domain.Entities.Product> products)
{
_repository.Setup(r => r.GetAll()).ReturnsAsync(products);
return this;
}

public ProductsReadOnlyRepositoryBuild GetById(ProductClientHub.Domain.Entities.Product? product)
{
if(product is not null)
_repository.Setup(r => r.GetById(It.IsAny<Guid>())).ReturnsAsync(product);

return this;
}

public IProductsReadOnlyRepository Build()
{
return _repository.Object;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using ProductClientHub.Domain.Extensions;
using ProductClientHub.Domain.Repositories.Client;
using ProductClientHub.Domain.Repositories.UnitOfWork;
using ProductClientHub.Domain.Services.LoggedUser;
using ProductClientHub.Domain.Services.loggedClient;
using ProductClientHub.Exceptions.ExceptionsBase;

namespace ProductClientHub.Application.UseCases.Users.Update;
Expand All @@ -15,24 +15,24 @@ public class UpdateClientUseCase : IUpdateClientUseCase
private readonly IClientWriteOnlyRepository _clientWriteOnlyRepository;
private readonly IClientReadOnlyRepository _clientReadOnlyRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly ILoggedUser _loggedUser;
private readonly ILoggedClient _loggedClient;

public UpdateClientUseCase(IClientWriteOnlyRepository clientWriteOnlyRepository,
IClientReadOnlyRepository clientReadOnlyRepository,
IUnitOfWork unitOfWork,
ILoggedUser loggedUser)
ILoggedClient loggedClient)
{
_clientWriteOnlyRepository = clientWriteOnlyRepository;
_clientReadOnlyRepository = clientReadOnlyRepository;
_unitOfWork = unitOfWork;
_loggedUser = loggedUser;
_loggedClient = loggedClient;
}

public async Task<ResponseClientUpdatedJson> Execute(RequestShortClientJson request)
{
Validate(request);

var userLogged = await _loggedUser.User();
var userLogged = await _loggedClient.User();

var client = await _clientReadOnlyRepository.GetById(userLogged.Id) ?? throw new NotFoundException(ResourceMessagesExceptions.CLIENT_NOCONTENT);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
using ProductClientHub.Domain.Extensions;
using ProductClientHub.Domain.Repositories.Product;
using ProductClientHub.Domain.Repositories.UnitOfWork;
using ProductClientHub.Domain.Services.LoggedUser;
using ProductClientHub.Domain.Services.loggedClient;
using ProductClientHub.Exceptions.ExceptionsBase;

namespace ProductClientHub.Application.UseCases.Products.Delete;

public class DeleteProductUseCase : IDeleteProductUseCase
{
private readonly IDeleteProductOnlyRepository _productsWriteOnlyRepository;
private readonly IDeleteProductWriteOnlyRepository _productsWriteOnlyRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly ILoggedUser _loggedUser;
private readonly ILoggedClient _loggedClient;

public DeleteProductUseCase(IDeleteProductOnlyRepository productsWriteOnlyRepository,
public DeleteProductUseCase(IDeleteProductWriteOnlyRepository productsWriteOnlyRepository,
IUnitOfWork unitOfWork,
ILoggedUser loggedUser)
ILoggedClient loggedClient)
{
_productsWriteOnlyRepository = productsWriteOnlyRepository;
_unitOfWork = unitOfWork;
_loggedUser = loggedUser;
_loggedClient = loggedClient;
}

public async Task Execute(Guid productId)
{
var client = await _loggedUser.User();
var client = await _loggedClient.User();

var productExist = await _productsWriteOnlyRepository.Delete(client.Id, productId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
using ProductClientHub.Communication.Responses;
using ProductClientHub.Domain.Extensions;
using ProductClientHub.Domain.Repositories.Product;
using ProductClientHub.Domain.Services.LoggedUser;
using ProductClientHub.Domain.Services.loggedClient;
using ProductClientHub.Exceptions.ExceptionsBase;

namespace ProductClientHub.Application.UseCases.Products.GetAll;

public class GetAllProductsUseCase : IGetAllProductsUseCase
{
private readonly IProductsReadOnlyRepository _productReadOnlyRepository;
private readonly ILoggedUser _loggedUser;
private readonly ILoggedClient _loggedClient;

public GetAllProductsUseCase(IProductsReadOnlyRepository productReadOnlyRepository, ILoggedUser loggedUser)
public GetAllProductsUseCase(IProductsReadOnlyRepository productReadOnlyRepository, ILoggedClient loggedClient)
{
_productReadOnlyRepository = productReadOnlyRepository;
_loggedUser = loggedUser;
_loggedClient = loggedClient;
}

public async Task<ResponseProductsJson> Execute()
{
var user = await _loggedUser.User();
var user = await _loggedClient.User();

if (user is null)
throw new UserNotLoggedException(ResourceMessagesExceptions.NOT_LOGGED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using ProductClientHub.Domain.Repositories.Client;
using ProductClientHub.Domain.Repositories.Product;
using ProductClientHub.Domain.Repositories.UnitOfWork;
using ProductClientHub.Domain.Services.LoggedUser;
using ProductClientHub.Domain.Services.loggedClient;
using ProductClientHub.Exceptions.ExceptionsBase;

namespace ProductClientHub.Application.UseCases.Products.Register;
Expand All @@ -16,22 +16,22 @@ public class RegisterProductUseCase : IRegisterProductUseCase
private readonly IProductsWriteOnlyRepository _productsWriteOnlyRepository;
private readonly IClientReadOnlyRepository _clientReadOnlyRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly ILoggedUser _loggedUser;
private readonly ILoggedClient _loggedClient;

public RegisterProductUseCase(IProductsWriteOnlyRepository productsWriteOnlyRepository,
IUnitOfWork unitOfWork,
IClientReadOnlyRepository clientReadOnlyRepository,
ILoggedUser loggedUser)
ILoggedClient loggedClient)
{
_productsWriteOnlyRepository = productsWriteOnlyRepository;
_unitOfWork = unitOfWork;
_clientReadOnlyRepository = clientReadOnlyRepository;
_loggedUser = loggedUser;
_loggedClient = loggedClient;
}

public async Task<ResponseShortProductJson> Execute(RequestProductJson request)
{
var user = await _loggedUser.User();
var user = await _loggedClient.User();

await Validate(user.Id, request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using ProductClientHub.Domain.Repositories.Client;
using ProductClientHub.Domain.Repositories.Product;
using ProductClientHub.Domain.Repositories.UnitOfWork;
using ProductClientHub.Domain.Services.LoggedUser;
using ProductClientHub.Domain.Services.loggedClient;
using ProductClientHub.Exceptions.ExceptionsBase;

namespace ProductClientHub.Application.UseCases.Products.Update;
Expand All @@ -17,24 +17,24 @@ public class UploadProductUseCase : IUploadProductUseCase
private readonly IClientReadOnlyRepository _clientReadOnlyRepository;
private readonly IProductsReadOnlyRepository _productsReadOnlyRepository;
private readonly IUploadProductOnlyRepository _productWriteOnlyRepository;
private readonly ILoggedUser _loggedUser;
private readonly ILoggedClient _loggedClient;

public UploadProductUseCase(IUnitOfWork unitOfWork,
IUploadProductOnlyRepository productWriteOnlyRepository,
IClientReadOnlyRepository clientReadOnlyRepository,
IProductsReadOnlyRepository productsReadOnlyRepository,
ILoggedUser loggedUser)
ILoggedClient loggedClient)
{
_unitOfWork = unitOfWork;
_productWriteOnlyRepository = productWriteOnlyRepository;
_clientReadOnlyRepository = clientReadOnlyRepository;
_productsReadOnlyRepository = productsReadOnlyRepository;
_loggedUser = loggedUser;
_loggedClient = loggedClient;
}

public async Task<ResponseShortProductJson> Execute(Guid productId, RequestProductJson request)
{
var client = await _loggedUser.User();
var client = await _loggedClient.User();
await Validate(client.Id, request);

var product = await _productsReadOnlyRepository.GetById(productId) ?? throw new NotFoundException(ResourceMessagesExceptions.PRODUCT_NOTFOUND);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ProductClientHub.Domain.Repositories.Product;

public interface IDeleteProductOnlyRepository
public interface IDeleteProductWriteOnlyRepository
{
Task<bool> Delete(Guid clientId, Guid productId);
}
4 changes: 2 additions & 2 deletions ProductClientHub.Domain/Services/LoggedUser/ILoggedUser.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using ProductClientHub.Domain.Entities;

namespace ProductClientHub.Domain.Services.LoggedUser;
namespace ProductClientHub.Domain.Services.loggedClient;

public interface ILoggedUser
public interface ILoggedClient
{
public Task<Client> User();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace ProductClientHub.Infrastructure.DataAcess.Repositories.Products;

public class ProductsWriteOnlyRepository : IProductsWriteOnlyRepository, IDeleteProductOnlyRepository, IUploadProductOnlyRepository
public class ProductsWriteOnlyRepository : IProductsWriteOnlyRepository, IDeleteProductWriteOnlyRepository, IUploadProductOnlyRepository
{
private readonly ProductClientHubDbContext _dbContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
using ProductClientHub.Domain.Security.Tokens;
using ProductClientHub.Infrastructure.Security.Tokens.Acess.Generator;
using ProductClientHub.Infrastructure.Security.Tokens.Acess.Validator;
using ProductClientHub.Domain.Services.LoggedUser;
using ProductClientHub.Domain.Services.loggedClient;
using ProductClientHub.Domain.Services.Messaging;
using ProductClientHub.Infrastructure.Services;
using ProductClientHub.Infrastructure.Messaging.RabbitMq;
Expand All @@ -37,7 +37,7 @@
AddFluentMigrator_PostgreSql(services, configuration);
AddTokens(services, configuration);
AddPasswordEncrpter(services);
AddLoggedUser(services);
AddloggedClient(services);
AddMessaging(services, configuration);
}

Expand All @@ -63,7 +63,7 @@
//products
services.AddScoped<IProductsWriteOnlyRepository, ProductsWriteOnlyRepository>();
services.AddScoped<IProductsReadOnlyRepository, ProductsReadOnlyRepository>();
services.AddScoped<IDeleteProductOnlyRepository, ProductsWriteOnlyRepository>();
services.AddScoped<IDeleteProductWriteOnlyRepository, ProductsWriteOnlyRepository>();
services.AddScoped<IUploadProductOnlyRepository, ProductsWriteOnlyRepository>();
}

Expand All @@ -75,10 +75,10 @@
services.AddScoped<IAccessTokenGenerator>(option => new JwtTokenGenerator(expirationTimeMinutes, signingKey!));
services.AddScoped<IAccessTokenValidator>(option => new JwtTokenValidator(signingKey!));

//services.AddScoped<IRefreshTokenGenerator, RefreshTokenGenerator>();

Check warning on line 78 in ProductClientHub.Infrastructure/DependencyInjectionExtension.cs

View workflow job for this annotation

GitHub Actions / build

Remove this commented out code.

Check warning on line 78 in ProductClientHub.Infrastructure/DependencyInjectionExtension.cs

View workflow job for this annotation

GitHub Actions / build

Remove this commented out code.

Check warning on line 78 in ProductClientHub.Infrastructure/DependencyInjectionExtension.cs

View workflow job for this annotation

GitHub Actions / build

Remove this commented out code.

Check warning on line 78 in ProductClientHub.Infrastructure/DependencyInjectionExtension.cs

View workflow job for this annotation

GitHub Actions / build

Remove this commented out code.

Check warning on line 78 in ProductClientHub.Infrastructure/DependencyInjectionExtension.cs

View workflow job for this annotation

GitHub Actions / build

Remove this commented out code.

Check warning on line 78 in ProductClientHub.Infrastructure/DependencyInjectionExtension.cs

View workflow job for this annotation

GitHub Actions / build

Remove this commented out code.
}

private static void AddLoggedUser(IServiceCollection services) => services.AddScoped<ILoggedUser, LoggedUser>();
private static void AddloggedClient(IServiceCollection services) => services.AddScoped<ILoggedClient, loggedClient>();

private static void AddMessaging(IServiceCollection services, IConfiguration configuration)
{
Expand Down
6 changes: 3 additions & 3 deletions ProductClientHub.Infrastructure/Services/LoggedUser.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using Microsoft.EntityFrameworkCore;
using ProductClientHub.Domain.Entities;
using ProductClientHub.Domain.Security.Tokens;
using ProductClientHub.Domain.Services.LoggedUser;
using ProductClientHub.Domain.Services.loggedClient;
using ProductClientHub.Infrastructure.Database;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;

namespace ProductClientHub.Infrastructure.Services;

public class LoggedUser : ILoggedUser
public class loggedClient : ILoggedClient

Check warning on line 11 in ProductClientHub.Infrastructure/Services/LoggedUser.cs

View workflow job for this annotation

GitHub Actions / build

Rename class 'loggedClient' to match pascal case naming rules, consider using 'LoggedClient'.

Check warning on line 11 in ProductClientHub.Infrastructure/Services/LoggedUser.cs

View workflow job for this annotation

GitHub Actions / build

Rename class 'loggedClient' to match pascal case naming rules, consider using 'LoggedClient'.

Check warning on line 11 in ProductClientHub.Infrastructure/Services/LoggedUser.cs

View workflow job for this annotation

GitHub Actions / build

Rename class 'loggedClient' to match pascal case naming rules, consider using 'LoggedClient'.

Check warning on line 11 in ProductClientHub.Infrastructure/Services/LoggedUser.cs

View workflow job for this annotation

GitHub Actions / build

Rename class 'loggedClient' to match pascal case naming rules, consider using 'LoggedClient'.

Check warning on line 11 in ProductClientHub.Infrastructure/Services/LoggedUser.cs

View workflow job for this annotation

GitHub Actions / build

Rename class 'loggedClient' to match pascal case naming rules, consider using 'LoggedClient'.

Check warning on line 11 in ProductClientHub.Infrastructure/Services/LoggedUser.cs

View workflow job for this annotation

GitHub Actions / build

Rename class 'loggedClient' to match pascal case naming rules, consider using 'LoggedClient'.
{
private readonly ProductClientHubDbContext _dbContext;
private readonly ITokenProvider _tokenProvider;

public LoggedUser(ProductClientHubDbContext dbContext, ITokenProvider tokenProvider)
public loggedClient(ProductClientHubDbContext dbContext, ITokenProvider tokenProvider)
{
_dbContext = dbContext;
_tokenProvider = tokenProvider;
Expand Down
Loading
Loading