Skip to content

Commit 3342873

Browse files
authored
Merge pull request #136 from samuelzedec/develop
feat: atualizar relacionamentos de entidades e melhorar resiliência do banco de dados
2 parents 30d1eda + 898c2fa commit 3342873

File tree

15 files changed

+2195
-27
lines changed

15 files changed

+2195
-27
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Riber - Changelog
22

3+
## v4.3.1 - 09/12/2025
4+
**REFATOÇÃO**: Remove o método de busca por id da entidade nos IAiModelService
5+
Adiciona relationacimento entre entidade `ProductEmbeddings` e `Company` para uma melhor busca
6+
7+
---
8+
39
## v4.3.0 - 08/11/2025
410
- **NOVO**: Novas entidades par uso de chat e agendes de IA
511
- Adiciona entidade `Chat` para o usuário armazenar conversas com IA

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Companies>Samuel Zedec</Companies>
55
<Copyright>Copyright © $([System.DateTime]::Now.Year)</Copyright>
66
<Description>Sistema de gestão financeira para um lanchonete local</Description>
7-
<Version>4.3.0</Version>
7+
<Version>4.3.1</Version>
88
</PropertyGroup>
99

1010
<!-- Repositório e Documentação -->

src/Riber.Application/Abstractions/Services/AI/IAiModelService.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Riber.Application.Abstractions.Services.AI;
22

3-
public interface IAiModelService<TInput, TOutput>
3+
public interface IAiModelService<in TInput, TOutput>
44
where TInput : class
55
where TOutput : class
66
{
@@ -23,17 +23,10 @@ public interface IAiModelService<TInput, TOutput>
2323
/// <summary>
2424
/// Encontra itens semelhantes com base no vetor de consulta fornecido.
2525
/// </summary>
26+
/// <param name="companyId">O identificador único da empresa a ser consultada.</param>
2627
/// <param name="query">Um array de números de ponto flutuante representando o vetor de consulta para a operação de similaridade.</param>
2728
/// <param name="cancellationToken">Um token para monitorar solicitações de cancelamento.</param>
2829
/// <typeparam name="TOutput">O tipo de item que será retornado como resultado da operação.</typeparam>
2930
/// <returns>Uma tarefa que representa a operação assíncrona, contendo uma memória somente leitura de itens semelhantes do tipo especificado.</returns>
30-
Task<ReadOnlyMemory<TOutput>> FindSimilarAsync(float[] query, CancellationToken cancellationToken = default);
31-
32-
/// <summary>
33-
/// Obtém um recurso ou dado com base no identificador da entidade especificado.
34-
/// </summary>
35-
/// <param name="entityId">O identificador único da entidade a ser recuperada.</param>
36-
/// <param name="cancellationToken">Um token para monitorar solicitações de cancelamento.</param>
37-
/// <returns>Uma tarefa que representa a operação assíncrona, contendo o recurso ou dado encontrado, ou null se não encontrado.</returns>
38-
Task<TInput?> GetByEntityIdAsync(Guid entityId, CancellationToken cancellationToken = default);
31+
Task<ReadOnlyMemory<TOutput>> FindSimilarAsync(Guid companyId, float[] query, CancellationToken cancellationToken = default);
3932
}

src/Riber.Domain/Enums/AssistantType.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ public enum AssistantType
44
{
55
SalesAnalysis = 1,
66
ProductAnalysis = 2,
7-
MonthlyReport = 3
87
}

src/Riber.Infrastructure/DependencyInjection.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ private static void AddPersistence(this IServiceCollection services, string defa
105105
b.MigrationsAssembly(typeof(AppDbContext).Assembly.FullName)
106106
.MigrationsHistoryTable("__EFMigrationsHistory");
107107
})
108-
.AddInterceptors(new CaseInsensitiveInterceptor(), new AuditInterceptor()));
108+
.AddInterceptors(new CaseInsensitiveInterceptor(), new AuditInterceptor())
109+
.EnableDetailedErrors()
110+
.EnableServiceProviderCaching()
111+
);
109112
}
110113

111114
private static void AddRepositories(this IServiceCollection services)

src/Riber.Infrastructure/Extensions/AssistantTypeExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class AssistantTypeExtension
77
public static string GetModel(this AssistantType assistantType)
88
=> assistantType switch
99
{
10-
AssistantType.SalesAnalysis or AssistantType.MonthlyReport => "claude-sonnet-4-20250514",
10+
AssistantType.SalesAnalysis => "claude-sonnet-4-20250514",
1111
AssistantType.ProductAnalysis => "claude-haiku-4-5-20251001",
1212
_ => throw new ArgumentOutOfRangeException(nameof(assistantType), assistantType, null)
1313
};

src/Riber.Infrastructure/Messaging/Consumers/GenerateProductEmbeddingsMessageConsumer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public async Task Consume(ConsumeContext<GenerateProductEmbeddingsMessage> conte
4040
logger.LogInformation("Embeddings do produto {ProductId} gerados.", productId);
4141
var productEmbeddingsModel = new ProductEmbeddingsModel
4242
{
43-
ProductId = productId,
44-
Embeddings = new Vector(embeddings)
43+
ProductId = productId, CompanyId = product.CompanyId, Embeddings = new Vector(embeddings)
4544
};
4645

4746
await modelService.CreateAsync(productEmbeddingsModel, context.CancellationToken);

src/Riber.Infrastructure/Persistence/Factories/AppDbContextFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public AppDbContext CreateDbContext(string[] args)
2525
b.MigrationsAssembly(typeof(AppDbContext).Assembly.FullName)
2626
.MigrationsHistoryTable("__EFMigrationsHistory");
2727
})
28-
.AddInterceptors(
29-
new CaseInsensitiveInterceptor(),
30-
new AuditInterceptor());
28+
.AddInterceptors(new CaseInsensitiveInterceptor(), new AuditInterceptor())
29+
.EnableSensitiveDataLogging()
30+
.EnableServiceProviderCaching();
3131

3232
return new AppDbContext(optionsBuilder.Options);
3333
}

src/Riber.Infrastructure/Persistence/Mappings/Models/ProductEmbeddingsModelMap.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,18 @@ protected override void Mapping(EntityTypeBuilder<ProductEmbeddingsModel> builde
3030
.HasForeignKey(p => p.ProductId)
3131
.HasConstraintName("fk_product_embeddings_product_id")
3232
.OnDelete(DeleteBehavior.NoAction);
33+
34+
builder
35+
.Property(p => p.CompanyId)
36+
.HasColumnName("company_id")
37+
.HasColumnType("uuid")
38+
.IsRequired();
39+
40+
builder
41+
.HasOne(p => p.Company)
42+
.WithMany()
43+
.HasForeignKey(p => p.CompanyId)
44+
.HasConstraintName("fk_product_embeddings_company_id")
45+
.OnDelete(DeleteBehavior.NoAction);
3346
}
3447
}

0 commit comments

Comments
 (0)