diff --git a/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentResponse.cs b/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentResponse.cs
index e5d1b287..3fc4d222 100644
--- a/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentResponse.cs
+++ b/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentResponse.cs
@@ -3,23 +3,8 @@
///
/// Represents the response for reading a document.
///
-public class ReadDocumentResponse
+public class ReadDocumentResponse : ReadDocumentResponseBase
{
- ///
- /// The unique identifier of the document.
- ///
- public int Guid { get; init; }
-
- ///
- /// The identifier of the associated envelope.
- ///
- public int EnvelopeId { get; init; }
-
- ///
- /// The date and time when the document was added.
- ///
- public DateTime AddedWhen { get; init; }
-
///
/// The binary data of the document, if available.
///
diff --git a/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentResponseBase.cs b/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentResponseBase.cs
new file mode 100644
index 00000000..afa13cb2
--- /dev/null
+++ b/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentResponseBase.cs
@@ -0,0 +1,22 @@
+namespace EnvelopeGenerator.Application.Documents.Queries.Read;
+
+///
+/// Represents the response for reading a document.
+///
+public class ReadDocumentResponseBase
+{
+ ///
+ /// The unique identifier of the document.
+ ///
+ public int Guid { get; init; }
+
+ ///
+ /// The identifier of the associated envelope.
+ ///
+ public int EnvelopeId { get; init; }
+
+ ///
+ /// The date and time when the document was added.
+ ///
+ public DateTime AddedWhen { get; init; }
+}
diff --git a/EnvelopeGenerator.Terminal/CommandManager.cs b/EnvelopeGenerator.Terminal/CommandManager.cs
index 3ba0f76a..a593df00 100644
--- a/EnvelopeGenerator.Terminal/CommandManager.cs
+++ b/EnvelopeGenerator.Terminal/CommandManager.cs
@@ -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());
+ }
}
}
diff --git a/EnvelopeGenerator.Terminal/Program.cs b/EnvelopeGenerator.Terminal/Program.cs
index 2aed708a..09f61cbd 100644
--- a/EnvelopeGenerator.Terminal/Program.cs
+++ b/EnvelopeGenerator.Terminal/Program.cs
@@ -1,4 +1,5 @@
-using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting;
namespace EnvelopeGenerator.Terminal;
@@ -8,6 +9,10 @@ public class Program
{
var builder = Host.CreateApplicationBuilder(args);
+ builder.Configuration
+ .SetBasePath(AppContext.BaseDirectory)
+ .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
+
var config = builder.Configuration;
builder.Services.AddCommandManagerRunner(config);