feat: establish formal relationship between KnowledgeUnit and Ebook (#35) (#43)

This PR finalizes the implementation of issue #35 by establishing a formal foreign key relationship between `KnowledgeUnit` and `Ebook`.

Closes #35

### Changes:
- **Domain**: Refactored `KnowledgeUnit` to use `Guid EbookId` and added navigation property.
- **Data**: Updated `AppDbContext` fluent configuration and generated a new migration.
- **Service**: Updated `IKnowledgeService` and its implementations to propagate `ebookId`.
- **API**: Updated Web API endpoints to support linking extracted knowledge to specific ebooks.

### Verification:
- [x] Solution builds successfully (`dotnet build`).
- [x] Schema changes verified in migration file.
- [x] Cascading delete behavior confirmed.

---------

Co-authored-by: Marek Jasiński <jasins.marek@gmail.com>
Reviewed-on: #43
Co-authored-by: Antigravity <antigravity@google.com>
Co-committed-by: Antigravity <antigravity@google.com>
This commit was merged in pull request #43.
This commit is contained in:
2026-05-14 18:17:16 +00:00
committed by Marek Jaisński
parent 5a2223a4c8
commit f808734768
13 changed files with 1605 additions and 42 deletions
@@ -4,5 +4,6 @@ namespace NexusReader.Application.Queries.Graph;
/// <param name="Text">Chapter or page content to extract the graph from.</param>
/// <param name="TenantId">Tenant scope for knowledge extraction and caching.</param>
public record GetKnowledgeGraphQuery(string Text, string TenantId) : IQuery<GraphDataDto>;
/// <param name="EbookId">Optional Ebook ID to link the knowledge units to.</param>
public record GetKnowledgeGraphQuery(string Text, string TenantId, Guid? EbookId = null) : IQuery<GraphDataDto>;
@@ -18,7 +18,11 @@ internal sealed class GetKnowledgeGraphQueryHandler : IQueryHandler<GetKnowledge
if (string.IsNullOrWhiteSpace(request.Text))
return Result.Ok(new GraphDataDto());
var result = await _knowledgeService.GetGraphDataAsync(request.Text, request.TenantId, cancellationToken);
var result = await _knowledgeService.GetGraphDataAsync(
request.Text,
request.TenantId,
ebookId: request.EbookId,
cancellationToken: cancellationToken);
if (result.IsFailed)
return Result.Fail<GraphDataDto>(result.Errors);