Merge branch 'feat/terminal'
This commit is contained in:
commit
9183ba4da5
@ -3,23 +3,8 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents the response for reading a document.
|
/// Represents the response for reading a document.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// The binary data of the document, if available.
|
/// The binary data of the document, if available.
|
||||||
/// </summary>
|
/// </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]
|
[Subcommand]
|
||||||
public IEnvelopeReceiverService EnvelopeReceiver => _envelopeReceiverService;
|
public IEnvelopeReceiverService EnvelopeReceiver => _envelopeReceiverService;
|
||||||
|
|
||||||
[Command]
|
[Command(ArgumentSeparatorStrategy = ArgumentSeparatorStrategy.EndOfOptions)]
|
||||||
public async Task ReadDocument(IConsole console, int? id = null, int? envelopeId = null)
|
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);
|
ReadDocumentQuery query = new(id, envelopeId);
|
||||||
var document = await _mediator.Send(query);
|
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>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Terminal;
|
namespace EnvelopeGenerator.Terminal;
|
||||||
|
|
||||||
@ -8,6 +9,10 @@ public class Program
|
|||||||
{
|
{
|
||||||
var builder = Host.CreateApplicationBuilder(args);
|
var builder = Host.CreateApplicationBuilder(args);
|
||||||
|
|
||||||
|
builder.Configuration
|
||||||
|
.SetBasePath(AppContext.BaseDirectory)
|
||||||
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
||||||
|
|
||||||
var config = builder.Configuration;
|
var config = builder.Configuration;
|
||||||
|
|
||||||
builder.Services.AddCommandManagerRunner(config);
|
builder.Services.AddCommandManagerRunner(config);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user