feat(terminal): ReadDocument-Befehl um PDF-Speicheroptionen erweitert
Optionen `save`, `dir` und `fileName` zum `ReadDocument`-Befehl hinzugefügt. Wenn `save` aktiviert ist, wird das PDF an dem angegebenen oder dem Standardpfad gespeichert. Ermöglicht dem Benutzer mehr Kontrolle über Speicherort und Dateinamen.
This commit is contained in:
parent
186f3c3319
commit
2966d64455
@ -3,23 +3,8 @@
|
||||
/// <summary>
|
||||
/// Represents the response for reading a document.
|
||||
/// </summary>
|
||||
public class ReadDocumentResponse
|
||||
public class ReadDocumentResponse : ReadDocumentResponseBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier of the document.
|
||||
/// </summary>
|
||||
public int Guid { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The identifier of the associated envelope.
|
||||
/// </summary>
|
||||
public int EnvelopeId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The date and time when the document was added.
|
||||
/// </summary>
|
||||
public DateTime AddedWhen { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The binary data of the document, if available.
|
||||
/// </summary>
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
namespace EnvelopeGenerator.Application.Documents.Queries.Read;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the response for reading a document.
|
||||
/// </summary>
|
||||
public class ReadDocumentResponseBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier of the document.
|
||||
/// </summary>
|
||||
public int Guid { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The identifier of the associated envelope.
|
||||
/// </summary>
|
||||
public int EnvelopeId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The date and time when the document was added.
|
||||
/// </summary>
|
||||
public DateTime AddedWhen { get; init; }
|
||||
}
|
||||
@ -32,11 +32,27 @@ public class CommandManager
|
||||
[Subcommand]
|
||||
public IEnvelopeReceiverService EnvelopeReceiver => _envelopeReceiverService;
|
||||
|
||||
[Command]
|
||||
public async Task ReadDocument(IConsole console, int? id = null, int? envelopeId = null)
|
||||
[Command(ArgumentSeparatorStrategy = ArgumentSeparatorStrategy.EndOfOptions)]
|
||||
public async Task ReadDocument(IConsole console,
|
||||
[Option(Description = "ID of the document.")] int? id = null,
|
||||
[Option(Description = "ID of the envelope containing the document.")] int? envelopeId = null,
|
||||
[Option(Description = "Path to save the PDF")] bool save = false,
|
||||
[Option(Description = "Directory to save the PDF")] string? dir = null,
|
||||
[Option(Description = "Name of file to save the PDF")] string? fileName = null)
|
||||
{
|
||||
ReadDocumentQuery query = new(id, envelopeId);
|
||||
var document = await _mediator.Send(query);
|
||||
console.WriteLine(JsonSerializer.Serialize(document, Options));
|
||||
console.WriteLine(JsonSerializer.Serialize(save ? document as ReadDocumentResponseBase : document, Options));
|
||||
|
||||
if (save)
|
||||
{
|
||||
dir ??= AppContext.BaseDirectory;
|
||||
fileName ??= $"D{document?.Guid}E{document?.EnvelopeId}.pdf";
|
||||
|
||||
var path = Path.Combine(dir, fileName);
|
||||
console.WriteLine("Save to " + path);
|
||||
|
||||
File.WriteAllBytes(path, document?.ByteData ?? Array.Empty<byte>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user