save development progress
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using StellaOps.Microservice;
|
||||
|
||||
namespace Examples.Billing.Microservice.Endpoints;
|
||||
|
||||
/// <summary>
|
||||
/// Request model for getting an invoice.
|
||||
/// </summary>
|
||||
public sealed record GetInvoiceRequest
|
||||
{
|
||||
public required string Id { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response model for an invoice.
|
||||
/// </summary>
|
||||
public sealed record GetInvoiceResponse
|
||||
{
|
||||
public required string InvoiceId { get; init; }
|
||||
public required string CustomerId { get; init; }
|
||||
public required decimal Amount { get; init; }
|
||||
public required string Status { get; init; }
|
||||
public required DateTime CreatedAt { get; init; }
|
||||
public DateTime? PaidAt { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Endpoint for retrieving an invoice by ID.
|
||||
/// Demonstrates a GET endpoint with path parameters.
|
||||
/// </summary>
|
||||
[StellaEndpoint("GET", "/invoices/{id}", TimeoutSeconds = 10, RequiredClaims = ["invoices:read"])]
|
||||
public sealed class GetInvoiceEndpoint : IStellaEndpoint<GetInvoiceRequest, GetInvoiceResponse>
|
||||
{
|
||||
private readonly ILogger<GetInvoiceEndpoint> _logger;
|
||||
|
||||
public GetInvoiceEndpoint(ILogger<GetInvoiceEndpoint> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task<GetInvoiceResponse> HandleAsync(
|
||||
GetInvoiceRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("Fetching invoice {InvoiceId}", request.Id);
|
||||
|
||||
// Simulate invoice lookup
|
||||
return Task.FromResult(new GetInvoiceResponse
|
||||
{
|
||||
InvoiceId = request.Id,
|
||||
CustomerId = "CUST-001",
|
||||
Amount = 199.99m,
|
||||
Status = "paid",
|
||||
CreatedAt = DateTime.UtcNow.AddDays(-7),
|
||||
PaidAt = DateTime.UtcNow.AddDays(-1)
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user