Initial curated itworx-knowledge-hub source from 3b1751d0d9dee551aa6994eee0093704dc334817
This commit is contained in:
commit
ad8ad252a9
825 files changed
+124216
No files matched your search
+35
@@ -0,0 +1,35 @@
|
||||
using ItWorx.KnowledgeHub.Application.Common;
|
||||
using ItWorx.KnowledgeHub.Domain.Ingestion;
|
||||
|
||||
namespace ItWorx.KnowledgeHub.Application.Ingestion.UseCases;
|
||||
|
||||
public sealed record CreateIngestionProposalCommand(Guid WorkspaceId, Guid ActorId, string Manifest, string CorrelationId,
|
||||
string? IdempotencyKey, IngestionPublication? Publication = null);
|
||||
|
||||
public sealed class CreateIngestionProposalUseCase(IIngestionProposalRepository proposals, TimeProvider timeProvider)
|
||||
{
|
||||
public async Task<OperationResultValue<Guid>> ExecuteAsync(CreateIngestionProposalCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
if (command.WorkspaceId == Guid.Empty || command.ActorId == Guid.Empty || string.IsNullOrWhiteSpace(command.Manifest) || command.Manifest.Length > 100_000)
|
||||
return OperationResultValue.Failure<Guid>(OperationStatus.ValidationFailed, ["Ongeldig voorstel."]);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(command.IdempotencyKey))
|
||||
{
|
||||
var existing = await proposals.FindByIdempotencyKeyAsync(command.WorkspaceId, command.IdempotencyKey, cancellationToken);
|
||||
if (existing is not null)
|
||||
return OperationResultValue.Success(existing.Id);
|
||||
}
|
||||
|
||||
var proposal = IngestionProposal.Create(command.WorkspaceId, command.ActorId,
|
||||
string.IsNullOrWhiteSpace(command.CorrelationId) ? "ingestion" : command.CorrelationId,
|
||||
command.Manifest, IngestionProposal.DefaultMaxPublishRetries);
|
||||
if (!string.IsNullOrWhiteSpace(command.IdempotencyKey)) proposal.AssignIdempotencyKey(command.IdempotencyKey);
|
||||
if (command.Publication is not null)
|
||||
{
|
||||
proposal.SetPublication(command.Publication, command.ActorId, timeProvider.GetUtcNow());
|
||||
}
|
||||
proposals.Add(proposal);
|
||||
await proposals.SaveChangesAsync(cancellationToken);
|
||||
return OperationResultValue.Success(proposal.Id);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user